File tree 2 files changed +17
-6
lines changed
Sources/_StringProcessing/Unicode
2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -79,18 +79,18 @@ extension String {
79
79
}
80
80
81
81
if #available( SwiftStdlib 5 . 7 , * ) {
82
- var indices : Set < String . Index > = [ ]
82
+ if cache == nil {
83
+ cache = [ ]
84
+ }
83
85
var j = maxIndex ?? range. lowerBound
84
86
85
87
while j < range. upperBound, j <= i {
86
- indices . insert ( j)
88
+ cache! . insert ( j)
87
89
j = _wordIndex ( after: j)
88
90
}
89
91
90
- cache = indices
91
92
maxIndex = j
92
-
93
- return indices. contains ( i)
93
+ return cache!. contains ( i)
94
94
} else {
95
95
return false
96
96
}
Original file line number Diff line number Diff line change @@ -2381,7 +2381,18 @@ extension RegexTests {
2381
2381
XCTAssertTrue ( " cafe " . contains ( caseInsensitiveRegex) )
2382
2382
XCTAssertTrue ( " CaFe " . contains ( caseInsensitiveRegex) )
2383
2383
}
2384
-
2384
+
2385
+ // https://github.com/swiftlang/swift-experimental-string-processing/issues/768
2386
+ func testWordBoundaryCaching( ) throws {
2387
+ // This will first find word boundaries up til the middle before failing,
2388
+ // then it will find word boundaries til late in the string, then fail,
2389
+ // and finally should succeed on a word boundary cached from the first
2390
+ // attempt.
2391
+ let input = " first second third fourth "
2392
+ let regex = try Regex ( #".*second\bX|.*third\bX|.*first\b"# )
2393
+ XCTAssertTrue ( input. contains ( regex) )
2394
+ }
2395
+
2385
2396
// MARK: Character Semantics
2386
2397
2387
2398
var eComposed : String { " é " }
You can’t perform that action at this time.
0 commit comments