Skip to content

Commit

Permalink
Fix casefold set (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely authored Dec 31, 2024
1 parent 9ccc25f commit c51a870
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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

0 comments on commit c51a870

Please sign in to comment.