-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
str::trim_left
and str::trim_right
method names are misleading
#39499
Comments
@jimblandy, |
For that very reason, I agree with @jimblandy’s assessment. Since |
@jimblandy, @pthariensflame, |
Well, if the core team felt strongly enough, they could deprecate these names and introduce aliases with better names; they‘ve done exactly that before already. |
I should be clear that I have no experience with right-to-left scripts beyond what I've read of the Unicode specification, and what I've picked up from working on Firefox.
The Unicode standard specifies that Unicode text is always stored in "logical order", meaning the order in which the text would be read. So the Rust string
The full details are complicated, but roughly, whitespace characters inherit the direction of the characters around them that have a strong implicit direction. This means that
Yeah, that's the solution that makes sense to me. |
I think this may be a dupe of #30459? |
Yes, it is. Thanks! |
If you're processing text in a language written from right to left, these methods do the opposite of what they claim. They really refer to the start and end of the slice.
It might be good to have
trim_start
andtrim_end
aliases (with_matches
variants as well) to help people write clearer code in applications that typically process right-to-left text.The rest of the API is pretty good about avoiding this mistake; the only other exception I noticed was the
std::fmt
alignment flags.The text was updated successfully, but these errors were encountered: