File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,6 @@ extension _StringGuts {
21
21
return i
22
22
}
23
23
24
- return _slowRoundDownToNearestWord ( i)
25
- }
26
-
27
- @inline ( never)
28
- internal func _slowRoundDownToNearestWord(
29
- _ i: String . Index
30
- ) -> String . Index {
31
- let offset = i. _encodedOffset
32
24
let start = previousWordIndex ( endingAt: offset)
33
25
let end = nextWordIndex ( startingAt: start)
34
26
_internalInvariant ( offset <= end, " Word breaking inconsistency " )
@@ -104,7 +96,7 @@ extension _StringGuts {
104
96
105
97
@inline ( never)
106
98
internal func _foreignPreviousWordIndex( endingAt i: Int ) -> Int {
107
- #if _runtime(_ObjC)
99
+ #if _runtime(_ObjC)
108
100
return previousWordBoundary ( endingAt: i) {
109
101
_internalInvariant ( $0 <= count)
110
102
Original file line number Diff line number Diff line change @@ -208,8 +208,6 @@ extension String {
208
208
@_spi ( _Unicode)
209
209
@available ( SwiftStdlib 5 . 7 , * )
210
210
public func _wordIndex( after i: String . Index ) -> String . Index {
211
- _precondition ( i < endIndex)
212
-
213
211
let i = _guts. validateWordIndex ( i)
214
212
215
213
let next = _guts. nextWordIndex ( startingAt: i. _encodedOffset)
@@ -219,12 +217,17 @@ extension String {
219
217
@_spi ( _Unicode)
220
218
@available ( SwiftStdlib 5 . 7 , * )
221
219
public func _wordIndex( before i: String . Index ) -> String . Index {
222
- _precondition ( i > startIndex)
223
- _precondition ( i <= endIndex)
224
-
225
220
let i = _guts. validateInclusiveWordIndex ( i)
226
221
222
+ _precondition ( i > startIndex, " String index is out of bounds " )
223
+
227
224
let previous = _guts. previousWordIndex ( endingAt: i. _encodedOffset)
228
225
return String . Index ( _encodedOffset: previous)
229
226
}
227
+
228
+ @_spi ( _Unicode)
229
+ @available ( SwiftStdlib 5 . 7 , * )
230
+ public func _nearestWordIndex( atOrBelow i: String . Index ) -> String . Index {
231
+ _guts. validateInclusiveWordIndex ( i)
232
+ }
230
233
}
You can’t perform that action at this time.
0 commit comments