mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
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:
parent
71e83746cc
commit
17fc1a297c
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user