Skip to content

Commit 020d94a

Browse files
committed
[string] Add less bad SPI for Foundation
1 parent 99051b5 commit 020d94a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

stdlib/public/core/StringGuts.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,3 +1413,36 @@ extension _StringGuts {
14131413
return UnsafeMutablePointer(mutating: _unmanagedUTF16View.start)
14141414
}
14151415
}
1416+
1417+
extension _StringGuts {
1418+
@available(*, deprecated)
1419+
public // SPI(Foundation)
1420+
var _isContiguousASCII: Bool {
1421+
return _object.isContiguousASCII
1422+
}
1423+
1424+
@available(*, deprecated)
1425+
public // SPI(Foundation)
1426+
var _isContiguousUTF16: Bool {
1427+
return _object.isContiguousUTF16
1428+
}
1429+
1430+
@available(*, deprecated)
1431+
public // SPI(Foundation)
1432+
func _withUnsafeUTF8CodeUnitsIfAvailable<Result>(
1433+
_ f: (UnsafeBufferPointer<UInt8>) throws -> Result
1434+
) rethrows -> Result? {
1435+
guard _object.isContiguousASCII else { return nil }
1436+
return try f(_unmanagedASCIIView.buffer)
1437+
}
1438+
1439+
@available(*, deprecated)
1440+
public // SPI(Foundation)
1441+
func _withUnsafeUTF16CodeUnitsIfAvailable<Result>(
1442+
_ f: (UnsafeBufferPointer<UInt16>) throws -> Result
1443+
) rethrows -> Result? {
1444+
guard _object.isContiguousUTF16 else { return nil }
1445+
return try f(_unmanagedUTF16View.buffer)
1446+
}
1447+
}
1448+

0 commit comments

Comments
 (0)