about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-28 20:50:51 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-28 21:06:28 +0200
commit9653c35fb9a4398942ecb305835a95fbd87c433a (patch)
tree2db576e71cd89557592715d64ecb4fb4a46f8c66 /src/utils/twtstr.nim
parentdbf2e0e831ebaf8a0e6f375a8f423f87280e7862 (diff)
downloadchawan-9653c35fb9a4398942ecb305835a95fbd87c433a.tar.gz
buffer, pager, config: add meta-refresh + misc fixes
* buffer, pager, config: add meta-refresh value, which makes it possible
  to follow http-equiv=refresh META tags.
* config: clean up redundant format mode parser
* timeout: accept varargs for params to pass on to functions
* pager: add "options" dict to JS gotoURL
* twtstr: remove redundant startsWithNoCase
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 14e93bda..44c6ea3f 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -45,12 +45,17 @@ func snakeToKebabCase*(s: string): string =
       c = '-'
 
 func kebabToCamelCase*(s: string): string =
-  result = s
+  result = ""
   var flip = false
-  for c in result.mitems:
-    if flip:
-      c = c.toUpperAscii()
-    flip = c == '-'
+  for c in s:
+    if c == '-':
+      flip = true
+    else:
+      if flip:
+        result &= c.toUpperAscii()
+      else:
+        result &= c
+      flip = false
 
 func camelToKebabCase*(s: string): string =
   result = ""
@@ -61,17 +66,6 @@ func camelToKebabCase*(s: string): string =
     else:
       result &= c
 
-func startsWithNoCase*(s, prefix: string): bool =
-  if s.len < prefix.len:
-    return false
-  # prefix.len is always lower
-  var i = 0
-  while true:
-    if i == prefix.len: return true
-    if s[i].toLowerAscii() != prefix[i].toLowerAscii():
-      return false
-    inc i
-
 func hexValue*(c: char): int =
   if c in AsciiDigit:
     return int(c) - int('0')
@@ -114,9 +108,9 @@ func toHexLower*(u: uint16): string =
 func equalsIgnoreCase*(s1, s2: string): bool {.inline.} =
   return s1.cmpIgnoreCase(s2) == 0
 
-func startsWithIgnoreCase*(s1, s2: string): bool =
+func startsWithIgnoreCase*(s1, s2: string; si = 0): bool =
   if s1.len < s2.len: return false
-  for i in 0 ..< s2.len:
+  for i in si ..< s2.len:
     if s1[i].toLowerAscii() != s2[i].toLowerAscii():
       return false
   return true