summaryrefslogtreecommitdiff
path: root/tnslc/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/utils')
-rw-r--r--tnslc/utils/algo.tnsl25
-rw-r--r--tnslc/utils/vector.tnsl13
2 files changed, 35 insertions, 3 deletions
diff --git a/tnslc/utils/algo.tnsl b/tnslc/utils/algo.tnsl
index 35ac35c..ed11aad 100644
--- a/tnslc/utils/algo.tnsl
+++ b/tnslc/utils/algo.tnsl
@@ -15,6 +15,25 @@
return out
;/
+/; ends_with (~uint8 str, suffix) [bool]
+ int chk = strlen(suffix)
+ int counter = 0
+
+ /; loop (str` !== 0) [str++]
+ /; if (suffix{counter} !== 0)
+ /; if (suffix{counter} == str`)
+ counter++
+ ;; else
+ counter = 0
+ ;/
+ ;; else
+ counter = 0
+ ;/
+ ;/
+
+ return chk == counter
+;/
+
/; base_for_char (uint8 c) [int]
/; if (c == 'b' || c == 'B')
return 2
@@ -150,7 +169,7 @@
/; loop (i > 0) [i = i / 16]
int n = i % 16
/; if (n > 9)
- out.push_char('a' + n - 10)
+ out.push_char('A' + n - 10)
;; else
out.push_char('0' + n)
;/
@@ -231,7 +250,7 @@
return cha`
;/
-/; unquote_str(~uint8 str) [~uint8]
+/; unquote_str(~uint8 str) [Vector]
Vector out
out.init(1)
@@ -244,6 +263,6 @@
out.push(~buf)
;/
- return out.as_cstr()
+ return out
;/
diff --git a/tnslc/utils/vector.tnsl b/tnslc/utils/vector.tnsl
index 38c45fc..b38978f 100644
--- a/tnslc/utils/vector.tnsl
+++ b/tnslc/utils/vector.tnsl
@@ -56,6 +56,19 @@ uint VECTOR_MAX_GROW = 256
self.count++
;/
+ /; replace (int index, ~void el)
+ ~uint8 start = self.get(index)
+ /; if (start == NULL)
+ return
+ ;/
+
+ /; loop (int i = 0; i < self._elsz) [i++]
+ ~uint8 to = start + i
+ ~uint8 from = el + i
+ to` = from`
+ ;/
+ ;/
+
/; _shrink(uint i)
/; if (i !< self.size)
self.size = 1