File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Sources/_StringProcessing/Regex Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,11 @@ extension Regex {
158
158
if let m = try _match ( input, in: low..< high, mode: . partialFromFront) {
159
159
return m
160
160
}
161
- input. formIndex ( after: & low)
161
+ if regex. program. loweredProgram. initialOptions. semanticLevel == . graphemeCluster {
162
+ input. formIndex ( after: & low)
163
+ } else {
164
+ input. unicodeScalars. formIndex ( after: & low)
165
+ }
162
166
}
163
167
return nil
164
168
}
Original file line number Diff line number Diff line change @@ -1612,5 +1612,15 @@ extension RegexTests {
1612
1612
1613
1613
// TODO: Add test for grapheme boundaries at start/end of match
1614
1614
1615
+ func testCase( ) {
1616
+ let regex = try ! Regex ( #".\N{SPARKLING HEART}."# )
1617
+ let input = " 🧟♀️💖🧠 or 🧠💖☕️ "
1618
+ let characterMatches = input. matches ( of: regex)
1619
+ XCTAssertEqual ( characterMatches. map { $0. 0 } , [ " 🧟♀️💖🧠 " , " 🧠💖☕️ " ] )
1620
+
1621
+ let scalarMatches = input. matches ( of: regex. matchingSemantics ( . unicodeScalar) )
1622
+ let scalarExpected : [ Substring ] = [ " \u{FE0F} 💖🧠 " , " 🧠💖☕ " ]
1623
+ XCTAssertEqual ( scalarMatches. map { $0. 0 } , scalarExpected)
1624
+ }
1615
1625
}
1616
1626
You can’t perform that action at this time.
0 commit comments