Skip to content

Commit 91177e6

Browse files
authored
Merge pull request #820 from swiftlang/word-breaking-818-6.2
[6.2] Work around word breaking issue
2 parents 2014cae + 463d5b0 commit 91177e6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎Sources/_StringProcessing/Unicode/WordBreaking.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ extension String {
8787
var j = maxIndex ?? range.lowerBound
8888

8989
while j < range.upperBound, j <= i {
90-
cache!.insert(j)
90+
// Workaround for underlying issue in https://github.com/swiftlang/swift-experimental-string-processing/issues/818
91+
let (inserted, _) = cache!.insert(j)
92+
guard inserted else { return true }
93+
9194
j = _wordIndex(after: j)
9295
}
9396

‎Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,22 @@ extension RegexDSLTests {
19461946
XCTAssertEqual(anyOutput[15].value as? Int, 123)
19471947
XCTAssertEqual(anyOutput[16].substring, "456")
19481948
}
1949+
1950+
func testIssue818() throws {
1951+
// Original report from https://github.com/swiftlang/swift-experimental-string-processing/issues/818
1952+
let clip = "⁠‘⁠⁠example.com⁠⁠’"
1953+
let clip2 = "\u{2060}\u{2018}\u{2060}\u{2060}example.com\u{2060}\u{2060}\u{2019}"
1954+
assert(clip.unicodeScalars.elementsEqual(clip2.unicodeScalars))
1955+
1956+
let pattern = Regex {
1957+
Anchor.wordBoundary // line A
1958+
"example"
1959+
Anchor.wordBoundary // line B
1960+
}
1961+
1962+
XCTAssertNotNil(clip.contains(pattern))
1963+
XCTAssertNotNil(clip2.contains(pattern))
1964+
}
19491965
}
19501966

19511967
extension Unicode.Scalar {

0 commit comments

Comments
 (0)