From 22dec9e742a15bdf8c37e4aab628a01de4ae5301 Mon Sep 17 00:00:00 2001 From: Tenari Date: Fri, 5 Jun 2026 07:54:06 -0500 Subject: [PATCH] new string fn --- all.h | 1 + string.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/all.h b/all.h index 1ab3f4c..c3ab619 100644 --- a/all.h +++ b/all.h @@ -683,6 +683,7 @@ fn bool stringDeleteCodepointsBetweenByteOffsetsInclusive(String* s, u32 start, fn u32 stringCountLines(String s); fn u32 stringLineLen(String s, u32 line_number); fn u32 stringLineStartByteOffset(String s, u32 line_number); +fn bool stringInsertBytesAt(String* s, str bytes, u32 at); ///// OS-wrapped apis void osInit(); diff --git a/string.c b/string.c index 2f701e6..600b8b1 100644 --- a/string.c +++ b/string.c @@ -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; +} +