diff options
author | bptato <nincsnevem662@gmail.com> | 2023-11-20 17:20:41 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-11-20 17:20:41 +0100 |
commit | 342a1a7f787fc260448842ee312cf29825f96ba6 (patch) | |
tree | e4e1d28e424e60da8b2618195c40442b79bd2ba8 /src/utils/twtstr.nim | |
parent | d20fc30e10aeecfb2ede7adc4547b9ae394565b9 (diff) | |
download | chawan-342a1a7f787fc260448842ee312cf29825f96ba6.tar.gz |
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.
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 22 |
1 files changed, 4 insertions, 18 deletions
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 = |