Skip to content

Commit c51a870

Browse files
authored
Fix casefold set (#151)
1 parent 9ccc25f commit c51a870

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

regex.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ srcDir = "src"
88
skipDirs = @["tests", "bench", "docs"]
99

1010
requires "nim >= 1.6.0"
11-
requires "unicodedb >= 0.13.1"
11+
requires "unicodedb >= 0.13.2"
1212

1313
template execTest(lang, target: static string) =
1414
doAssert lang in ["c", "js"]

src/regex/exptransformation.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,12 @@ func applyFlag(n: var Node, f: Flag) =
183183
n.cp = n.cp.simpleCaseFold
184184
# todo: apply recursevely to
185185
# shorthands of reInSet/reNotSet (i.e: [:ascii:])
186-
# XXX add all casefolds that map to the cp instead of swapCase
187186
if n.kind in {reInSet, reNotSet}:
188187
var cps = newSeq[Rune]()
189188
for cp in items n.cps:
190-
let cp2 = cp.swapCase()
191-
if cp != cp2:
192-
cps.add cp2
189+
for cp2 in cp.resolveCaseFold:
190+
if cp != cp2:
191+
cps.add cp2
193192
n.cps.add cps
194193
for sl in n.ranges[0 .. ^1]:
195194
let cpa = sl.a.swapCase()

tests/tests_misc.nim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,14 @@ test "rebar":
710710
check findAllBounds("s", re2(r"ſ", {regexCaseless})) == @[0 .. 0]
711711
check findAllBounds("ſ", re2(r"S", {regexCaseless})) == @[0 .. 1]
712712
check findAllBounds("S", re2(r"ſ", {regexCaseless})) == @[0 .. 0]
713-
# XXX fix
714-
#check match("s", re2(r"[ſ]", {regexCaseless}))
715-
#check match("ſ", re2(r"[s]", {regexCaseless}))
713+
check match("s", re2(r"[ſ]", {regexCaseless}))
714+
check match("ſ", re2(r"[s]", {regexCaseless}))
715+
check match("S", re2(r"[ſ]", {regexCaseless}))
716+
check match("ſ", re2(r"[S]", {regexCaseless}))
717+
check findAllBounds("ſ", re2(r"[s]", {regexCaseless})) == @[0 .. 1]
718+
check findAllBounds("s", re2(r"[ſ]", {regexCaseless})) == @[0 .. 0]
719+
check findAllBounds("ſ", re2(r"[S]", {regexCaseless})) == @[0 .. 1]
720+
check findAllBounds("S", re2(r"[ſ]", {regexCaseless})) == @[0 .. 0]
716721
check match("a", re2(r"A", {regexCaseless}))
717722
check match("A", re2(r"a", {regexCaseless}))
718723
check match("@", re2(r"@", {regexCaseless}))

0 commit comments

Comments
 (0)