File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Sources/_StringProcessing/Unicode Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -81,18 +81,18 @@ extension String {
81
81
}
82
82
83
83
if #available( SwiftStdlib 5 . 7 , * ) {
84
- var indices : Set < String . Index > = [ ]
84
+ if cache == nil {
85
+ cache = [ ]
86
+ }
85
87
var j = maxIndex ?? range. lowerBound
86
88
87
89
while j < range. upperBound, j <= i {
88
- indices . insert ( j)
90
+ cache! . insert ( j)
89
91
j = _wordIndex ( after: j)
90
92
}
91
93
92
- cache = indices
93
94
maxIndex = j
94
-
95
- return indices. contains ( i)
95
+ return cache!. contains ( i)
96
96
} else {
97
97
return false
98
98
}
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