Skip to content

Commit 3b31f75

Browse files
authored
(140308690) AttributedString APIs for operations over noncontiguous ranges (#1145)
This PR implements the API changes proposed in SF-0014 by adding a new DiscontiguousAttributedSubstring type (the result of slicing an AttributedString with a RangeSet) which vends out slices of each underlying view, an upgraded Runs view which now handles discontiguous segments, and performs operations over the discontiguous subranges.
1 parent 2db87df commit 3b31f75

8 files changed

+1214
-152
lines changed

Sources/FoundationEssentials/AttributedString/AttributedString+Guts.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ extension AttributedString.Guts {
105105
if left._guts === right._guts, left._strBounds == right._strBounds { return true }
106106

107107
guard left.count == right.count else { return false }
108+
guard !left.isEmpty else { return true }
108109

109-
var leftIndex = left._strBounds.lowerBound
110-
var rightIndex = right._strBounds.lowerBound
110+
guard var leftIndex = left._strBounds.ranges.first?.lowerBound, var rightIndex = right._strBounds.ranges.first?.lowerBound else { return false }
111111

112112
var it1 = left.makeIterator()
113113
var it2 = right.makeIterator()
@@ -135,8 +135,8 @@ extension AttributedString.Guts {
135135
return false
136136
}
137137
}
138-
assert(leftIndex == left._strBounds.upperBound)
139-
assert(rightIndex == right._strBounds.upperBound)
138+
assert(leftIndex == left._strBounds.ranges.last?.upperBound)
139+
assert(rightIndex == right._strBounds.ranges.last?.upperBound)
140140
return true
141141
}
142142

@@ -159,6 +159,10 @@ extension AttributedString.Guts {
159159

160160
extension AttributedString.Guts {
161161
internal func description(in range: Range<BigString.Index>) -> String {
162+
self.description(in: RangeSet(range))
163+
}
164+
165+
internal func description(in range: RangeSet<BigString.Index>) -> String {
162166
var result = ""
163167
let runs = Runs(self, in: range)
164168
for run in runs {

0 commit comments

Comments
 (0)