Browse Source

Add `strings.pop_byte` `strings.pop_rune`

gingerBill 5 years ago
parent
commit
5b7c83d871
2 changed files with 18 additions and 4 deletions
  1. 0 4
      core/runtime/core.odin
  2. 18 0
      core/strings/builder.odin

+ 0 - 4
core/runtime/core.odin

@@ -298,10 +298,6 @@ Context :: struct {
 	assertion_failure_proc: Assertion_Failure_Proc,
 	assertion_failure_proc: Assertion_Failure_Proc,
 	logger:                 Logger,
 	logger:                 Logger,
 
 
-	// stdin:  os.Handle,
-	// stdout: os.Handle,
-	// stderr: os.Handle,
-
 	thread_id:  int,
 	thread_id:  int,
 
 
 	user_data:  any,
 	user_data:  any,

+ 18 - 0
core/strings/builder.odin

@@ -86,6 +86,24 @@ write_bytes :: proc(b: ^Builder, x: []byte) {
 	append(&b.buf, ..x);
 	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)
 @(private, static)
 DIGITS_LOWER := "0123456789abcdefx";
 DIGITS_LOWER := "0123456789abcdefx";