aboutsummaryrefslogtreecommitdiff
path: root/core/strings
diff options
context:
space:
mode:
authorBrendan Punsky <bpunsky@gmail.com>2019-03-13 16:45:46 -0400
committerGitHub <noreply@github.com>2019-03-13 16:45:46 -0400
commiteadb66c9efc19ad1deaee6ca5a141cbd7206fcce (patch)
tree01eb1a33ffba203c45460e0e50da4b5f4ca31076 /core/strings
parent9d7e1c17cc4a9b0d6cfd4c741c800b5732eb9948 (diff)
parentbdab5e00da6dee80b7582135815f2183def935bb (diff)
Merge branch 'master' into master
Diffstat (limited to 'core/strings')
-rw-r--r--core/strings/builder.odin4
-rw-r--r--core/strings/strings.odin17
2 files changed, 19 insertions, 2 deletions
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index e86d748cc..547c456ba 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -61,8 +61,8 @@ write_bytes :: proc(b: ^Builder, x: []byte) {
append(&b.buf, ..x);
}
-@(private)
-static DIGITS_LOWER := "0123456789abcdefx";
+@(private, static)
+DIGITS_LOWER := "0123456789abcdefx";
write_quoted_string :: proc(b: ^Builder, s: string, quote: byte = '"') {
write_byte(b, quote);
diff --git a/core/strings/strings.odin b/core/strings/strings.odin
index efc5f2a6d..60fb56b27 100644
--- a/core/strings/strings.odin
+++ b/core/strings/strings.odin
@@ -329,6 +329,10 @@ is_space :: proc(r: rune) -> bool {
return false;
}
+is_null :: proc(r: rune) -> bool {
+ return r == 0x0000;
+}
+
index_proc :: proc(s: string, p: proc(rune) -> bool, truth := true) -> int {
for r, i in s {
if p(r) == truth {
@@ -478,6 +482,19 @@ trim_space :: proc(s: string) -> string {
}
+trim_left_null :: proc(s: string) -> string {
+ return trim_left_proc(s, is_null);
+}
+
+trim_right_null :: proc(s: string) -> string {
+ return trim_right_proc(s, is_null);
+}
+
+trim_null :: proc(s: string) -> string {
+ return trim_right_null(trim_left_null(s));
+}
+
+
// returns a slice of sub-strings into `s`
// `allocator` is used only for the slice
// `skip_empty=true` does not return zero-length substrings