diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-13 22:11:30 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-13 22:11:41 +0100 |
commit | e39d3765a7add4adb972e5af49d16c483160fc4c (patch) | |
tree | aae277df303559c5cd8b4f352f2f266e28a60ee8 /src/utils/twtstr.nim | |
parent | 0ce307ef4535004708840497004395f09b74d67f (diff) | |
download | chawan-e39d3765a7add4adb972e5af49d16c483160fc4c.tar.gz |
twtstr: simplify control char procs
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index fe6ba236..fb77c807 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -21,37 +21,20 @@ func onlyWhitespace*(s: string): bool = return true func isControlChar*(r: Rune): bool = - case r - of Rune(0x00)..Rune(0x1F): return true - of Rune(0x7F): return true - else: return false + return int(r) <= 0x1F or int(r) == 0x7F func isC0ControlOrSpace*(c: char): bool = return c in (Controls + {' '}) -func genControlCharMap*(): string = - for c in low(char)..high(char): - if c == '?': - result &= char(127) - else: - result &= char((int(c) and 0x1f)) - -const controlCharMap = genControlCharMap() - func getControlChar*(c: char): char = - return controlCharMap[int(c)] - -func genControlLetterMap*(): string = - for c in low(char)..high(char): - if c == char(127): - result &= '?' - else: - result &= char((int(c) or 0x40)) - -const controlLetterMap = genControlLetterMap() + if c == '?': + return char(127) + return char(int(c) and 0x1F) func getControlLetter*(c: char): char = - return controlLetterMap[int(c)] + if c == char(127): + return '?' + return char(int(c) or 0x40) func toHeaderCase*(str: string): string = result = str |