about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-18 19:22:11 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-18 19:22:11 +0100
commit74296e6a91a21fbb34ecd079631098443593b4e6 (patch)
tree95d626b25c6e676e2bba3e5768eb30009c3a2b81 /src/js
parent6ccd70418dd9c219cb882e60bd96873255b077e6 (diff)
downloadchawan-74296e6a91a21fbb34ecd079631098443593b4e6.tar.gz
regex: compileSearchRegex improvements
* do not eat \\c, \\C
* emulate vi-style word boundary matching (\<, \>) with \b
Diffstat (limited to 'src/js')
-rw-r--r--src/js/regex.nim16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/js/regex.nim b/src/js/regex.nim
index 1d78f806..fbbaf55f 100644
--- a/src/js/regex.nim
+++ b/src/js/regex.nim
@@ -87,21 +87,19 @@ proc compileSearchRegex*(str: string, defaultFlags: LREFlags):
     Result[Regex, string] =
   # Emulate vim's \c/\C: override defaultFlags if one is found, then remove it
   # from str.
+  # Also, replace \< and \> with \b as (a bit sloppy) vi emulation.
   var flags = defaultFlags
   var s = newStringOfCap(str.len)
   var quot = false
   for c in str:
     if quot:
       quot = false
-      if c == 'c':
-        flags.incl(LRE_FLAG_IGNORECASE)
-        continue
-      elif c == 'C':
-        flags.excl(LRE_FLAG_IGNORECASE)
-        continue
-      else:
-        s &= '\\'
-    if c == '\\':
+      case c
+      of 'c': flags.incl(LRE_FLAG_IGNORECASE)
+      of 'C': flags.excl(LRE_FLAG_IGNORECASE)
+      of '<', '>': s &= "\\b"
+      else: s &= '\\' & c
+    elif c == '\\':
       quot = true
     else:
       s &= c