From ddadc23a70883b57b0513c01744bd326563cfc53 Mon Sep 17 00:00:00 2001 From: Tenari Date: Mon, 25 May 2026 10:14:04 -0500 Subject: [PATCH] c-string compact toggle param --- all.h | 2 +- string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/all.h b/all.h index 8519434..99609d9 100644 --- a/all.h +++ b/all.h @@ -677,7 +677,7 @@ fn Codepoint codepointFromBytesBefore(ptr bytes, u32 offset); fn Codepoint codepointFromRawInt(u32 c); fn void codepointFillBuf(Codepoint cp, ptr buf); fn String stringFromRawCodepoint(Arena* a, u32 c); -fn bool stringInsertCodepointAtByte(String* s, Codepoint c, u32 byte_offset); +fn bool stringInsertCodepointAtByte(String* s, Codepoint c, u32 byte_offset, bool keep_trailing_zero); fn u8 stringDeleteCodepointAtByte(String* s, u32 byte_offset); fn bool stringDeleteCodepointsBetweenByteOffsetsInclusive(String* s, u32 start, u32 end); diff --git a/string.c b/string.c index 14120ce..57659c2 100644 --- a/string.c +++ b/string.c @@ -244,8 +244,8 @@ fn String stringFromRawCodepoint(Arena* a, u32 c) { return result; } -fn bool stringInsertCodepointAtByte(String* s, Codepoint c, u32 byte_offset) { - u32 remaining_space = s->capacity - s->length; +fn bool stringInsertCodepointAtByte(String* s, Codepoint c, u32 byte_offset, bool keep_trailing_zero) { + i32 remaining_space = (s->capacity - (keep_trailing_zero ? 1 : 0)) - s->length; if (remaining_space < c.size) return false; char codepoint_bytes[4];