-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
builtin,js: implement JS string.split_any
#21612
Conversation
In the string The only thing after the 5, is the |
Doing it like this is just as bad as the Go |
What is the V version splitting in the |
It split with Same as |
I understand that reasoning, but it feels like that's more driven by implementation result than actual intention. The most common use case I know for split is for CSV values. In these cases, you expect it to split the string every time it encounters the delimiter. E.g. if you had the following CSV:
you'd want to reliably and conveniently extract each field.
|
The difference is in the description of
Meaning, you can include several different delimiters, and it will split on all of them. println('12;34:56^78,'.split_any(';:^,')) output is
Obviously contrived, but suppose you had a timestamp in a log file, and wanted to split the pieces... with println('[2024-05-31_19:39:23] This is the log message.'.split_any('[-_:]')) output is
... and in this case, I'd have to agree... the |
I'm not sure how to proceed in this case because the suggested behavior is contrary to all my experiences with other languages and isn't consistent with the regular split behavior where it overlaps in concept. In rough pseudocode, this seems like the correct simplified example to me.
|
I don't hold much authority here, so I think either someone needs to decide it's more important to keep the existing V behavior, or we need more input on what the expected behavior should be. |
The expected behavior is that all backends should produce exactly the same results. If anything is changed, then all backends should be changed so that the above statement is still true. |
Here is a plan of action:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work.
Implement
string.split_any
for the JS backend.This PR fixes #21440.