about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 7589c262..64f66f88 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -546,6 +546,23 @@ func percentDecode*(input: string, si = 0): string =
         i += 2
     inc i
 
+func htmlEscape*(s: string): string =
+  var res = ""
+  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
+
 #basically std join but with char
 func join*(ss: openarray[string], sep: char): string =
   if ss.len == 0: