bugfix: `dyn_str` functions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Mar 2023 20:41:38 +0000 (14:41 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Mar 2023 20:41:38 +0000 (14:41 -0600)
core/container/array.onyx
core/string/string.onyx

index 9a6cb4baaf9bdc203ab3be49647d82bdfadabfeb..cfe352e6dcb15bb0722454d8ad9768508a4232db 100644 (file)
@@ -120,6 +120,7 @@ insert :: #match #local {}
 
 #overload
 insert :: (arr: &[..] $T, idx: u32, x: T) -> bool {
+    if idx >= arr.count do return false;
     if !ensure_capacity(arr, arr.count + 1) do return false;
 
     arr.count += 1;
@@ -134,6 +135,7 @@ insert :: (arr: &[..] $T, idx: u32, x: T) -> bool {
 
 #overload
 insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool {
+    if idx >= arr.count do return false;
     if !ensure_capacity(arr, arr.count + new_arr.count) do return false;
 
     arr.count += new_arr.count;
index 425d1c5c0778c767ec721c214ec14c587323a461..4295c32745220727123d483384c050c587f9ca6c 100644 (file)
@@ -644,9 +644,32 @@ bisect :: (s: str, substr: str) -> (str, str) {
     return s[0 .. index], s[index+substr.length .. s.length];
 }
 
+//
 // Used by dyn_str
-delete  :: core.array.delete
-append  :: core.array.concat
-clear   :: core.array.clear
-retreat :: core.array.pop
-insert  :: core.array.insert
+//
+
+delete  :: macro (x: &dyn_str, idx: u32) -> u8 {
+    return (package core.array).delete(x, idx);
+}
+
+append  :: macro (x: &dyn_str, other: str) {
+    (package core.array).concat(x, other);
+}
+
+clear   :: macro (x: &dyn_str) {
+    (package core.array).clear(x);
+}
+
+retreat :: macro (x: &dyn_str, chars := 1) {
+    (package core.array).pop(x, chars);
+}
+
+insert  :: #match #locked {
+    macro (x: &dyn_str, idx: u32, new_str: str) -> bool {
+        return (package core.array).insert(x, idx, new_str);
+    },
+
+    macro (x: &dyn_str, idx: u32, ch: u8) -> bool {
+        return (package core.array).insert(x, idx, ch);
+    }
+}