about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-10 19:08:40 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-10 19:08:40 +0100
commit78cc5143a3a98f2803258d42818cf17727d70fe7 (patch)
tree4d99de0e075449f3910a3ae8e326335740b44237 /src/js
parent1e858c874804444bc4b95b6e89eb96a0deb8473c (diff)
downloadchawan-78cc5143a3a98f2803258d42818cf17727d70fe7.tar.gz
regex.nim: remove unused functions
Including replace.
Diffstat (limited to 'src/js')
-rw-r--r--src/js/regex.nim43
1 files changed, 1 insertions, 42 deletions
diff --git a/src/js/regex.nim b/src/js/regex.nim
index e4b31c23..d65e5a29 100644
--- a/src/js/regex.nim
+++ b/src/js/regex.nim
@@ -6,7 +6,6 @@ import unicode
 import bindings/libregexp
 import bindings/quickjs
 import js/javascript
-import utils/twtstr
 
 export
   LRE_FLAG_GLOBAL,
@@ -36,7 +35,7 @@ type string16 = distinct string
 
 # Convert a UTF-8 string to UTF-16.
 # Note: this doesn't check for (invalid) UTF-8 containing surrogates.
-proc toUTF16*(s: string): string16 =
+proc toUTF16(s: string): string16 =
   var res = ""
   var i = 0
   template put16(c: uint16) =
@@ -89,17 +88,6 @@ template fastRuneAt(s: string16, i: int, r: untyped, doInc = true, be = false) =
       r = Rune(c1) # ucs-2
       when doInc: i += 2
 
-iterator runes(s: string16): Rune =
-  var i = 0
-  var r: Rune
-  while i < s.len:
-    fastRuneAt(s, i, r)
-    yield r
-
-proc fromUTF16(s: string16): string =
-  for r in s.runes:
-    result &= r
-
 var dummyRuntime = newJSRuntime()
 var dummyContext = dummyRuntime.newJSContextRaw()
 
@@ -227,32 +215,3 @@ proc exec*(regex: Regex, str: string, start = 0, length = str.len): RegexResult
           e8 += r.size()
         result.captures.add((s8, e8))
   dealloc(capture)
-
-#TODO do something with this?
-proc replace(str: string, replace: RegexReplace): string =
-  let res = replace.regex.exec(str)
-  if res.success:
-    var repl = newStringOfCap(replace.rule.len)
-    for i in 0 ..< replace.rule.high:
-      if replace.rule[i] == '\\':
-        var j = i + 1
-        var ds = ""
-        while j < replace.rule.len and replace.rule[j] in AsciiDigit:
-          ds &= replace.rule[j]
-          inc j
-        let n = parseInt32(ds)
-        if n < res.captures.len:
-          repl &= str[res.captures[i].s..res.captures[i].e]
-          continue
-      repl &= replace.rule[i]
-    if replace.rule.len > 0:
-      repl &= replace.rule[replace.rule.high]
-    var i = 0
-    for j in 0 ..< res.captures.len:
-      result &= str.substr(i, res.captures[j].s)
-      i = res.captures[j].e
-      if not replace.global: break
-    if i < str.len:
-      result &= str.substr(i, str.len)
-  else:
-    return str