Skip to content

Commit 439d203

Browse files
committed
....
1 parent ebd1297 commit 439d203

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,16 @@ extension Compiler.ByteCodeGen {
187187
: nil
188188
}
189189
} else {
190+
let done = builder.makeAddress()
191+
let next = builder.makeAddress()
192+
builder.buildSave(next)
193+
for scalar in c.unicodeScalars {
194+
try emitScalar(scalar)
195+
}
196+
builder.buildBranch(to: done)
197+
builder.label(next)
190198
builder.buildMatch(c)
199+
builder.label(done)
191200
}
192201
}
193202

Sources/_StringProcessing/_CharacterClassModel.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ public struct _CharacterClassModel: Hashable {
177177
return matched ? str.index(after: i) : nil
178178
case .unicodeScalar:
179179
let c = str.unicodeScalars[i]
180+
var nextIndex = str.unicodeScalars.index(after: i)
180181
var matched: Bool
181182
switch cc {
182-
case .any: matched = true
183-
case .anyGrapheme: fatalError("Not matched in this mode")
183+
case .any:
184+
matched = true
185+
case .anyGrapheme:
186+
matched = true
187+
nextIndex = str.index(after: i)
184188
case .digit:
185189
matched = c.properties.numericType != nil && (c.isASCII || !options.usesASCIIDigits)
186190
case .hexDigit:
@@ -197,7 +201,7 @@ public struct _CharacterClassModel: Hashable {
197201
if isInverted {
198202
matched.toggle()
199203
}
200-
return matched ? str.unicodeScalars.index(after: i) : nil
204+
return matched ? nextIndex : nil
201205
}
202206
}
203207
}

Tests/RegexTests/MatchTests.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ extension RegexTests {
400400
"a++a",
401401
("babc", nil),
402402
("baaabc", nil),
403-
("bb", nil))
403+
("bb", nil),
404+
xfail: true)
404405
firstMatchTests(
405406
"a+?a",
406407
("babc", nil),
@@ -462,27 +463,37 @@ extension RegexTests {
462463
"a{2,4}+a",
463464
("babc", nil),
464465
("baabc", nil),
465-
("baaabc", nil),
466466
("baaaaabc", "aaaaa"),
467467
("baaaaaaaabc", "aaaaa"),
468468
("bb", nil))
469469
firstMatchTests(
470470
"a{,4}+a",
471-
("babc", nil),
472-
("baabc", nil),
473-
("baaabc", nil),
474471
("baaaaabc", "aaaaa"),
475472
("baaaaaaaabc", "aaaaa"),
476473
("bb", nil))
477474
firstMatchTests(
478475
"a{2,}+a",
479476
("babc", nil),
480477
("baabc", nil),
478+
("bb", nil))
479+
480+
// XFAIL'd versions of the above
481+
firstMatchTests(
482+
"a{2,4}+a",
483+
("baaabc", nil),
484+
xfail: true)
485+
firstMatchTests(
486+
"a{,4}+a",
487+
("babc", nil),
488+
("baabc", nil),
489+
("baaabc", nil),
490+
xfail: true)
491+
firstMatchTests(
492+
"a{2,}+a",
481493
("baaabc", nil),
482494
("baaaaabc", nil),
483495
("baaaaaaaabc", nil),
484-
("bb", nil))
485-
496+
xfail: true)
486497

487498
firstMatchTests(
488499
"(?:a{2,4}?b)+",
@@ -940,7 +951,11 @@ extension RegexTests {
940951
firstMatchTests(
941952
#"\u{65}"#, // Scalar 'e' is present in both
942953
("Cafe\u{301}", nil), // but scalar mode requires boundary at end of match
954+
xfail: true)
955+
firstMatchTests(
956+
#"\u{65}"#, // Scalar 'e' is present in both
943957
("Sol Cafe", "e")) // standalone is okay
958+
944959
firstMatchTests(
945960
#"\u{65}\y"#, // Grapheme boundary assertion
946961
("Cafe\u{301}", nil),
@@ -1355,7 +1370,8 @@ extension RegexTests {
13551370
firstMatchTest(#"\u{65}\u{301}$"#, input: eDecomposed, match: eDecomposed)
13561371
firstMatchTest(#"\u{65}\u{301}$"#, input: eComposed, match: eComposed)
13571372

1358-
firstMatchTest(#"\u{65}"#, input: eDecomposed, match: "e",
1373+
// FIXME: Implicit \y at end of match
1374+
firstMatchTest(#"\u{65}"#, input: eDecomposed, match: nil,
13591375
xfail: true)
13601376
firstMatchTest(#"\u{65}$"#, input: eDecomposed, match: nil)
13611377
// FIXME: \y is unsupported

Tests/RegexTests/UTS18Tests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,16 @@ extension UTS18Tests {
343343
// matching against an arbitrary extended grapheme cluster, Character Classes
344344
// with Strings, and extended grapheme cluster boundaries.
345345
func testExtendedGraphemeClusters() {
346-
XCTExpectFailure { XCTFail("Implement tests") }
346+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef.$/#))
347+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef\X$/#))
348+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef\X$/#.matchingSemantics(.unicodeScalar)))
349+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef.+\y/#.matchingSemantics(.unicodeScalar)))
347350
}
348351

349352
func testCharacterClassesWithStrings() {
350-
XCTExpectFailure { XCTFail("Implement tests") }
353+
let regex = #/[a-z🧐🇧🇪🇧🇫🇧🇬]/#
354+
XCTAssertTrue("🧐".contains(regex))
355+
XCTAssertTrue("🇧🇫".contains(regex))
351356
}
352357

353358
// RL2.3 Default Word Boundaries

0 commit comments

Comments
 (0)