about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-12 19:42:04 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-12 19:42:04 +0100
commit820f0f0f039252533133c3bd1037a73036815a45 (patch)
tree305dd3cd0416123c27701c199164fa54e822a7fb /src/utils
parent5efdc54db2d2c766d7ce7c6545207ce2ce805620 (diff)
downloadchawan-820f0f0f039252533133c3bd1037a73036815a45.tar.gz
twtstr: import functions from gopher2html
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 13a432bf..c5078568 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -222,7 +222,8 @@ func until*(s: string, c: set[char], starti = 0): string =
       break
     result.add(s[i])
 
-func until*(s: string, c: char): string = s.until({c})
+func until*(s: string, c: char, starti = 0): string =
+  s.until({c}, starti)
 
 func after*(s: string, c: set[char]): string =
   var i = 0
@@ -557,21 +558,15 @@ func percentDecode*(input: string, si = 0): string =
     inc i
 
 func htmlEscape*(s: string): string =
-  var res = ""
+  result = ""
   for c in s:
-    if c == '<':
-      res &= "&lt;"
-    elif c == '>':
-      res &= "&gt;"
-    elif c == '&':
-      res &= "&amp;"
-    elif c == '"':
-      res &= "&quot;"
-    elif c == '\'':
-      res &= "&apos;"
-    else:
-      res &= c
-  return res
+    case c
+    of '<': result &= "&lt;"
+    of '>': result &= "&gt;"
+    of '&': result &= "&amp;"
+    of '"': result &= "&quot;"
+    of '\'': result &= "&apos;"
+    else: result &= c
 
 func dqEscape*(s: string): string =
   result = newStringOfCap(s.len)