diff options
author | bptato <nincsnevem662@gmail.com> | 2021-11-20 13:11:37 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-11-20 13:11:42 +0100 |
commit | c7347c46b6bbce1194849ae5c8612b17b2b396ed (patch) | |
tree | 96c17148d75256b96314a84cf73db42b1973abeb /src/utils/twtstr.nim | |
parent | 8579619813e6c65f9bfe52f3429292b661838f38 (diff) | |
download | chawan-c7347c46b6bbce1194849ae5c8612b17b2b396ed.tar.gz |
Fix delete character
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index d2a06165..b5524b13 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -72,11 +72,29 @@ func isControlChar*(r: Rune): bool = of Rune(0x7F): return true else: return false +func genControlCharMap*(): string = + for c in low(char)..high(char): + if c == '?': + result &= char(127) + else: + result &= char(bitand(int(c), 0x1f)) + +const controlCharMap = genControlCharMap() + func getControlChar*(c: char): char = - return char(bitand(int(c), 0x1f)) + return controlCharMap[int(c)] + +func genControlLetterMap*(): string = + for c in low(char)..high(char): + if c == char(127): + result &= '?' + else: + result &= char(bitor(int(c), 0x40)) + +const controlLetterMap = genControlLetterMap() func getControlLetter*(c: char): char = - return char(bitor(int(c), 0x40)) + return controlLetterMap[int(c)] func findChar*(str: string, c: char, start: int = 0): int = var i = start |