@@ -200,9 +200,9 @@ extension Substring: StringProtocol {
200
200
public var endIndex : Index { _slice. _endIndex }
201
201
202
202
public func index( after i: Index ) -> Index {
203
- // Note: in Swift 5.6 and below , this method used to be inlinable,
204
- // forwarding to `_slice.base.index(after:)`. Unfortunately, that approach
205
- // isn't compatible with SE-0180, as it allows Unicode scalars outside the
203
+ // Note: Prior to Swift 5.7 , this method used to be inlinable, forwarding to
204
+ // `_slice.base.index(after:)`. Unfortunately, that approach isn't
205
+ // compatible with SE-0180, as it allows Unicode scalars outside the
206
206
// substring to affect grapheme breaking results within the substring. This
207
207
// leads to Collection conformance issues when the `Substring`'s bounds do
208
208
// not fall on grapheme boundaries in `base`.
@@ -256,9 +256,9 @@ extension Substring: StringProtocol {
256
256
}
257
257
258
258
public func index( before i: Index ) -> Index {
259
- // Note: in Swift 5.6 and below , this method used to be inlinable,
260
- // forwarding to `_slice.base.index(before:)`. Unfortunately, that approach
261
- // isn't compatible with SE-0180, as it allows Unicode scalars outside the
259
+ // Note: Prior to Swift 5.7 , this method used to be inlinable, forwarding to
260
+ // `_slice.base.index(before:)`. Unfortunately, that approach isn't
261
+ // compatible with SE-0180, as it allows Unicode scalars outside the
262
262
// substring to affect grapheme breaking results within the substring. This
263
263
// leads to Collection conformance issues when the `Substring`'s bounds do
264
264
// not fall on grapheme boundaries in `base`.
@@ -294,26 +294,26 @@ extension Substring: StringProtocol {
294
294
_internalInvariant ( priorOffset >= startIndex. _encodedOffset)
295
295
296
296
var r = Index (
297
- encodedOffset: priorOffset, characterStride: priorStride)
297
+ encodedOffset: priorOffset, characterStride: priorStride
298
+ ) . _scalarAligned
298
299
299
300
// Don't set the `_isCharacterAligned` bit in indices of exotic substrings
300
301
// whose startIndex isn't aligned on a grapheme cluster boundary. (Their
301
302
// grapheme breaks may not match with those in `base`.)
302
303
if _startIsCharacterAligned {
303
304
r = r. _characterAligned
304
- } else {
305
- r = r. _scalarAligned
306
305
}
306
+
307
307
return r
308
308
}
309
309
310
310
public func index( _ i: Index , offsetBy distance: Int ) -> Index {
311
- // Note: in Swift 5.6 and below , this method used to be inlinable,
312
- // forwarding to `_slice.base.index(_:offsetBy:)`. Unfortunately, that
313
- // approach isn't compatible with SE-0180, as it allows Unicode scalars
314
- // outside the substring to affect grapheme breaking results within the
315
- // substring. This leads to Collection conformance issues when the
316
- // `Substring`'s bounds do not fall on grapheme boundaries in `base`.
311
+ // Note: Prior to Swift 5.7 , this method used to be inlinable, forwarding to
312
+ // `_slice.base.index(_:offsetBy:)`. Unfortunately, that approach isn't
313
+ // compatible with SE-0180, as it allows Unicode scalars outside the
314
+ // substring to affect grapheme breaking results within the substring. This
315
+ // leads to Collection conformance issues when the `Substring`'s bounds do
316
+ // not fall on grapheme boundaries in `base`.
317
317
318
318
// TODO: known-ASCII and single-scalar-grapheme fast path, etc.
319
319
var i = _wholeGuts. validateInclusiveCharacterIndex ( i, in: _bounds)
@@ -334,12 +334,12 @@ extension Substring: StringProtocol {
334
334
public func index(
335
335
_ i: Index , offsetBy distance: Int , limitedBy limit: Index
336
336
) -> Index ? {
337
- // Note: in Swift 5.6 and below , this method used to be inlinable,
338
- // forwarding to `_slice.base.index(_:offsetBy:limitedBy:)`. Unfortunately,
339
- // that approach isn't compatible with SE-0180, as it allows Unicode scalars
340
- // outside the substring to affect grapheme breaking results within the
341
- // substring. This leads to Collection conformance issues when the
342
- // `Substring`'s bounds do not fall on grapheme boundaries in `base`.
337
+ // Note: Prior to Swift 5.7 , this method used to be inlinable, forwarding to
338
+ // `_slice.base.index(_:offsetBy:limitedBy:)`. Unfortunately, that approach
339
+ // isn't compatible with SE-0180, as it allows Unicode scalars outside the
340
+ // substring to affect grapheme breaking results within the substring. This
341
+ // leads to Collection conformance issues when the `Substring`'s bounds do
342
+ // not fall on grapheme boundaries in `base`.
343
343
344
344
// Per SE-0180, `i` and `limit` are allowed to fall in between grapheme
345
345
// breaks, in which case this function must still terminate without trapping
@@ -372,12 +372,12 @@ extension Substring: StringProtocol {
372
372
}
373
373
374
374
public func distance( from start: Index , to end: Index ) -> Int {
375
- // Note: in Swift 5.6 and below , this method used to be inlinable,
376
- // forwarding to `_slice.base.distance(from:to:)`. Unfortunately, that
377
- // approach isn't compatible with SE-0180, as it allows Unicode scalars
378
- // outside the substring to affect grapheme breaking results within the
379
- // substring. This leads to Collection conformance issues when the
380
- // `Substring`'s bounds do not fall on grapheme boundaries in `base`.
375
+ // Note: Prior to Swift 5.7 , this method used to be inlinable, forwarding to
376
+ // `_slice.base.distance(from:to:)`. Unfortunately, that approach isn't
377
+ // compatible with SE-0180, as it allows Unicode scalars outside the
378
+ // substring to affect grapheme breaking results within the substring. This
379
+ // leads to Collection conformance issues when the `Substring`'s bounds do
380
+ // not fall on grapheme boundaries in `base`.
381
381
382
382
// FIXME: Due to the `index(after:)` problem above, this function doesn't
383
383
// always return consistent results when the given indices fall between
@@ -400,8 +400,7 @@ extension Substring: StringProtocol {
400
400
count += 1
401
401
i = _uncheckedIndex ( after: i)
402
402
}
403
- }
404
- else if i > end {
403
+ } else if i > end {
405
404
while i > end { // Note `<` instead of `==`
406
405
count -= 1
407
406
i = _uncheckedIndex ( before: i)
0 commit comments