diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-10 00:46:26 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-10 00:51:46 +0200 |
commit | b5081e76373b27f38caa1f1f202aa7f368013a8a (patch) | |
tree | 5ebb901002a5715a45d951e5c1d2a64b1a3365b0 /src/utils/twtstr.nim | |
parent | de0251debf593b82f5edcc8bf0e155eb55b5fd5f (diff) | |
download | chawan-b5081e76373b27f38caa1f1f202aa7f368013a8a.tar.gz |
twtstr: remove pointless lookup tables
it's a waste of space; we don't use these *that* much.
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 4f51d6a8..226714d7 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -73,27 +73,19 @@ func startsWithNoCase*(str, prefix: string): bool = if str[i].toLowerAscii() != prefix[i].toLowerAscii(): return false inc i -const hexCharMap = (func(): array[char, int] = - for i in 0..255: - case chr(i) - of '0'..'9': result[char(i)] = i - ord('0') - of 'a'..'f': result[char(i)] = i - ord('a') + 10 - of 'A'..'F': result[char(i)] = i - ord('A') + 10 - else: result[char(i)] = -1 -)() - -const decCharMap = (func(): array[char, int] = - for i in 0..255: - case char(i) - of '0'..'9': result[char(i)] = i - ord('0') - else: result[char(i)] = -1 -)() - func hexValue*(c: char): int = - return hexCharMap[c] + if c in AsciiDigit: + return int(c) - int('0') + if c in 'a'..'f': + return int(c) - int('a') + 0xA + if c in 'A'..'F': + return int(c) - int('A') + 0xA + return -1 func decValue*(c: char): int = - return decCharMap[c] + if c in AsciiDigit: + return int(c) - int('0') + return -1 func isAscii*(s: string): bool = for c in s: |