Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casefold set #151

Merged
merged 2 commits into from
Dec 31, 2024
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
2 changes: 1 addition & 1 deletion regex.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ srcDir = "src"
skipDirs = @["tests", "bench", "docs"]

requires "nim >= 1.6.0"
requires "unicodedb >= 0.13.1"
requires "unicodedb >= 0.13.2"

template execTest(lang, target: static string) =
doAssert lang in ["c", "js"]
Expand Down
7 changes: 3 additions & 4 deletions src/regex/exptransformation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,12 @@ func applyFlag(n: var Node, f: Flag) =
n.cp = n.cp.simpleCaseFold
# todo: apply recursevely to
# shorthands of reInSet/reNotSet (i.e: [:ascii:])
# XXX add all casefolds that map to the cp instead of swapCase
if n.kind in {reInSet, reNotSet}:
var cps = newSeq[Rune]()
for cp in items n.cps:
let cp2 = cp.swapCase()
if cp != cp2:
cps.add cp2
for cp2 in cp.resolveCaseFold:
if cp != cp2:
cps.add cp2
n.cps.add cps
for sl in n.ranges[0 .. ^1]:
let cpa = sl.a.swapCase()
Expand Down
11 changes: 8 additions & 3 deletions tests/tests_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,14 @@ test "rebar":
check findAllBounds("s", re2(r"ſ", {regexCaseless})) == @[0 .. 0]
check findAllBounds("ſ", re2(r"S", {regexCaseless})) == @[0 .. 1]
check findAllBounds("S", re2(r"ſ", {regexCaseless})) == @[0 .. 0]
# XXX fix
#check match("s", re2(r"[ſ]", {regexCaseless}))
#check match("ſ", re2(r"[s]", {regexCaseless}))
check match("s", re2(r"[ſ]", {regexCaseless}))
check match("ſ", re2(r"[s]", {regexCaseless}))
check match("S", re2(r"[ſ]", {regexCaseless}))
check match("ſ", re2(r"[S]", {regexCaseless}))
check findAllBounds("ſ", re2(r"[s]", {regexCaseless})) == @[0 .. 1]
check findAllBounds("s", re2(r"[ſ]", {regexCaseless})) == @[0 .. 0]
check findAllBounds("ſ", re2(r"[S]", {regexCaseless})) == @[0 .. 1]
check findAllBounds("S", re2(r"[ſ]", {regexCaseless})) == @[0 .. 0]
check match("a", re2(r"A", {regexCaseless}))
check match("A", re2(r"a", {regexCaseless}))
check match("@", re2(r"@", {regexCaseless}))
Expand Down
Loading