Skip to content

Commit 809b085

Browse files
committed
Factor out nextScalarIndex for matchBitsetScalar
1 parent c2ee8cc commit 809b085

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/_StringProcessing/Engine/Processor.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,18 @@ extension Processor {
231231
currentPosition < end ? input.unicodeScalars[currentPosition] : nil
232232
}
233233

234+
func nextScalarIndex(offsetBy n: Int, boundaryCheck: Bool) -> Input.Index? {
235+
if let idx = input.unicodeScalars.index(currentPosition, offsetBy: 1, limitedBy: end),
236+
(!boundaryCheck || input.isOnGraphemeClusterBoundary(idx)) {
237+
return idx
238+
}
239+
return nil
240+
}
241+
234242
mutating func matchScalar(_ s: Unicode.Scalar, boundaryCheck: Bool) -> Bool {
235243
guard let curScalar = loadScalar(),
236244
curScalar == s,
237-
let idx = input.unicodeScalars.index(currentPosition, offsetBy: 1, limitedBy: end),
238-
(!boundaryCheck || input.isOnGraphemeClusterBoundary(idx))
245+
let idx = nextScalarIndex(offsetBy: 1, boundaryCheck: boundaryCheck)
239246
else {
240247
signalFailure()
241248
return false

0 commit comments

Comments
 (0)