summaryrefslogtreecommitdiff
path: root/tnslc/utils.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-08-24 20:12:24 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-08-24 20:12:24 -0400
commit56262f5e8e521c782629aa18ed3d294c26f45011 (patch)
treeabaa7133ce5fa87bbc7b8b28e71f870958f8e990 /tnslc/utils.tnsl
parent02e3121d70b8e3d3d2fa333dc0fef9cc63b5f93a (diff)
change in_csv to return an index
Diffstat (limited to 'tnslc/utils.tnsl')
-rw-r--r--tnslc/utils.tnsl13
1 files changed, 10 insertions, 3 deletions
diff --git a/tnslc/utils.tnsl b/tnslc/utils.tnsl
index 54f01aa..91e8d2e 100644
--- a/tnslc/utils.tnsl
+++ b/tnslc/utils.tnsl
@@ -21,23 +21,25 @@
{}uint8 csv_pr = "\0\0"
-/; in_csv ({}uint8 csv, ~uint8 cstr) [bool]
+/; in_csv ({}uint8 csv, ~uint8 cstr) [int]
int sl = cstr_len(cstr)
int cl = len csv
int seen = 0
+ int idx = 0
/; loop (int i = 0; i < cl) [i++]
/; if (seen < 0)
/; if (csv{i} == ',')
seen = 0
+ idx++
;/
continue
;/
/; if (seen !< sl)
/; if (csv{i} == ',')
- return true
+ return idx
;/
seen = -1
;; else if (cstr{seen} == csv{i})
@@ -45,13 +47,18 @@
# _printf(~csv_pr{0})
seen++
;; else if (csv{i} == ',')
+ idx++
seen = 0
;; else
seen = -1
;/
;/
- return seen == sl
+ /; if (seen == sl)
+ return idx
+ ;/
+
+ return 0 - 1
;/
/; cstr_copy (~uint8 from, to)