mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Restrict BIgString and _BString to Swift 5.8 and macOS 13.3 /iOS 16.4/etc
These types heavily rely on stdlib functionality that ships in Swift 5.8; they do not run correctly on earlier releases.
This commit is contained in:
39 files changed
+313
-142
No files matched your search
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct Builder {
|
||||
typealias Chunk = _BString.Chunk
|
||||
@@ -37,6 +40,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _Rope<_BString.Chunk>.Builder {
|
||||
func breakState() -> _CharacterRecognizer {
|
||||
let chars = self.prefixSummary.characters
|
||||
@@ -55,6 +59,7 @@ extension _Rope<_BString.Chunk>.Builder {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Builder {
|
||||
mutating func append(_ str: __owned some StringProtocol) {
|
||||
append(Substring(str))
|
||||
@@ -126,6 +131,7 @@ extension _BString.Builder {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Builder {
|
||||
mutating func finalize() -> _BString {
|
||||
// Resync breaks in suffix.
|
||||
@@ -139,3 +145,5 @@ extension _BString.Builder {
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
var isEmpty: Bool {
|
||||
rope.summary.isZero
|
||||
@@ -23,6 +26,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
var characterCount: Int { rope.summary.characters }
|
||||
var unicodeScalarCount: Int { rope.summary.unicodeScalars }
|
||||
@@ -30,6 +34,7 @@ extension _BString {
|
||||
var utf8Count: Int { rope.summary.utf8 }
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func distance(
|
||||
from start: Index,
|
||||
@@ -68,6 +73,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
// FIXME: See if we need direct implementations for these.
|
||||
|
||||
@@ -88,6 +94,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
// FIXME: See if we need direct implementations for these.
|
||||
|
||||
@@ -108,6 +115,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func _path(
|
||||
_ i: Index,
|
||||
@@ -193,6 +201,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func characterIndex(after i: Index) -> Index {
|
||||
index(i, offsetBy: 1, in: CharacterMetric())
|
||||
@@ -213,6 +222,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func characterIndex(before i: Index) -> Index {
|
||||
index(i, offsetBy: -1, in: CharacterMetric())
|
||||
@@ -233,6 +243,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func characterIndex(roundingDown i: Index) -> Index {
|
||||
let offset = i._utf8Offset - 1
|
||||
@@ -287,6 +298,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func _character(
|
||||
at start: Path, base: Index?, in chunk: Chunk
|
||||
@@ -359,3 +371,5 @@ extension _BString {
|
||||
return chunk.string.unicodeScalars[path.chunk]
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func dump(heightLimit: Int = .max) {
|
||||
rope.dump(heightLimit: heightLimit)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct Index {
|
||||
// The layout is similar to (and somewhat compatible with) String.Index.
|
||||
@@ -26,6 +29,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index {
|
||||
@inline(__always)
|
||||
internal var _orderingValue: UInt64 {
|
||||
@@ -33,24 +37,28 @@ extension _BString.Index {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index: Equatable {
|
||||
internal static func ==(left: Self, right: Self) -> Bool {
|
||||
left._orderingValue == right._orderingValue
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index: Comparable {
|
||||
internal static func <(left: Self, right: Self) -> Bool {
|
||||
left._orderingValue < right._orderingValue
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index: Hashable {
|
||||
internal func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(_orderingValue)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index: CustomStringConvertible {
|
||||
internal var description: String {
|
||||
let offset = _utf16Delta == 0 ? "" : "+\(_utf16Delta)"
|
||||
@@ -58,6 +66,7 @@ extension _BString.Index: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Index {
|
||||
@inline(__always)
|
||||
internal static func _bitsForUTF8Offset(_ utf8Offset: Int) -> UInt64 {
|
||||
@@ -94,3 +103,5 @@ extension _BString.Index {
|
||||
Self(_utf8Offset: _utf8Offset + delta)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func ingester(
|
||||
forInserting input: __owned Substring,
|
||||
@@ -21,6 +24,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct Ingester {
|
||||
typealias Chunk = _BString.Chunk
|
||||
@@ -133,6 +137,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension String {
|
||||
func _nextSlice(
|
||||
after i: Index,
|
||||
@@ -148,6 +153,7 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
init(_ string: String) {
|
||||
guard !string.isEmpty else { self.init(); return }
|
||||
@@ -157,3 +163,5 @@ extension _BString.Chunk {
|
||||
assert(ingester.isAtEnd)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func invariantCheck() {
|
||||
#if DEBUG
|
||||
@@ -32,3 +35,5 @@ extension _BString {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct ChunkIterator {
|
||||
var base: Rope.Iterator
|
||||
@@ -23,6 +26,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.ChunkIterator: IteratorProtocol {
|
||||
typealias Element = String
|
||||
|
||||
@@ -31,6 +35,7 @@ extension _BString.ChunkIterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct UTF8Iterator {
|
||||
internal var _rope: Rope.Iterator
|
||||
@@ -48,6 +53,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.UTF8Iterator: IteratorProtocol {
|
||||
internal typealias Element = UInt8
|
||||
|
||||
@@ -61,6 +67,7 @@ extension _BString.UTF8Iterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct UTF16Iterator {
|
||||
internal var _rope: Rope.Iterator
|
||||
@@ -78,6 +85,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.UTF16Iterator: IteratorProtocol {
|
||||
internal typealias Element = UInt16
|
||||
|
||||
@@ -91,6 +99,7 @@ extension _BString.UTF16Iterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct UnicodeScalarIterator {
|
||||
internal var _rope: Rope.Iterator
|
||||
@@ -117,6 +126,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.UnicodeScalarIterator: IteratorProtocol {
|
||||
internal typealias Element = Unicode.Scalar
|
||||
|
||||
@@ -133,6 +143,7 @@ extension _BString.UnicodeScalarIterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct CharacterIterator {
|
||||
internal var _utf8BaseOffset: Int
|
||||
@@ -186,6 +197,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.CharacterIterator: IteratorProtocol {
|
||||
internal typealias Element = Character
|
||||
|
||||
@@ -270,6 +282,7 @@ extension _BString.CharacterIterator: IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.CharacterIterator {
|
||||
// The UTF-8 offset of the current position, from the start of the string.
|
||||
var utf8Offset: Int {
|
||||
@@ -310,3 +323,5 @@ extension _BString.CharacterIterator {
|
||||
return self._index < path.chunk
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
internal protocol _StringMetric: _RopeMetric where Element == _BString.Chunk {
|
||||
func distance(
|
||||
from start: String.Index,
|
||||
@@ -23,6 +26,7 @@ internal protocol _StringMetric: _RopeMetric where Element == _BString.Chunk {
|
||||
) -> (found: Bool, forward: Bool)
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal struct CharacterMetric: _StringMetric {
|
||||
typealias Element = _BString.Chunk
|
||||
@@ -201,3 +205,5 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct Path {
|
||||
var rope: Rope.Index
|
||||
@@ -42,12 +45,14 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Path: CustomStringConvertible {
|
||||
var description: String {
|
||||
"\(rope).\(chunk._description)"
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func path(
|
||||
to i: Index,
|
||||
@@ -62,6 +67,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func baseIndex(
|
||||
with index: Index,
|
||||
@@ -83,3 +89,5 @@ extension _BString {
|
||||
return index(base: base, offsetBy: path.chunk)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct Summary {
|
||||
// FIXME: We only need 48 * 3 = 192 bits to represent a nonnegative value; pack these better
|
||||
@@ -34,12 +37,14 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Summary: CustomStringConvertible {
|
||||
var description: String {
|
||||
"❨\(utf8)⋅\(utf16)⋅\(unicodeScalars)⋅\(characters)❩"
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Summary: _RopeSummary {
|
||||
@inline(__always)
|
||||
static var maxNodeSize: Int { 10 }
|
||||
@@ -67,3 +72,5 @@ extension _BString.Summary: _RopeSummary {
|
||||
utf8 -= other.utf8
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
/// The core of a B-tree based String implementation.
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
internal struct _BString: Sendable {
|
||||
typealias Rope = _Rope<Chunk>
|
||||
|
||||
@@ -23,3 +26,10 @@ internal struct _BString: Sendable {
|
||||
self.rope = rope
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@available(*, unavailable, message: "_BString requires Swift 5.8")
|
||||
internal struct _BString: Sendable {}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
mutating func append(_ other: __owned Self) {
|
||||
self._append(other.string[...], other.counts)
|
||||
@@ -63,6 +66,7 @@ extension _BString.Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
mutating func _insert(
|
||||
_ slice: Slice,
|
||||
@@ -166,3 +170,5 @@ extension _BString.Chunk {
|
||||
return .split(spawn: spawn, endStates: (sum - offset, old, new))
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
@inline(__always)
|
||||
var hasBreaks: Bool { counts.hasBreaks }
|
||||
@@ -37,6 +40,7 @@ extension _BString.Chunk {
|
||||
var wholeCharacters: Substring { string[firstBreak...] }
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
var immediateLastBreakState: _CharacterRecognizer? {
|
||||
guard hasBreaks else { return nil }
|
||||
@@ -64,3 +68,4 @@ extension _BString.Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk: _RopeElement {
|
||||
typealias Summary = _BString.Summary
|
||||
typealias Index = String.Index
|
||||
@@ -112,6 +115,7 @@ extension _BString.Chunk: _RopeElement {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
static func _redistributeData(
|
||||
_ left: inout Self,
|
||||
@@ -149,3 +153,5 @@ extension _BString.Chunk {
|
||||
left = Self(left.string[..<i], counts.left)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
struct Counts: Equatable {
|
||||
/// The number of UTF-8 code units within this chunk.
|
||||
@@ -96,6 +99,7 @@ extension _BString.Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk.Counts {
|
||||
var characters: Int {
|
||||
get { Int(_characters) }
|
||||
@@ -121,6 +125,7 @@ extension _BString.Chunk.Counts {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk.Counts {
|
||||
mutating func append(_ other: Self) {
|
||||
assert(hasSpaceToMerge(other))
|
||||
@@ -144,3 +149,4 @@ extension _BString.Chunk.Counts {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk: CustomStringConvertible {
|
||||
var description: String {
|
||||
let counts = """
|
||||
@@ -65,3 +68,5 @@ extension _BString.Chunk: CustomStringConvertible {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,12 +9,16 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension UInt8 {
|
||||
/// Returns true if this is a leading code unit in the UTF-8 encoding of a Unicode scalar that
|
||||
/// is outside the BMP.
|
||||
var _isUTF8NonBMPLeadingCodeUnit: Bool { self >= 0b11110000 }
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
func characterDistance(from start: String.Index, to end: String.Index) -> Int {
|
||||
let firstBreak = self.firstBreak
|
||||
@@ -104,3 +108,5 @@ extension _BString.Chunk {
|
||||
return (false, false)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
/// UTF-16 index lookup.
|
||||
func index(at utf8Offset: Int, utf16Delta: Int) -> String.Index {
|
||||
@@ -24,3 +27,5 @@ extension _BString.Chunk {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
func splitCounts(at i: String.Index) -> (left: Counts, right: Counts) {
|
||||
precondition(i <= string.endIndex)
|
||||
@@ -142,3 +145,5 @@ extension _BString.Chunk {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
struct Chunk {
|
||||
typealias Slice = (string: Substring, characters: Int, prefix: Int, suffix: Int)
|
||||
@@ -43,6 +46,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
@inline(__always)
|
||||
static var maxUTF8Count: Int { 255 }
|
||||
@@ -54,6 +58,7 @@ extension _BString.Chunk {
|
||||
static var maxSlicingError: Int { 3 }
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
@inline(__always)
|
||||
mutating func take() -> Self {
|
||||
@@ -70,7 +75,7 @@ extension _BString.Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
@inline(__always)
|
||||
var characterCount: Int { counts.characters }
|
||||
@@ -94,6 +99,7 @@ extension _BString.Chunk {
|
||||
var lastScalar: UnicodeScalar { string.unicodeScalars.last! }
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
var availableSpace: Int { Swift.max(0, Self.maxUTF8Count - utf8Count) }
|
||||
|
||||
@@ -103,6 +109,7 @@ extension _BString.Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
func hasSpaceToMerge(_ other: some StringProtocol) -> Bool {
|
||||
utf8Count + other.utf8.count <= Self.maxUTF8Count
|
||||
@@ -112,3 +119,5 @@ extension _BString.Chunk {
|
||||
utf8Count + other.utf8Count <= Self.maxUTF8Count
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,12 +9,16 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func isIdentical(to other: Self) -> Bool {
|
||||
self.rope.isIdentical(to: other.rope)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal func characterIsEqual(to other: Self) -> Bool {
|
||||
// FIXME: Implement properly normalized comparisons & hashing.
|
||||
@@ -93,6 +97,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
/// Lexicographically compare the UTF-8 representations of `left` to `right`, returning a Boolean
|
||||
/// value indicating whether `left` is equal to `right`.
|
||||
@@ -183,3 +188,5 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,14 +9,20 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString: ExpressibleByStringLiteral {
|
||||
internal init(stringLiteral value: String) {
|
||||
self.init(value)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString: CustomStringConvertible {
|
||||
internal var description: String {
|
||||
String(_from: self)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal func hashCharacters(into hasher: inout Hasher) {
|
||||
// FIXME: Implement properly normalized comparisons & hashing.
|
||||
@@ -35,3 +38,5 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension Range<_BString.Index> {
|
||||
internal var _isEmptyUTF8: Bool {
|
||||
lowerBound._utf8Offset == upperBound._utf8Offset
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func append(contentsOf other: __owned some StringProtocol) {
|
||||
append(contentsOf: Substring(other))
|
||||
@@ -46,6 +49,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
var _firstUnicodeScalar: Unicode.Scalar {
|
||||
assert(!isEmpty)
|
||||
@@ -111,12 +115,14 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
var isUndersized: Bool {
|
||||
utf8Count < Chunk.minUTF8Count
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
/// Note: This assumes `other` already has the correct break positions.
|
||||
mutating func _append(_ other: __owned Chunk) {
|
||||
@@ -197,3 +203,5 @@ extension _BString {
|
||||
self.rope = Rope.join(other, self.rope)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal init(_ input: some StringProtocol) {
|
||||
var builder = Rope.Builder()
|
||||
@@ -75,6 +78,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension String {
|
||||
internal init(_from big: _BString) {
|
||||
guard !big.isEmpty else {
|
||||
@@ -123,6 +127,7 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
internal init(repeating value: Self, count: Int) {
|
||||
precondition(count >= 0, "Negative count")
|
||||
@@ -146,3 +151,5 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func insert(contentsOf other: __owned some StringProtocol, at index: Index) {
|
||||
insert(contentsOf: Substring(other), at: index)
|
||||
@@ -54,6 +57,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func insert(contentsOf other: __owned Self, at index: Index) {
|
||||
guard index < endIndex else {
|
||||
@@ -77,6 +81,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func insert(contentsOf other: __owned Self, in range: Range<Index>, at index: Index) {
|
||||
guard index < endIndex else {
|
||||
@@ -95,3 +100,5 @@ extension _BString {
|
||||
self = builder.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
func _breakState(
|
||||
upTo end: Path,
|
||||
@@ -61,6 +64,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
/// - Returns: the position at which the grapheme breaks finally sync up with the originals.
|
||||
/// (or nil if they never did).
|
||||
@@ -96,6 +100,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Rope {
|
||||
mutating func resyncBreaks(
|
||||
old: inout _CharacterRecognizer,
|
||||
@@ -152,6 +157,7 @@ extension _BString.Rope {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString.Chunk {
|
||||
/// Resyncronize chunk metadata with the (possibly) reshuffled grapheme
|
||||
/// breaks after an insertion that ended at `index`.
|
||||
@@ -261,3 +267,5 @@ extension _BString.Chunk {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func removeSubrange(_ bounds: Range<Index>) {
|
||||
precondition(bounds.upperBound <= endIndex, "Index out of bounds")
|
||||
@@ -19,6 +22,7 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func removeCharacter(at i: Index) -> Character {
|
||||
let (start, chunk) = self.path(to: i, preferEnd: false)
|
||||
@@ -40,3 +44,5 @@ extension _BString {
|
||||
return scalar
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func replaceSubrange(_ range: Range<Index>, with newElements: some StringProtocol) {
|
||||
precondition(range.upperBound <= endIndex, "Index out of bounds")
|
||||
@@ -69,3 +72,4 @@ extension _BString {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.8)
|
||||
|
||||
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
|
||||
extension _BString {
|
||||
mutating func split(
|
||||
at index: Index
|
||||
@@ -28,3 +31,5 @@ extension _BString {
|
||||
return builder
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user