new string fn

This commit is contained in:
Tenari
2026-06-05 07:54:06 -05:00
parent d9648c8bac
commit 22dec9e742
2 changed files with 16 additions and 0 deletions
+15
View File
@@ -466,3 +466,18 @@ fn u32 stringLineStartByteOffset(String s, u32 line_number) {
return s.length;
}
fn bool stringInsertBytesAt(String* s, str bytes, u32 at) {
u32 len = strlen(bytes);
if ((s->capacity - s->length) < len) {
return false;
}
for (u32 i = 0; i < len; i++) {
// move the original byte over by `len`
s->bytes[at + i + len] = s->bytes[at + i];
// copy the new byte in
s->bytes[at + i] = bytes[i];
s->length += 1;
}
return true;
}