Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting string that contains consecutive delimiters #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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