From 342a1a7f787fc260448842ee312cf29825f96ba6 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 20 Nov 2023 17:20:41 +0100 Subject: twtstr: remove tolower, isWhitespace * tolower: strutils toLowerAscii is good enough for the cases where we need it. Also, it's easy to confuse with unicode toLower and vice versa. * isWhitespace: in AsciiWhitespace is more idiomatic. Also has a naming collision with unicode toLower. --- src/utils/twtstr.nim | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/utils/twtstr.nim') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 327fae81..78c92883 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -28,12 +28,9 @@ const AsciiAlphaNumeric* = AsciiAlpha + AsciiDigit const AsciiHexDigit* = (AsciiDigit + {'a'..'f', 'A'..'F'}) const AsciiWhitespace* = {' ', '\n', '\r', '\t', '\f'} -func isWhitespace*(c: char): bool {.inline.} = - return c in AsciiWhitespace - func onlyWhitespace*(s: string): bool = for c in s: - if not c.isWhitespace(): + if c notin AsciiWhitespace: return false return true @@ -70,20 +67,9 @@ const controlLetterMap = genControlLetterMap() func getControlLetter*(c: char): char = return controlLetterMap[int(c)] -const lowerChars = (func(): array[char, char] = - for i in 0..255: - if char(i) in 'A'..'Z': - result[char(i)] = char(i + 32) - else: - result[char(i)] = char(i) -)() - -func tolower*(c: char): char = - return lowerChars[c] - proc mtoLowerAscii*(str: var string) = for i in 0 ..< str.len: - str[i] = str[i].tolower() + str[i] = str[i].toLowerAscii() func toHeaderCase*(str: string): string = result = str @@ -122,7 +108,7 @@ func startsWithNoCase*(str, prefix: string): bool = var i = 0 while true: if i == prefix.len: return true - if str[i].tolower() != prefix[i].tolower(): return false + if str[i].toLowerAscii() != prefix[i].toLowerAscii(): return false inc i const hexCharMap = (func(): array[char, int] = @@ -203,7 +189,7 @@ func stripAndCollapse*(s: string): string = func skipBlanks*(buf: string, at: int): int = result = at - while result < buf.len and buf[result].isWhitespace(): + while result < buf.len and buf[result] in AsciiWhitespace: inc result func until*(s: string, c: set[char], starti = 0): string = -- cgit 1.4.1-2-gfad0