From e39d3765a7add4adb972e5af49d16c483160fc4c Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 13 Mar 2024 22:11:30 +0100 Subject: twtstr: simplify control char procs --- src/utils/twtstr.nim | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'src/utils/twtstr.nim') 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 -- cgit 1.4.1-2-gfad0