Fix Str.split when string equals delimiter

countSegments and strSplitHelp check whether the length of the string is
strictly greater-than the length of the delimiter, skipping most of the
logic when this is not the case.

Changing the check to a greater-than-or-equal allows for the case when
the string and the delimiter are equal, giving the expected result of
["", ""].
This commit is contained in:
raleng 2022-07-28 01:36:02 +02:00
parent 71e83746cc
commit 17fc1a297c
No known key found for this signature in database
GPG Key ID: A7DBF700E0E77020

View File

@ -789,7 +789,7 @@ fn strSplitHelp(array: [*]RocStr, string: RocStr, delimiter: RocStr) void {
const delimiter_bytes_ptrs = delimiter.asU8ptr();
const delimiter_len = delimiter.len();
if (str_len > delimiter_len and delimiter_len > 0) {
if (str_len >= delimiter_len and delimiter_len > 0) {
const end_index: usize = str_len - delimiter_len + 1;
while (str_index <= end_index) {
var delimiter_index: usize = 0;
@ -1104,7 +1104,7 @@ pub fn countSegments(string: RocStr, delimiter: RocStr) callconv(.C) usize {
var count: usize = 1;
if (str_len > delimiter_len and delimiter_len > 0) {
if (str_len >= delimiter_len and delimiter_len > 0) {
var str_index: usize = 0;
const end_cond: usize = str_len - delimiter_len + 1;