@@ -300,47 +300,6 @@ extension _StringGuts {
300300 scalarAlign ( validateInclusiveSubscalarIndex ( i, in: bounds) ) ,
301301 in: bounds)
302302 }
303-
304- internal func validateCharacterRange(
305- _ range: Range < String . Index >
306- ) -> Range < String . Index > {
307- if
308- isFastCharacterIndex ( range. lowerBound) ,
309- isFastCharacterIndex ( range. upperBound)
310- {
311- _precondition ( range. upperBound. _encodedOffset <= count,
312- " String index range is out of bounds " )
313- return range
314- }
315-
316- let r = validateSubscalarRange ( range)
317- let l = roundDownToNearestCharacter ( scalarAlign ( r. lowerBound) )
318- let u = roundDownToNearestCharacter ( scalarAlign ( r. upperBound) )
319- return Range ( _uncheckedBounds: ( l, u) )
320- }
321-
322- internal func validateCharacterRange(
323- _ range: Range < String . Index > ,
324- in bounds: Range < String . Index >
325- ) -> Range < String . Index > {
326- _internalInvariant ( bounds. upperBound <= endIndex)
327-
328- if
329- isFastCharacterIndex ( range. lowerBound) ,
330- isFastCharacterIndex ( range. upperBound)
331- {
332- _precondition (
333- range. lowerBound >= bounds. lowerBound
334- && range. upperBound <= bounds. upperBound,
335- " String index range is out of bounds " )
336- return range
337- }
338-
339- let r = validateSubscalarRange ( range, in: bounds)
340- let l = roundDownToNearestCharacter ( scalarAlign ( r. lowerBound) , in: bounds)
341- let u = roundDownToNearestCharacter ( scalarAlign ( r. upperBound) , in: bounds)
342- return Range ( _uncheckedBounds: ( l, u) )
343- }
344303}
345304
346305// Temporary additions to deal with binary compatibility issues with existing
@@ -439,3 +398,20 @@ extension _StringGuts {
439398 scalarAlign ( validateInclusiveSubscalarIndex_5_7 ( i) ) )
440399 }
441400}
401+
402+ // Word index validation (String)
403+ extension _StringGuts {
404+ internal func validateWordIndex(
405+ _ i: String . Index
406+ ) -> String . Index {
407+ return roundDownToNearestWord ( scalarAlign ( validateSubscalarIndex ( i) ) )
408+ }
409+
410+ internal func validateInclusiveWordIndex(
411+ _ i: String . Index
412+ ) -> String . Index {
413+ return roundDownToNearestWord (
414+ scalarAlign ( validateInclusiveSubscalarIndex ( i) )
415+ )
416+ }
417+ }
0 commit comments