aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-23 11:46:43 +0100
committergingerBill <bill@gingerbill.org>2021-05-23 11:46:43 +0100
commite82f8214e81e87f337d75c76ae0606a07e51afa0 (patch)
treef0cbe6dfa8d71d561f4f69d34959b35df171cba4
parentb8f8d4c3a12ea85285511112b33425923418556a (diff)
Add `bytes.remove`, `bytes.remove_all`, `strings.remove`, `strings.remove_all`
-rw-r--r--core/bytes/bytes.odin8
-rw-r--r--core/strings/strings.odin8
2 files changed, 16 insertions, 0 deletions
diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin
index 639e36721..b3d332c67 100644
--- a/core/bytes/bytes.odin
+++ b/core/bytes/bytes.odin
@@ -526,6 +526,14 @@ replace :: proc(s, old, new: []byte, n: int, allocator := context.allocator) ->
return;
}
+remove :: proc(s, key: []byte, n: int, allocator := context.allocator) -> (output: []byte, was_allocation: bool) {
+ return replace(s, key, {}, n, allocator);
+}
+
+remove_all :: proc(s, key: []byte, allocator := context.allocator) -> (output: []byte, was_allocation: bool) {
+ return remove(s, key, -1, allocator);
+}
+
@(private) _ascii_space := [256]u8{'\t' = 1, '\n' = 1, '\v' = 1, '\f' = 1, '\r' = 1, ' ' = 1};
diff --git a/core/strings/strings.odin b/core/strings/strings.odin
index 2aa2ac71d..5537822a8 100644
--- a/core/strings/strings.odin
+++ b/core/strings/strings.odin
@@ -541,6 +541,14 @@ replace :: proc(s, old, new: string, n: int, allocator := context.allocator) ->
return;
}
+remove :: proc(s, key: string, n: int, allocator := context.allocator) -> (output: string, was_allocation: bool) {
+ return replace(s, key, "", n, allocator);
+}
+
+remove_all :: proc(s, key: string, allocator := context.allocator) -> (output: string, was_allocation: bool) {
+ return remove(s, key, -1, allocator);
+}
+
@(private) _ascii_space := [256]u8{'\t' = 1, '\n' = 1, '\v' = 1, '\f' = 1, '\r' = 1, ' ' = 1};