Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Sources/_StringProcessing/ByteCodeGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -773,11 +773,19 @@ fileprivate extension Compiler.ByteCodeGen {
case .atom(let atom):
switch atom {
case .char(let c):
// Single scalar ascii value character
guard let val = c._singleScalarAsciiValue else {
return false
if options.isCaseInsensitive && c.isCased {
// Cased character with case-insensitive matching; match only as an ASCII bitset
guard let bitset = DSLTree.CustomCharacterClass(members: [.atom(atom)]).asAsciiBitset(options) else {
return false
}
builder.buildQuantify(bitset: bitset, kind, minTrips, maxExtraTrips, isScalarSemantics: isScalarSemantics)
} else {
// Uncased character OR case-sensitive matching; match as a single scalar ascii value character
guard let val = c._singleScalarAsciiValue else {
return false
}
builder.buildQuantify(asciiChar: val, kind, minTrips, maxExtraTrips, isScalarSemantics: isScalarSemantics)
}
builder.buildQuantify(asciiChar: val, kind, minTrips, maxExtraTrips, isScalarSemantics: isScalarSemantics)

case .any:
builder.buildQuantifyAny(
Expand Down
35 changes: 35 additions & 0 deletions Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,41 @@ extension RegexTests {
("cafe", true),
("CaFe", true),
("EfAc", true))

matchTest(
#"(?i)a+b"#,
("ab", true),
("Ab", true),
("aB", true),
("AB", true),
("AaAab", true),
("aaaAB", true))
matchTest(
#"^(?i)a?b$"#,
("ab", true),
("Ab", true),
("aB", true),
("AB", true),
("aaB", false),
("b", true),
("B", true))
matchTest(
#"^(?i)[a]?b$"#,
("ab", true),
("Ab", true),
("aB", true),
("AB", true),
("b", true),
("B", true))
matchTest(
#"^(?i)a{2,4}b$"#,
("ab", false),
("Ab", false),
("AaB", true),
("aAB", true),
("aAaB", true),
("aAaAB", true),
("AaAaAB", false))
}

func testNonSemanticWhitespace() {
Expand Down