more string shit

This commit is contained in:
Tenari
2026-05-24 20:53:11 -05:00
parent 02a44bcfe3
commit 314f30d632
2 changed files with 22 additions and 3 deletions
+19 -2
View File
@@ -261,8 +261,10 @@ fn bool stringInsertCodepointAtByte(String* s, Codepoint c, u32 byte_offset) {
return true;
}
fn bool stringDeleteCodepointAtByte(String* s, u32 byte_offset) {
if (s->length < byte_offset) return false;
fn u8 stringDeleteCodepointAtByte(String* s, u32 byte_offset) {
// returns number of bytes deleted
if (s->length < byte_offset) return 0;
if (s->length == 0) return 0;
Codepoint cp = codepointFromBytes(s->bytes, byte_offset);
// shift all the bytes from the back towards the byte_offset
@@ -272,6 +274,21 @@ fn bool stringDeleteCodepointAtByte(String* s, u32 byte_offset) {
}
s->length -= 1;
}
return cp.size;
}
fn bool stringDeleteCodepointsBetweenByteOffsetsInclusive(String* s, u32 start, u32 end) {
if (end < start) return false;
if (s->length < start || s->length < end) return false;
if (s->length == 0) return false;
u32 codepoint_size = 0;
for (u32 i = 0; i < (end - start); i+=codepoint_size) {
codepoint_size = stringDeleteCodepointAtByte(s, start);
if (codepoint_size == 0) {
return false;
}
}
return true;
}