Skip to content

Commit ff58d54

Browse files
committed
[stdlib][NFC] Substring adjustments
1 parent 3616a05 commit ff58d54

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

stdlib/public/core/Substring.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,16 @@ extension Substring: StringProtocol {
251251
///
252252
/// - has the right encoding,
253253
/// - is within bounds, and
254-
/// - is scalar aligned.
254+
/// - is character aligned within this substring.
255255
///
256256
/// It does not mark the encoding of the returned index.
257257
internal func _uncheckedIndex(after i: Index) -> Index {
258258
_internalInvariant(_wholeGuts.hasMatchingEncoding(i))
259259
_internalInvariant(i._isScalarAligned)
260260
_internalInvariant(i >= startIndex && i < endIndex)
261261

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.
264264

265265
// TODO: known-ASCII fast path, single-scalar-grapheme fast path, etc.
266266
let stride = _characterStride(startingAt: i)
@@ -309,16 +309,16 @@ extension Substring: StringProtocol {
309309
///
310310
/// - has the right encoding,
311311
/// - is within bounds, and
312-
/// - is scalar aligned.
312+
/// - is character aligned within this substring.
313313
///
314314
/// It does not mark the encoding of the returned index.
315315
internal func _uncheckedIndex(before i: Index) -> Index {
316316
_internalInvariant(_wholeGuts.hasMatchingEncoding(i))
317317
_internalInvariant(i._isScalarAligned)
318318
_internalInvariant(i > startIndex && i <= endIndex)
319319

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.
322322

323323
// TODO: known-ASCII fast path, single-scalar-grapheme fast path, etc.
324324
let priorStride = _characterStride(endingAt: i)
@@ -562,17 +562,18 @@ extension Substring: StringProtocol {
562562
in: newOffsetBounds.lowerBound ..< _wholeGuts.count)
563563
_slice._startIndex = String.Index(
564564
encodedOffset: startIndex._encodedOffset,
565-
transcodedOffset: 0,
566-
characterStride: newStride)._scalarAligned._knownUTF8
565+
characterStride: newStride
566+
)._scalarAligned._knownUTF8
567567
}
568568

569569
// Update endIndex.
570570
if newOffsetBounds.upperBound != endIndex._encodedOffset {
571571
_slice._endIndex = Index(
572-
encodedOffset: newOffsetBounds.upperBound,
573-
transcodedOffset: 0
572+
_encodedOffset: newOffsetBounds.upperBound
574573
)._scalarAligned._knownUTF8
575574
}
575+
576+
// TODO(lorentey): Mark new bounds character aligned if possible
576577
}
577578

578579
/// Creates a string from the given Unicode code units in the specified
@@ -1214,7 +1215,7 @@ extension Substring.UnicodeScalarView: RangeReplaceableCollection {
12141215
public mutating func replaceSubrange<C: Collection>(
12151216
_ subrange: Range<Index>, with replacement: C
12161217
) where C.Element == Element {
1217-
// TODO(lorentey): Review index validation
1218+
// TODO(lorentey): Don't forward to slice
12181219
let subrange = _wholeGuts.validateScalarRange(subrange, in: _bounds)
12191220
_slice.replaceSubrange(subrange, with: replacement)
12201221
}

0 commit comments

Comments
 (0)