// The builtin string and C-string types.
// A string is simply a slice of bytes, and a c-string is a pointer
// to byte, with a null-terminator ('\0') at the end.
-str :: #type [] u8;
-cstr :: #type & u8;
+str :: #type [] u8;
+cstr :: #type & u8;
+dyn_str :: #type [..] u8;
// Semi-useful shortcut for adding something to an array.
#operator << macro (arr: [..] $T, v: T) do core.array.push(&arr, v);
+insert :: #match #local {}
+
+#overload
insert :: (arr: &[..] $T, idx: u32, x: T) -> bool {
if !ensure_capacity(arr, arr.count + 1) do return false;
return true;
}
+#overload
+insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool {
+ if !ensure_capacity(arr, arr.count + new_arr.count) do return false;
+
+ arr.count += new_arr.count;
+ while i := arr.count; i > idx {
+ arr.data[i] = arr.data[i - 1];
+ i -= 1;
+ }
+
+ for i: 0 .. new_arr.count {
+ arr.data[i + idx] = new_arr[i];
+ }
+ return true;
+}
+
insert_empty :: (arr: &[..] $T, idx: u32) -> bool {
if !ensure_capacity(arr, arr.count + 1) do return false;
return to_return;
}
-pop :: (arr: &[..] $T) -> T {
+pop :: (arr: &[..] $T, n := 1) -> T {
if arr.count == 0 do return .{};
- arr.count -= 1;
+ c := core.math.min(n, arr.count);
+ arr.count -= n;
return arr.data[arr.count];
}
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