Skip to content

Commit 676ff8f

Browse files
committed
Address Karoy's comments
1 parent b555c43 commit 676ff8f

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

stdlib/public/core/StringWordBreaking.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ extension _StringGuts {
2121
return i
2222
}
2323

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
3224
let start = previousWordIndex(endingAt: offset)
3325
let end = nextWordIndex(startingAt: start)
3426
_internalInvariant(offset <= end, "Word breaking inconsistency")
@@ -104,7 +96,7 @@ extension _StringGuts {
10496

10597
@inline(never)
10698
internal func _foreignPreviousWordIndex(endingAt i: Int) -> Int {
107-
#if _runtime(_ObjC)
99+
#if _runtime(_ObjC)
108100
return previousWordBoundary(endingAt: i) {
109101
_internalInvariant($0 <= count)
110102

stdlib/public/core/UnicodeSPI.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ extension String {
208208
@_spi(_Unicode)
209209
@available(SwiftStdlib 5.7, *)
210210
public func _wordIndex(after i: String.Index) -> String.Index {
211-
_precondition(i < endIndex)
212-
213211
let i = _guts.validateWordIndex(i)
214212

215213
let next = _guts.nextWordIndex(startingAt: i._encodedOffset)
@@ -219,12 +217,17 @@ extension String {
219217
@_spi(_Unicode)
220218
@available(SwiftStdlib 5.7, *)
221219
public func _wordIndex(before i: String.Index) -> String.Index {
222-
_precondition(i > startIndex)
223-
_precondition(i <= endIndex)
224-
225220
let i = _guts.validateInclusiveWordIndex(i)
226221

222+
_precondition(i > startIndex, "String index is out of bounds")
223+
227224
let previous = _guts.previousWordIndex(endingAt: i._encodedOffset)
228225
return String.Index(_encodedOffset: previous)
229226
}
227+
228+
@_spi(_Unicode)
229+
@available(SwiftStdlib 5.7, *)
230+
public func _nearestWordIndex(atOrBelow i: String.Index) -> String.Index {
231+
_guts.roundDownToNearestWord(i)
232+
}
230233
}

0 commit comments

Comments
 (0)