diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-29 13:39:58 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-29 13:51:55 +0200 |
commit | 19068fd7d803a157de671e189e01731bc903ba9e (patch) | |
tree | aae00bec40a00b67586373199cfe6d9789e19013 /src/utils/twtstr.nim | |
parent | 1dd9eba6aba9760339fbef9bbd4244108fac2eab (diff) | |
download | chawan-19068fd7d803a157de671e189e01731bc903ba9e.tar.gz |
Factor out map search, remove sugar
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 35023290..0c37439a 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -3,7 +3,6 @@ import strutils import unicode import os import math -import sugar import sequtils import options import punycode @@ -12,6 +11,7 @@ import bindings/libunicode import data/idna import data/charwidth import utils/opt +import utils/map when defined(posix): import posix @@ -308,7 +308,8 @@ const romanNumbers = [ (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I") ] -const romanNumbers_lower = romanNumbers.map((x) => (x[0], x[1].tolower())) +const romanNumbers_lower = romanNumbers.map(proc(x: auto): auto = + (x[0], x[1].tolower())) func romanNumber*(i: int): string = return number_additive(i, 1..3999, romanNumbers) @@ -721,6 +722,7 @@ func unicodeToAscii*(s: string, checkhyphens, checkbidi, checkjoiners, transitio return none(string) #error return some(labels.join('.')) + # https://www.w3.org/TR/xml/#NT-Name const NameStartCharRanges = [ (0xC0, 0xD6), @@ -755,7 +757,7 @@ func matchNameProduction*(str: string): bool = inc i else: fastRuneAt(str, i, r) - if binarySearch(NameStartCharRanges, int32(r), (x, y) => cmp(x[0], y)) == -1: + if not isInRange(NameStartCharRanges, int32(r)): return false # NameChar while i < str.len: @@ -765,9 +767,9 @@ func matchNameProduction*(str: string): bool = inc i else: fastRuneAt(str, i, r) - if binarySearch(NameStartCharRanges, int32(r), (x, y) => cmp(x[0], y)) == -1: - if binarySearch(NameCharRanges, int32(r), (x, y) => cmp(x[0], y)) == -1: - return false + if not isInRange(NameStartCharRanges, int32(r)) and + not isInMap(NameCharRanges, int32(r)): + return false return true func matchQNameProduction*(s: string): bool = |