@@ -251,16 +251,16 @@ extension Substring: StringProtocol {
251
251
///
252
252
/// - has the right encoding,
253
253
/// - is within bounds, and
254
- /// - is scalar aligned.
254
+ /// - is character aligned within this substring .
255
255
///
256
256
/// It does not mark the encoding of the returned index.
257
257
internal func _uncheckedIndex( after i: Index ) -> Index {
258
258
_internalInvariant ( _wholeGuts. hasMatchingEncoding ( i) )
259
259
_internalInvariant ( i. _isScalarAligned)
260
260
_internalInvariant ( i >= startIndex && i < endIndex)
261
261
262
- // Implicit precondition : `i` must be `Character`-aligned within this
263
- // substring, even if it doesn't have the corresponding flag set.
262
+ // Note : `i` must be `Character`-aligned within this substring, even if it
263
+ // doesn't have the corresponding flag set.
264
264
265
265
// TODO: known-ASCII fast path, single-scalar-grapheme fast path, etc.
266
266
let stride = _characterStride ( startingAt: i)
@@ -309,16 +309,16 @@ extension Substring: StringProtocol {
309
309
///
310
310
/// - has the right encoding,
311
311
/// - is within bounds, and
312
- /// - is scalar aligned.
312
+ /// - is character aligned within this substring .
313
313
///
314
314
/// It does not mark the encoding of the returned index.
315
315
internal func _uncheckedIndex( before i: Index ) -> Index {
316
316
_internalInvariant ( _wholeGuts. hasMatchingEncoding ( i) )
317
317
_internalInvariant ( i. _isScalarAligned)
318
318
_internalInvariant ( i > startIndex && i <= endIndex)
319
319
320
- // Implicit precondition : `i` must be `Character`-aligned within this
321
- // substring, even if it doesn't have the corresponding flag set.
320
+ // Note : `i` must be `Character`-aligned within this substring, even if it
321
+ // doesn't have the corresponding flag set.
322
322
323
323
// TODO: known-ASCII fast path, single-scalar-grapheme fast path, etc.
324
324
let priorStride = _characterStride ( endingAt: i)
@@ -562,17 +562,18 @@ extension Substring: StringProtocol {
562
562
in: newOffsetBounds. lowerBound ..< _wholeGuts. count)
563
563
_slice. _startIndex = String . Index (
564
564
encodedOffset: startIndex. _encodedOffset,
565
- transcodedOffset : 0 ,
566
- characterStride : newStride ) . _scalarAligned. _knownUTF8
565
+ characterStride : newStride
566
+ ) . _scalarAligned. _knownUTF8
567
567
}
568
568
569
569
// Update endIndex.
570
570
if newOffsetBounds. upperBound != endIndex. _encodedOffset {
571
571
_slice. _endIndex = Index (
572
- encodedOffset: newOffsetBounds. upperBound,
573
- transcodedOffset: 0
572
+ _encodedOffset: newOffsetBounds. upperBound
574
573
) . _scalarAligned. _knownUTF8
575
574
}
575
+
576
+ // TODO(lorentey): Mark new bounds character aligned if possible
576
577
}
577
578
578
579
/// Creates a string from the given Unicode code units in the specified
@@ -1214,7 +1215,7 @@ extension Substring.UnicodeScalarView: RangeReplaceableCollection {
1214
1215
public mutating func replaceSubrange< C: Collection > (
1215
1216
_ subrange: Range < Index > , with replacement: C
1216
1217
) where C. Element == Element {
1217
- // TODO(lorentey): Review index validation
1218
+ // TODO(lorentey): Don't forward to slice
1218
1219
let subrange = _wholeGuts. validateScalarRange ( subrange, in: _bounds)
1219
1220
_slice. replaceSubrange ( subrange, with: replacement)
1220
1221
}
0 commit comments