summaryrefslogtreecommitdiff
path: root/tnslc/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/utils')
-rw-r--r--tnslc/utils/algo.tnsl40
1 files changed, 40 insertions, 0 deletions
diff --git a/tnslc/utils/algo.tnsl b/tnslc/utils/algo.tnsl
index 8426f9d..a08c773 100644
--- a/tnslc/utils/algo.tnsl
+++ b/tnslc/utils/algo.tnsl
@@ -200,3 +200,43 @@
return out.as_cstr()
;/
+/; unquote_cha(~uint8 cha) [uint8]
+ /; if (cha` !== '\\')
+ return cha`
+ ;/
+
+ cha++
+
+ /; if (cha` == '\"')
+ return '\"'
+ ;; else if (cha` == '\'')
+ return '\''
+ ;; else if (cha` == '\\')
+ return '\\'
+ ;; else if (cha` == 'n')
+ return '\n'
+ ;; else if (cha` == 't')
+ return '\t'
+ ;; else if (cha` == '0')
+ return 0
+ ;/
+
+ return cha`
+;/
+
+/; unquote_str(~uint8 str) [~uint8]
+ Vector out
+ out.init(1)
+
+ /; loop (str++; str` !== 0 && str` !== '\"') [str++]
+ uint8 buf = str`
+ /; if (str` == '\\')
+ buf = unquote_cha(str)
+ str++
+ ;/
+ out.push(~buf)
+ ;/
+
+ return out.as_cstr()
+;/
+