Add strings.pop_byte strings.pop_rune

This commit is contained in:
gingerBill
2020-07-08 23:15:48 +01:00
parent 4059542afb
commit 5b7c83d871
2 changed files with 18 additions and 4 deletions
-4
View File
@@ -298,10 +298,6 @@ Context :: struct {
assertion_failure_proc: Assertion_Failure_Proc,
logger: Logger,
// stdin: os.Handle,
// stdout: os.Handle,
// stderr: os.Handle,
thread_id: int,
user_data: any,
+18
View File
@@ -86,6 +86,24 @@ write_bytes :: proc(b: ^Builder, x: []byte) {
append(&b.buf, ..x);
}
pop_byte :: proc(b: ^Builder) -> (r: byte) {
if len(b.buf) == 0 {
return 0;
}
r = b.buf[len(b.buf)-1];
d := cast(^mem.Raw_Dynamic_Array)&b.buf;
d.len = max(d.len-1, 0);
return;
}
pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
r, width = utf8.decode_last_rune(b.buf[:]);
d := cast(^mem.Raw_Dynamic_Array)&b.buf;
d.len = max(d.len-width, 0);
return;
}
@(private, static)
DIGITS_LOWER := "0123456789abcdefx";