aboutsummaryrefslogtreecommitdiff
path: root/core/bytes
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-02-14 10:57:29 +0000
committergingerBill <gingerBill@users.noreply.github.com>2022-02-14 10:57:29 +0000
commitf56114719081164fb38a700dacc298173b0f34dc (patch)
tree65b30ebb923883b20aded53c3fb0ad445965c096 /core/bytes
parentcf528431f50ad2d6d21435e471cb6c713259c4ec (diff)
Correct _split_iterator
Diffstat (limited to 'core/bytes')
-rw-r--r--core/bytes/bytes.odin40
1 files changed, 8 insertions, 32 deletions
diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin
index 1bf11e0b0..fb36b2d6e 100644
--- a/core/bytes/bytes.odin
+++ b/core/bytes/bytes.odin
@@ -219,39 +219,24 @@ split_after_n :: proc(s, sep: []byte, n: int, allocator := context.allocator) ->
@private
_split_iterator :: proc(s: ^[]byte, sep: []byte, sep_save, n: int) -> (res: []byte, ok: bool) {
- s, n := s, n
-
- if n == 0 {
- return
- }
-
- if sep == nil {
+ if sep == "" {
res = s[:]
ok = true
s^ = s[len(s):]
return
}
- if n < 0 {
- n = count(s^, sep) + 1
- }
-
- n -= 1
-
- i := 0
- for ; i < n; i += 1 {
- m := index(s^, sep)
- if m < 0 {
- break
- }
+ m := index(s^, sep)
+ if m < 0 {
+ // not found
+ res = s[:]
+ ok = res != ""
+ s^ = s[len(s):]
+ } else {
res = s[:m+sep_save]
ok = true
s^ = s[m+len(sep):]
- return
}
- res = s[:]
- ok = res != nil
- s^ = s[len(s):]
return
}
@@ -260,19 +245,10 @@ split_iterator :: proc(s: ^[]byte, sep: []byte) -> ([]byte, bool) {
return _split_iterator(s, sep, 0, -1)
}
-split_n_iterator :: proc(s: ^[]byte, sep: []byte, n: int) -> ([]byte, bool) {
- return _split_iterator(s, sep, 0, n)
-}
-
split_after_iterator :: proc(s: ^[]byte, sep: []byte) -> ([]byte, bool) {
return _split_iterator(s, sep, len(sep), -1)
}
-split_after_n_iterator :: proc(s: ^[]byte, sep: []byte, n: int) -> ([]byte, bool) {
- return _split_iterator(s, sep, len(sep), n)
-}
-
-
index_byte :: proc(s: []byte, c: byte) -> int {
for i := 0; i < len(s); i += 1 {