Skip to content

[string] Add less bad SPI for Foundation #15442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions stdlib/public/core/StringGuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result>(
_ f: (UnsafeBufferPointer<UInt8>) throws -> Result
) rethrows -> Result? {
guard _object.isContiguousASCII else { return nil }
return try f(_unmanagedASCIIView.buffer)
}

@available(*, deprecated)
public // SPI(Foundation)
func _withUnsafeUTF16CodeUnitsIfAvailable<Result>(
_ f: (UnsafeBufferPointer<UInt16>) throws -> Result
) rethrows -> Result? {
guard _object.isContiguousUTF16 else { return nil }
return try f(_unmanagedUTF16View.buffer)
}
}