-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Semantic of std::str::CharSplitsN
and regex::RegexSplitsN
don't match.
#14899
Comments
After being confused by my own memories, I thought about why python does the It is because it's returning IMO the API should be such that "the rest" does not appear similar to the exact splits. |
perl splits (Of course, that's also because LIMIT=0 has a special meaning. Of course it does, it's perl. Negative limit has a special meaning, too!) ETA: ruby's split behavior is identical to perl's. Consistency matters more than the particular choice, in my opinion. |
What I'm saying is that if we were eager about allocating, the obvious API would be:
where the |
Changing the existing APIs from the current simple and efficient |
Note also that if Personally I think we should provide every possible bit of functionality without allocating. |
Sorry, I'm not saying it should return a It can be implemented as a two-pass thing, or possibly as some sort of method that can be called once you've exhausted the head portion. |
/cc @aturon |
@Kimundi I believe this should fall out of your more general API changes? Are we nearing a point where we can move forward on that? |
regexes have now moved externally, so I'm going to close this |
Both implement an
Iterator
over slices of a string that is being split at a pattern, butstd::str::CharSplitsN
splits at mostN
times, yieldingN + 1
strings; whileregex::RegexSplitsN
splits at mostN - 1
times, yieldingN
strings.This is inconsistent and confusing, and one of them should be changed to have the semantic of the other, however it is unclear which is the better one.
The text was updated successfully, but these errors were encountered: