diff --git a/Sources/RopeModule/BString/Basics/_BString+Builder.swift b/Sources/RopeModule/BString/Basics/_BString+Builder.swift index a2a77e90..fd33db18 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Builder.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Builder.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Contents.swift b/Sources/RopeModule/BString/Basics/_BString+Contents.swift index 206e68f6..3601488b 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Contents.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Contents.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Debugging.swift b/Sources/RopeModule/BString/Basics/_BString+Debugging.swift index bd31783d..b53bd0af 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Debugging.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Debugging.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Index.swift b/Sources/RopeModule/BString/Basics/_BString+Index.swift index 21e00106..ef649833 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Index.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Index.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Ingester.swift b/Sources/RopeModule/BString/Basics/_BString+Ingester.swift index 38f2faf4..2bb9c36b 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Ingester.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Ingester.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Invariants.swift b/Sources/RopeModule/BString/Basics/_BString+Invariants.swift index 0360d819..ec88d4d3 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Invariants.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Invariants.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Iterators.swift b/Sources/RopeModule/BString/Basics/_BString+Iterators.swift index ba3fa117..ab0863e1 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Iterators.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Iterators.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Metrics.swift b/Sources/RopeModule/BString/Basics/_BString+Metrics.swift index c7561584..4e0761df 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Metrics.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Metrics.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Path.swift b/Sources/RopeModule/BString/Basics/_BString+Path.swift index abcb3730..b32cd629 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Path.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Path.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString+Summary.swift b/Sources/RopeModule/BString/Basics/_BString+Summary.swift index 8720894d..ce138a82 100644 --- a/Sources/RopeModule/BString/Basics/_BString+Summary.swift +++ b/Sources/RopeModule/BString/Basics/_BString+Summary.swift @@ -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 diff --git a/Sources/RopeModule/BString/Basics/_BString.swift b/Sources/RopeModule/BString/Basics/_BString.swift index 056d6de0..cda99f64 100644 --- a/Sources/RopeModule/BString/Basics/_BString.swift +++ b/Sources/RopeModule/BString/Basics/_BString.swift @@ -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 @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Append and Insert.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Append and Insert.swift index 5aa80c8b..b0d7016b 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Append and Insert.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Append and Insert.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Breaks.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Breaks.swift index d184f3a6..fe85a115 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Breaks.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Breaks.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+CordElement.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+CordElement.swift index 58fae24e..bd009ef5 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+CordElement.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+CordElement.swift @@ -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[..=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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Description.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Description.swift index 89ba9ec4..f97d1c3c 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Description.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Description.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by Characters.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by Characters.swift index a7a59264..f97e128c 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by Characters.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by Characters.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by UTF16.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by UTF16.swift index a5a1f509..45473005 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by UTF16.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Indexing by UTF16.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Splitting.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Splitting.swift index d4af04a9..73898e4e 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk+Splitting.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk+Splitting.swift @@ -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 diff --git a/Sources/RopeModule/BString/Chunk/_BString+Chunk.swift b/Sources/RopeModule/BString/Chunk/_BString+Chunk.swift index f318912d..09c25757 100644 --- a/Sources/RopeModule/BString/Chunk/_BString+Chunk.swift +++ b/Sources/RopeModule/BString/Chunk/_BString+Chunk.swift @@ -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 diff --git a/Sources/RopeModule/BString/Conformances/_BString+Comparisons.swift b/Sources/RopeModule/BString/Conformances/_BString+Comparisons.swift index e65b2bf9..4fac1847 100644 --- a/Sources/RopeModule/BString/Conformances/_BString+Comparisons.swift +++ b/Sources/RopeModule/BString/Conformances/_BString+Comparisons.swift @@ -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 diff --git a/Sources/RopeModule/BString/Conformances/_BString+Conformances.swift b/Sources/RopeModule/BString/Conformances/_BString+Conformances.swift index fd6c0093..aa069437 100644 --- a/Sources/RopeModule/BString/Conformances/_BString+Conformances.swift +++ b/Sources/RopeModule/BString/Conformances/_BString+Conformances.swift @@ -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 diff --git a/Sources/RopeModule/BString/Conformances/_BString+Hashing.swift b/Sources/RopeModule/BString/Conformances/_BString+Hashing.swift index ceede27f..81192eae 100644 --- a/Sources/RopeModule/BString/Conformances/_BString+Hashing.swift +++ b/Sources/RopeModule/BString/Conformances/_BString+Hashing.swift @@ -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 diff --git a/Sources/RopeModule/BString/Operations/Range+_BString.swift b/Sources/RopeModule/BString/Operations/Range+_BString.swift index 6c9d1f0b..621458d9 100644 --- a/Sources/RopeModule/BString/Operations/Range+_BString.swift +++ b/Sources/RopeModule/BString/Operations/Range+_BString.swift @@ -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 diff --git a/Sources/RopeModule/BString/Operations/_BString+Append.swift b/Sources/RopeModule/BString/Operations/_BString+Append.swift index e22fcd56..8ad1e8ad 100644 --- a/Sources/RopeModule/BString/Operations/_BString+Append.swift +++ b/Sources/RopeModule/BString/Operations/_BString+Append.swift @@ -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 diff --git a/Sources/RopeModule/BString/Operations/_BString+Initializers.swift b/Sources/RopeModule/BString/Operations/_BString+Initializers.swift index 5b2c86af..7e16118a 100644 --- a/Sources/RopeModule/BString/Operations/_BString+Initializers.swift +++ b/Sources/RopeModule/BString/Operations/_BString+Initializers.swift @@ -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 diff --git a/Sources/RopeModule/BString/Operations/_BString+Insert.swift b/Sources/RopeModule/BString/Operations/_BString+Insert.swift index d0fdffce..707a4286 100644 --- a/Sources/RopeModule/BString/Operations/_BString+Insert.swift +++ b/Sources/RopeModule/BString/Operations/_BString+Insert.swift @@ -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, at index: Index) { guard index < endIndex else { @@ -95,3 +100,5 @@ extension _BString { self = builder.finalize() } } + +#endif diff --git a/Sources/RopeModule/BString/Operations/_BString+Managing Breaks.swift b/Sources/RopeModule/BString/Operations/_BString+Managing Breaks.swift index da0b3a93..f108d77d 100644 --- a/Sources/RopeModule/BString/Operations/_BString+Managing Breaks.swift +++ b/Sources/RopeModule/BString/Operations/_BString+Managing Breaks.swift @@ -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 diff --git a/Sources/RopeModule/BString/Operations/_BString+RemoveSubrange.swift b/Sources/RopeModule/BString/Operations/_BString+RemoveSubrange.swift index 308b05f0..ef6ffbce 100644 --- a/Sources/RopeModule/BString/Operations/_BString+RemoveSubrange.swift +++ b/Sources/RopeModule/BString/Operations/_BString+RemoveSubrange.swift @@ -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) { 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 diff --git a/Sources/RopeModule/BString/Operations/_BString+ReplaceSubrange.swift b/Sources/RopeModule/BString/Operations/_BString+ReplaceSubrange.swift index f3af7655..754e664c 100644 --- a/Sources/RopeModule/BString/Operations/_BString+ReplaceSubrange.swift +++ b/Sources/RopeModule/BString/Operations/_BString+ReplaceSubrange.swift @@ -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, with newElements: some StringProtocol) { precondition(range.upperBound <= endIndex, "Index out of bounds") @@ -69,3 +72,4 @@ extension _BString { } } +#endif diff --git a/Sources/RopeModule/BString/Operations/_BString+Split.swift b/Sources/RopeModule/BString/Operations/_BString+Split.swift index 0865685e..e38675fa 100644 --- a/Sources/RopeModule/BString/Operations/_BString+Split.swift +++ b/Sources/RopeModule/BString/Operations/_BString+Split.swift @@ -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 diff --git a/Sources/RopeModule/BigString/BigString+CharacterView.swift b/Sources/RopeModule/BigString/BigString+CharacterView.swift index 50b5f61b..e6a366c9 100644 --- a/Sources/RopeModule/BigString/BigString+CharacterView.swift +++ b/Sources/RopeModule/BigString/BigString+CharacterView.swift @@ -9,6 +9,9 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public struct Index { internal var _value: _BString.Index @@ -19,48 +22,56 @@ extension BigString { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.Index: CustomStringConvertible { public var description: String { "\(_value)" } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.Index: Equatable { public static func ==(left: Self, right: Self) -> Bool { left._value == right._value } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.Index: Comparable { public static func <(left: Self, right: Self) -> Bool { left._value < right._value } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.Index: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(_value) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: Equatable { public static func == (left: Self, right: Self) -> Bool { left._guts.characterIsEqual(to: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: Comparable { public static func < (left: Self, right: Self) -> Bool { left._guts.characterIsLess(than: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: Hashable { public func hash(into hasher: inout Hasher) { _guts.hashCharacters(into: &hasher) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: Sequence { public struct Iterator: IteratorProtocol { public typealias Element = Character @@ -81,6 +92,7 @@ extension BigString: Sequence { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: BidirectionalCollection { public typealias Element = Character @@ -117,6 +129,7 @@ extension BigString: BidirectionalCollection { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: RangeReplaceableCollection { public mutating func replaceSubrange( _ subrange: Range, @@ -279,3 +292,5 @@ extension BigString: RangeReplaceableCollection { _guts = _BString() } } + +#endif diff --git a/Sources/RopeModule/BigString/BigString+UTF16View.swift b/Sources/RopeModule/BigString/BigString+UTF16View.swift index 5304cd51..b6da68f9 100644 --- a/Sources/RopeModule/BigString/BigString+UTF16View.swift +++ b/Sources/RopeModule/BigString/BigString+UTF16View.swift @@ -9,6 +9,9 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public struct UTF16View { internal var _guts: _BString @@ -36,12 +39,14 @@ extension BigString { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public init(_ content: UTF16View) { self._guts = content._guts } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: CustomStringConvertible { public var description: String { var d = "<" @@ -53,24 +58,28 @@ extension BigString.UTF16View: CustomStringConvertible { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: Equatable { public static func ==(left: Self, right: Self) -> Bool { left._guts.utf8IsEqual(to: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: Comparable { public static func <(left: Self, right: Self) -> Bool { left._guts.utf8IsLess(than: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: Hashable { public func hash(into hasher: inout Hasher) { _guts.hashUTF8(into: &hasher) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: Sequence { public struct Iterator: IteratorProtocol { public typealias Element = UInt16 @@ -91,6 +100,7 @@ extension BigString.UTF16View: Sequence { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF16View: BidirectionalCollection { public typealias Index = BigString.Index public typealias Element = UInt16 @@ -127,3 +137,5 @@ extension BigString.UTF16View: BidirectionalCollection { _guts[utf16: position._value] } } + +#endif diff --git a/Sources/RopeModule/BigString/BigString+UTF8View.swift b/Sources/RopeModule/BigString/BigString+UTF8View.swift index fbb46a1b..9f789113 100644 --- a/Sources/RopeModule/BigString/BigString+UTF8View.swift +++ b/Sources/RopeModule/BigString/BigString+UTF8View.swift @@ -9,6 +9,9 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public struct UTF8View { internal var _guts: _BString @@ -36,12 +39,14 @@ extension BigString { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public init(_ content: UTF8View) { self._guts = content._guts } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: CustomStringConvertible { public var description: String { var d = "<" @@ -53,24 +58,28 @@ extension BigString.UTF8View: CustomStringConvertible { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: Equatable { public static func ==(left: Self, right: Self) -> Bool { left._guts.utf8IsEqual(to: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: Comparable { public static func <(left: Self, right: Self) -> Bool { left._guts.utf8IsLess(than: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: Hashable { public func hash(into hasher: inout Hasher) { _guts.hashUTF8(into: &hasher) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: Sequence { public struct Iterator: IteratorProtocol { public typealias Element = UInt8 @@ -91,6 +100,7 @@ extension BigString.UTF8View: Sequence { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UTF8View: BidirectionalCollection { public typealias Index = BigString.Index public typealias Element = UInt8 @@ -127,3 +137,5 @@ extension BigString.UTF8View: BidirectionalCollection { _guts[utf8: position._value] } } + +#endif diff --git a/Sources/RopeModule/BigString/BigString+UnicodeScalarView.swift b/Sources/RopeModule/BigString/BigString+UnicodeScalarView.swift index dbce1e65..a24d4ecc 100644 --- a/Sources/RopeModule/BigString/BigString+UnicodeScalarView.swift +++ b/Sources/RopeModule/BigString/BigString+UnicodeScalarView.swift @@ -9,6 +9,9 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public struct UnicodeScalarView { var _guts: _BString @@ -36,42 +39,49 @@ extension BigString { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public init(_ content: UnicodeScalarView) { self._guts = content._guts } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: ExpressibleByStringLiteral { public init(stringLiteral value: String) { self.init(_guts: _BString(value)) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: CustomStringConvertible { public var description: String { String(_from: _guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: Equatable { public static func ==(left: Self, right: Self) -> Bool { left._guts.utf8IsEqual(to: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: Comparable { public static func <(left: Self, right: Self) -> Bool { left._guts.utf8IsLess(than: right._guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: Hashable { public func hash(into hasher: inout Hasher) { _guts.hashUTF8(into: &hasher) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: Sequence { public struct Iterator: IteratorProtocol { public typealias Element = Unicode.Scalar @@ -92,6 +102,7 @@ extension BigString.UnicodeScalarView: Sequence { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: BidirectionalCollection { public typealias Element = Unicode.Scalar public typealias Index = BigString.Index @@ -129,6 +140,7 @@ extension BigString.UnicodeScalarView: BidirectionalCollection { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString.UnicodeScalarView: RangeReplaceableCollection { public mutating func replaceSubrange( _ subrange: Range, @@ -287,3 +299,5 @@ extension BigString.UnicodeScalarView: RangeReplaceableCollection { _guts = _BString() } } + +#endif diff --git a/Sources/RopeModule/BigString/BigString.swift b/Sources/RopeModule/BigString/BigString.swift index 0d44c07b..c13fcc97 100644 --- a/Sources/RopeModule/BigString/BigString.swift +++ b/Sources/RopeModule/BigString/BigString.swift @@ -9,6 +9,9 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) public struct BigString: Sendable { internal var _guts: _BString @@ -21,30 +24,35 @@ public struct BigString: Sendable { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: ExpressibleByStringLiteral { public init(stringLiteral value: String) { self.init(value) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: CustomStringConvertible, LosslessStringConvertible { public var description: String { String(_from: _guts) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString: TextOutputStream { public mutating func write(_ string: String) { self.append(contentsOf: string) } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension BigString { public func _invariantCheck() { _guts.invariantCheck() } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension String { public init(_ big: BigString) { self.init(_from: big._guts) @@ -55,6 +63,7 @@ extension String { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension String.UnicodeScalarView { public init(_ big: BigString.UnicodeScalarView) { self = String(_from: big._guts).unicodeScalars @@ -65,8 +74,16 @@ extension String.UnicodeScalarView { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension Range { internal var _base: Range<_BString.Index> { Range<_BString.Index>(uncheckedBounds: (lowerBound._value, upperBound._value)) } } + +#else + +@available(*, unavailable, message: "BigString requires Swift 5.8") +public struct BigString: Sendable {} + +#endif diff --git a/Sources/RopeModule/Utilities/String Utilities.swift b/Sources/RopeModule/Utilities/String Utilities.swift index 0b1fe136..a27ab140 100644 --- a/Sources/RopeModule/Utilities/String Utilities.swift +++ b/Sources/RopeModule/Utilities/String Utilities.swift @@ -9,6 +9,7 @@ // //===----------------------------------------------------------------------===// +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension StringProtocol { @inline(__always) var _indexOfLastCharacter: Index { @@ -44,6 +45,7 @@ extension StringProtocol { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension String { internal func _lpad(to width: Int, with pad: Character = " ") -> String { let c = self.count @@ -58,6 +60,7 @@ extension String { } } +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension String { @discardableResult mutating func _appendQuotedProtectingLeft( diff --git a/Sources/RopeModule/Utilities/_CharacterRecognizer.swift b/Sources/RopeModule/Utilities/_CharacterRecognizer.swift index da1b9d1e..faab4ef3 100644 --- a/Sources/RopeModule/Utilities/_CharacterRecognizer.swift +++ b/Sources/RopeModule/Utilities/_CharacterRecognizer.swift @@ -9,125 +9,26 @@ // //===----------------------------------------------------------------------===// -/// CR and LF are common special cases in grapheme breaking logic -private var _CR: UInt8 { return 0x0d } -private var _LF: UInt8 { return 0x0a } +#if swift(>=5.8) -internal func _hasGraphemeBreakBetween( - _ lhs: Unicode.Scalar, _ rhs: Unicode.Scalar -) -> Bool { - - // CR-LF is a special case: no break between these - if lhs == Unicode.Scalar(_CR) && rhs == Unicode.Scalar(_LF) { - return false - } - - // Whether the given scalar, when it appears paired with another scalar - // satisfying this property, has a grapheme break between it and the other - // scalar. - func hasBreakWhenPaired(_ x: Unicode.Scalar) -> Bool { - // TODO: This doesn't generate optimal code, tune/re-write at a lower - // level. - // - // NOTE: Order of case ranges affects codegen, and thus performance. All - // things being equal, keep existing order below. - switch x.value { - // Unified CJK Han ideographs, common and some supplemental, amongst - // others: - // U+3400 ~ U+A4CF - case 0x3400...0xa4cf: return true - - // Repeat sub-300 check, this is beneficial for common cases of Latin - // characters embedded within non-Latin script (e.g. newlines, spaces, - // proper nouns and/or jargon, punctuation). - // - // NOTE: CR-LF special case has already been checked. - case 0x0000...0x02ff: return true - - // Non-combining kana: - // U+3041 ~ U+3096 - // U+30A1 ~ U+30FC - case 0x3041...0x3096: return true - case 0x30a1...0x30fc: return true - - // Non-combining modern (and some archaic) Cyrillic: - // U+0400 ~ U+0482 (first half of Cyrillic block) - case 0x0400...0x0482: return true - - // Modern Arabic, excluding extenders and prependers: - // U+061D ~ U+064A - case 0x061d...0x064a: return true - - // Precomposed Hangul syllables: - // U+AC00 ~ U+D7AF - case 0xac00...0xd7af: return true - - // Common general use punctuation, excluding extenders: - // U+2010 ~ U+2029 - case 0x2010...0x2029: return true - - // CJK punctuation characters, excluding extenders: - // U+3000 ~ U+3029 - case 0x3000...0x3029: return true - - // Full-width forms: - // U+FF01 ~ U+FF9D - case 0xFF01...0xFF9D: return true - - default: return false - } - } - return hasBreakWhenPaired(lhs) && hasBreakWhenPaired(rhs) -} - -// FIXME: This has terrible performance. -// FIXME: Replace with Unicode._CharacterRecognizer once it gets into a build. -struct _CharacterRecognizer { - private var string: String - - init() { - string = "" - } - - init(first: Unicode.Scalar) { - string = String(first) - } - - static func quickBreak( - between scalar1: Unicode.Scalar, - and scalar2: Unicode.Scalar - ) -> Bool? { - if scalar1 == Unicode.Scalar(_CR) && scalar2 == Unicode.Scalar(_LF) { return false } - if _hasGraphemeBreakBetween(scalar1, scalar2) { return true } - return nil - } - - mutating func hasBreak( - before next: Unicode.Scalar - ) -> Bool { - let next = String(next) - guard !string.isEmpty else { - string = next - return true - } - string.append(next) - let i = string.index(after: string.startIndex) - if i == string.endIndex { return false } - string = next - return true - } -} - -extension _CharacterRecognizer: Equatable { - static func ==(left: Self, right: Self) -> Bool { - left.string.utf8.elementsEqual(right.string.utf8) - } -} +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) +internal typealias _CharacterRecognizer = Unicode._CharacterRecognizer +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension _CharacterRecognizer { mutating func firstBreak( in str: Substring ) -> Range? { + #if true + var str = str + let scalarRange = str.withUTF8 { buffer in + self._firstBreak(inUncheckedUnsafeUTF8Buffer: buffer) + } + guard let scalarRange else { return nil } + let lower = str._utf8Index(at: scalarRange.lowerBound) + let upper = str._utf8Index(at: scalarRange.upperBound) + return lower ..< upper + #else guard !str.isEmpty else { return nil } let c = self.string.utf8.count if c == 0 { @@ -151,8 +52,11 @@ extension _CharacterRecognizer { let lower = str._utf8Index(at: offset - c) let upper = str._utf8Index(at: offset - c + scalarWidth) return lower ..< upper + #endif } } + +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) extension _CharacterRecognizer { init(partialCharacter: Substring.UnicodeScalarView) { self.init() @@ -257,31 +161,4 @@ extension _CharacterRecognizer { } } -extension String { - // FIXME: Remove once the stdlib entry point gets into a build. - func _index(roundingDown i: Index) -> Index { - guard i < endIndex else { return endIndex } - guard !i._isCharacterAligned else { return i } - return index(before: index(after: i)) - } -} - -extension Substring { - // FIXME: Remove once the stdlib entry point gets into a build. - func _index(roundingDown i: Index) -> Index { - index(i, offsetBy: 0) - } - - func _nextBreak(onOrAfter i: Index) -> Index { - let nearestDown = _index(roundingDown: i) - guard nearestDown != i else { return nearestDown } - return index(after: nearestDown) - } -} - -extension String.UnicodeScalarView { - // FIXME: Remove once the stdlib entry point gets into a build. - func _index(roundingDown i: Index) -> Index { - index(i, offsetBy: 0) - } -} +#endif diff --git a/Tests/RopeModuleTests/TestBigString.swift b/Tests/RopeModuleTests/TestBigString.swift index d5502406..34fde0df 100644 --- a/Tests/RopeModuleTests/TestBigString.swift +++ b/Tests/RopeModuleTests/TestBigString.swift @@ -9,9 +9,11 @@ // //===----------------------------------------------------------------------===// +#if swift(>=5.8) import RopeModule import XCTest +@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) class TestBigString: XCTestCase { override class func setUp() { // Turn off output buffering. @@ -538,3 +540,4 @@ class TestBigString: XCTestCase { } } } +#endif