-
Notifications
You must be signed in to change notification settings - Fork 13.3k
split() should document the behavior around adjacent separators, particularly at the start of the string #25986
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
Comments
That said, it does seem inconsistent to me? For example, four leading spaces yields four empty entries, but two intermediate spaces yield one empty entry, and one intermediate space yields no empty entries. |
There are two reasonable behaviours I see. One is to split around padding, to get |
It is certainly expected by the implementors, this is the way it has been since introduction of .split() I believe. Since it's stable, I guess it's a documentation issue Replace each space with a splitting point and it seems consistent " a b c"
"||||a||b|c"
=> "", "", "", "", "a", "", "b", "c" @nikomatsakis You're not taking into account the string that precedes the first separator I guess. It's empty in this case. |
FWIW, Python does the same thing >>> " a b c".split(' ')
['', '', '', '', 'a', '', 'b', 'c'] Both Rust and Python can filter the list or iterator just fine, but it's slightly simpler in Python since an empty string is a falseish value. |
@bluss yes, ok, that makes sense (I did not, it's true, consider the "empty string" at the beginning.) I don't particularly like this behavior -- I've always found it annoying in Python too :) -- but yes I agree it's a doc issue, not a bug. |
@bluss basically said all I'd say already. So yeah, I guess the docs could be improved a bit? |
.split(x).connect(x) should be an identity function, which is how it is consistent. |
@nagisa This doesn't seem to actually be the case. The number of leading spaces seems to match the number of empty entries. Eg.
As such, the requirement seems to hold. |
I don’t understand what you’re trying to say here, because
|
Sorry, I thought by saying "should be" you were implying that it wasn't - I was pointing out that it is consistent. Nvm then, we agree. |
This can be confusing when whitespace is the separator Fixes rust-lang#25986
This can be confusing when whitespace is the separator Fixes #25986
It's not clear to me if this is the expected behavior or not, but this program:
yields:
whereas I expected:
If the current behavior is expected, it should be more clearly documented, at minimum.
cc @Kimundi
The text was updated successfully, but these errors were encountered: