From d2451e51ede8a733c22fbe0b285ccb341e272b16 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 11 Dec 2023 10:45:41 +0100 Subject: css: add case-insensitive matching Also case-sensitive, but for now that is the same as normal matching... --- src/utils/twtstr.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils/twtstr.nim') 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)) -- cgit 1.4.1-2-gfad0