Skip to content

Conversation

@moltenform
Copy link

Expected behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "", " b"]
Observed behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "SPLIT b"]
Within the loop in bsplitstrcb, i is sent too far forward
upon finding a match. Here is a proposed fix including tests,
open to suggestions. A few more details in the GH pull request.

Expected behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "", " b"]
Observed behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "SPLIT b"]
Within the loop in bsplitstrcb, i is sent too far forward
upon finding a match. Here is a proposed fix including tests,
open to suggestions. A few more details in the GH pull request.
@moltenform
Copy link
Author

Splitting string containing consecutive delimiters gives unexpected results

Expected behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "", " b"]
Observed behavior:
split("a SPLITSPLIT b", "SPLIT") ---> ["a ", "SPLIT b"]

For me, this is not the expected behavior.
It seems to not correspond with the behavior when a single char delimiter is used,
split("a || b", "|") ---> ["a ", "", " b"]
(Note that the string gets sent to bsplitcb when delim is one char.)
Also, the behavior does not correspond with JavaScript, Python, etc. split().

Precise example:
struct tagbstring delim = bsStatic("aa");
struct tagbstring s = bsStatic("1aaaa1");
bstrlist *list = bsplitstr(s, delim);
list is ["1", "aa1"] instead of ["1", "", "", "1"]

Proposed fix attached, but open to suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant