diff --git a/stdlib/public/core/StringGuts.swift b/stdlib/public/core/StringGuts.swift index 8198126ef745d..99112f570fc22 100644 --- a/stdlib/public/core/StringGuts.swift +++ b/stdlib/public/core/StringGuts.swift @@ -1413,3 +1413,36 @@ extension _StringGuts { return UnsafeMutablePointer(mutating: _unmanagedUTF16View.start) } } + +extension _StringGuts { + @available(*, deprecated) + public // SPI(Foundation) + var _isContiguousASCII: Bool { + return _object.isContiguousASCII + } + + @available(*, deprecated) + public // SPI(Foundation) + var _isContiguousUTF16: Bool { + return _object.isContiguousUTF16 + } + + @available(*, deprecated) + public // SPI(Foundation) + func _withUnsafeUTF8CodeUnitsIfAvailable( + _ f: (UnsafeBufferPointer) throws -> Result + ) rethrows -> Result? { + guard _object.isContiguousASCII else { return nil } + return try f(_unmanagedASCIIView.buffer) + } + + @available(*, deprecated) + public // SPI(Foundation) + func _withUnsafeUTF16CodeUnitsIfAvailable( + _ f: (UnsafeBufferPointer) throws -> Result + ) rethrows -> Result? { + guard _object.isContiguousUTF16 else { return nil } + return try f(_unmanagedUTF16View.buffer) + } +} +