From 239c511ce9e580384eca804596dfaf227f98c807 Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 15:09:12 +0100 Subject: [PATCH 1/3] Fix strings.split_iterator when separator is empty --- core/strings/strings.odin | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index c014d2b2b..9e7ea6ac1 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1031,14 +1031,10 @@ Returns: */ @private _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { - if sep == "" { - res = s[:] - ok = true - s^ = s[len(s):] - return - } - m := index(s^, sep) + if sep == "" { + m = 1 if len(s) > 0 else -1 + } if m < 0 { // not found res = s[:] From 4c0b145bad3a49d3110ddc18c0dae2e59dcf05e4 Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 15:44:42 +0100 Subject: [PATCH 2/3] Fix unicode handling --- core/strings/strings.odin | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 9e7ea6ac1..b050262f0 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1033,7 +1033,12 @@ Returns: _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { m := index(s^, sep) if sep == "" { - m = 1 if len(s) > 0 else -1 + if len(s) == 0 { + m = -1 + } else { + _, w := utf8.decode_rune_in_string(s^) + m = w + } } if m < 0 { // not found From 385f5f50147f6f68f7722befc5ce0d36751a034d Mon Sep 17 00:00:00 2001 From: Jacob Friedman Date: Tue, 4 Feb 2025 19:51:48 +0100 Subject: [PATCH 3/3] Small optimization --- core/strings/strings.odin | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index b050262f0..e99a1bfb4 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1031,7 +1031,7 @@ Returns: */ @private _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { - m := index(s^, sep) + m: int if sep == "" { if len(s) == 0 { m = -1 @@ -1039,6 +1039,8 @@ _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, _, w := utf8.decode_rune_in_string(s^) m = w } + } else { + m = index(s^, sep) } if m < 0 { // not found