new string fn
This commit is contained in:
@@ -683,6 +683,7 @@ fn bool stringDeleteCodepointsBetweenByteOffsetsInclusive(String* s, u32 start,
|
|||||||
fn u32 stringCountLines(String s);
|
fn u32 stringCountLines(String s);
|
||||||
fn u32 stringLineLen(String s, u32 line_number);
|
fn u32 stringLineLen(String s, u32 line_number);
|
||||||
fn u32 stringLineStartByteOffset(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
|
///// OS-wrapped apis
|
||||||
void osInit();
|
void osInit();
|
||||||
|
|||||||
@@ -466,3 +466,18 @@ fn u32 stringLineStartByteOffset(String s, u32 line_number) {
|
|||||||
return s.length;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user