summaryrefslogtreecommitdiff
path: root/tnslc/utils.tnsl
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/utils.tnsl')
-rw-r--r--tnslc/utils.tnsl61
1 files changed, 60 insertions, 1 deletions
diff --git a/tnslc/utils.tnsl b/tnslc/utils.tnsl
index 6fe7769..9fe113a 100644
--- a/tnslc/utils.tnsl
+++ b/tnslc/utils.tnsl
@@ -17,4 +17,63 @@
;/
return true
-;/ \ No newline at end of file
+;/
+
+{}uint8 csv_pr = "\0\0"
+
+/; in_csv ({}uint8 csv, ~uint8 cstr) [bool]
+ int sl = cstr_len(cstr)
+ int cl = len csv
+ int seen = 0
+
+ /; loop (int i = 0; i < cl) [i++]
+
+ /; if (seen < 0)
+ /; if (csv{i} == ',')
+ seen = 0
+ ;/
+ continue
+ ;/
+
+ /; if (seen !< sl)
+ /; if (csv{i} == ',')
+ return true
+ ;/
+ seen = -1
+ ;; else if (cstr{seen} == csv{i})
+ csv_pr{0} = cstr{seen}
+ # _printf(~csv_pr{0})
+ seen++
+ ;; else if (csv{i} == ',')
+ seen = 0
+ ;; else
+ seen = -1
+ ;/
+ ;/
+
+ return seen == sl
+;/
+
+/; cstr_copy (~uint8 from, to)
+ int ln = cstr_len(from)
+
+ /; loop (int i = 0; i !> ln) [i++]
+ to{i} = from{i}
+ ;/
+;/
+
+/; contains_char ({}uint8 arr, uint8 c) [bool]
+ /; loop (int i = 0; i < len arr) [i++]
+ /; if (arr{i} == c)
+ return true
+ ;/
+ ;/
+ return false
+;/
+
+/; write_to_file(~void file, ~uint8 string)
+ int ln = cstr_len(string)
+ /; loop (int i = 0; i < ln) [i++]
+ _write_byte(file, string + i)
+ ;/
+;/