From 390772358cedc9ed541a27b3cac1f8d97beef0ef Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 17 Feb 2024 22:03:07 +0100 Subject: regex: re-work compileSearchRegex I've gotten tired of not being able to search for forward slashes. Now it works like in vim, and you can also set default ignore case in the config. --- src/utils/twtstr.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/utils/twtstr.nim') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 80b6be65..1916fff5 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -713,3 +713,19 @@ proc makeCRLF*(s: string): string = result &= '\n' else: result &= s[i] + +func strictParseEnum*[T: enum](s: string): Opt[T] = + # cmp when len is small enough, otherwise hashmap + when {T.low..T.high}.len <= 4: + for e in T.low .. T.high: + if $e == s: + return ok(e) + else: + const tab = (func(): Table[string, T] = + result = initTable[string, T]() + for e in T.low .. T.high: + result[$e] = e + )() + if s in tab: + return ok(tab[s]) + return err() -- cgit 1.4.1-2-gfad0