about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-11 10:45:41 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-11 10:45:41 +0100
commitd2451e51ede8a733c22fbe0b285ccb341e272b16 (patch)
tree1b118439904ec2591655968a7ce4912e3bea6ffb /src/utils/twtstr.nim
parent6b9db7e8d77c3ce68558f45f9162121a13a96a2b (diff)
downloadchawan-d2451e51ede8a733c22fbe0b285ccb341e272b16.tar.gz
css: add case-insensitive matching
Also case-sensitive, but for now that is the same as normal matching...
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 28a91558..13a432bf 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -177,6 +177,20 @@ func toHexLower*(u: uint16): string =
 func equalsIgnoreCase*(s1, s2: string): bool {.inline.} =
   return s1.cmpIgnoreCase(s2) == 0
 
+func startsWithIgnoreCase*(s1, s2: string): bool =
+  if s1.len < s2.len: return false
+  for i in 0 ..< s2.len:
+    if s1[i].toLowerAscii() != s2[i].toLowerAscii():
+      return false
+  return true
+
+func endsWithIgnoreCase*(s1, s2: string): bool =
+  if s1.len < s2.len: return false
+  for i in countdown(s2.high, 0):
+    if s1[i].toLowerAscii() != s2[i].toLowerAscii():
+      return false
+  return true
+
 func isDigitAscii*(r: Rune): bool =
   return int(r) < 256 and isDigit(char(r))