about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-18 20:46:30 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-18 20:46:30 +0100
commitbfaf210d87e90016f8f2521657bd04686170aa43 (patch)
treee9711cb2f72174058d88ce2d52a76239e3c54c62 /src/utils
parent1fbe17eeddefb87bf8e819be7792ae7a6482d8f8 (diff)
downloadchawan-bfaf210d87e90016f8f2521657bd04686170aa43.tar.gz
Add JS support to documents
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 9a70539a..91676d5a 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -90,6 +90,33 @@ const lowerChars = (func(): array[char, char] =
 func tolower*(c: char): char =
   return lowerChars[c]
 
+func toLowerAscii2*(str: string): string =
+  var i = 0
+  block noconv:
+    while i < str.len:
+      let c = str[i]
+      if c in AsciiUpperAlpha:
+        break noconv
+      inc i
+    return str
+  result = newString(str.len)
+  prepareMutation(result)
+  copyMem(addr result[0], unsafeAddr str[0], i)
+  while i < str.len:
+    result[i] = str[i].tolower()
+
+proc toLowerAsciiIp*(str: var string) =
+  var i = 0
+  block noconv:
+    while i < str.len:
+      let c = str[i]
+      if c in AsciiUpperAlpha:
+        break noconv
+      inc i
+    return
+  while i < str.len:
+    str[i] = str[i].tolower()
+
 func toHeaderCase*(str: string): string =
   result = str
   var flip = true
@@ -580,6 +607,7 @@ func unicodeToAscii*(s: string, checkhyphens, checkbidi, checkjoiners, transitio
       labels.add(label)
   return labels.join('.').some
 
+#TODO this is stupid
 func isValidNonZeroInt*(str: string): bool =
   if str.len == 0: return false
   if str == "0": return false