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/types/blob.nim | 3 ++- src/types/urimethodmap.nim | 2 +- src/types/url.nim | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/types') diff --git a/src/types/blob.nim b/src/types/blob.nim index b6ef4adf..9ddca2b5 100644 --- a/src/types/blob.nim +++ b/src/types/blob.nim @@ -1,4 +1,5 @@ import options +import strutils import js/dict import js/fromjs @@ -86,7 +87,7 @@ proc newWebFile(ctx: JSContext, fileBits: seq[string], fileName: string, for c in options.`type`: if c notin char(0x20)..char(0x7E): break ctype - file.ctype &= c.tolower() + file.ctype &= c.toLowerAscii() return file #TODO File, Blob constructors diff --git a/src/types/urimethodmap.nim b/src/types/urimethodmap.nim index 8453e554..283564a2 100644 --- a/src/types/urimethodmap.nim +++ b/src/types/urimethodmap.nim @@ -51,7 +51,7 @@ proc parseURIMethodMap*(this: var URIMethodMap, s: string) = var k = "" var i = 0 while i < line.len and line[i] notin AsciiWhitespace + {':'}: - k &= line[i].tolower() + k &= line[i].toLowerAscii() inc i if i >= line.len or line[i] != ':': continue # invalid diff --git a/src/types/url.nim b/src/types/url.nim index 69a3a78e..e115d54c 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -232,7 +232,7 @@ func endsInNumber(input: string): bool = if parts.len == 0: return false var last = parts[^1] if last != "": - if last.len == 2 and last[0] in Digits and last[1].tolower() == 'x': + if last.len == 2 and last[0] in Digits and last[1].toLowerAscii() == 'x': last = last.substr(2) for c in last: if c notin Digits: @@ -366,7 +366,7 @@ proc basicParseURL*(input: string, base = none(URL), url: URL = URL(), case state of SCHEME_START_STATE: if has and c.isAlphaAscii(): - buffer &= c.tolower() + buffer &= c.toLowerAscii() state = SCHEME_STATE elif not override: state = NO_SCHEME_STATE @@ -375,7 +375,7 @@ proc basicParseURL*(input: string, base = none(URL), url: URL = URL(), return none(URL) of SCHEME_STATE: if has and c in AsciiAlphaNumeric + {'+', '-', '.'}: - buffer &= c.tolower() + buffer &= c.toLowerAscii() elif has and c == ':': if override: if url.scheme in SpecialSchemes and buffer notin SpecialSchemes: -- cgit 1.4.1-2-gfad0