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];