aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/types/url.nim4
-rw-r--r--src/utils/twtstr.nim11
2 files changed, 3 insertions, 12 deletions
diff --git a/src/types/url.nim b/src/types/url.nim
index e73d5f83..83460dc3 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -355,7 +355,7 @@ func unicodeToAscii(s: string, beStrict: bool): Option[string] =
var labels: seq[string]
var all = 0
for label in processed.get.split('.'):
- if not label.isAscii():
+ if AllChars - Ascii in s:
try:
let converted = "xn--" & punycode.encode(label)
labels.add(converted)
@@ -376,7 +376,7 @@ func unicodeToAscii(s: string, beStrict: bool): Option[string] =
func domainToAscii(domain: string, bestrict = false): Option[string] =
var needsprocessing = false
for s in domain.split('.'):
- if s.startsWith("xn--") or not s.isAscii():
+ if s.startsWith("xn--") or AllChars - Ascii in s:
needsprocessing = true
break
if bestrict or needsprocessing:
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 226714d7..91f7a4ab 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -15,10 +15,7 @@ import utils/map
export charcategory
func onlyWhitespace*(s: string): bool =
- for c in s:
- if c notin AsciiWhitespace:
- return false
- return true
+ return AllChars - AsciiWhitespace notin s
func isControlChar*(r: Rune): bool =
return int(r) <= 0x1F or int(r) == 0x7F
@@ -87,12 +84,6 @@ func decValue*(c: char): int =
return int(c) - int('0')
return -1
-func isAscii*(s: string): bool =
- for c in s:
- if c >= char(0x80):
- return false
- return true
-
const HexCharsUpper = "0123456789ABCDEF"
const HexCharsLower = "0123456789abcdef"
func pushHex*(buf: var string, u: uint8) =