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

Document why str.to_lowercase and str.to_uppercase return a String #39201

Closed
Havvy opened this issue Jan 20, 2017 · 1 comment
Closed

Document why str.to_lowercase and str.to_uppercase return a String #39201

Havvy opened this issue Jan 20, 2017 · 1 comment

Comments

@Havvy
Copy link
Contributor

Havvy commented Jan 20, 2017

I haven't checked, but I'm 95% certain that they do this because some characters expand into multiple characters when casefolding which wouldn't fit into the buffer of the str, so we need a new buffer. Since we don't know the size beforehand, we just return a String.

Probably should link to char.to_lowercase and char.to_uppercase.

@Havvy
Copy link
Contributor Author

Havvy commented Jan 20, 2017

(With permission from @ubsan & @awygle)

<ubsandroid> I don't understand how they wouldn't
<ubsandroid> even in plain ASCII...
<awygle> don't those take non-mutable references to self anyway, so they couldn't do the mutate-in-place thing?
<awygle> i guess that may not be a "why", exactly...
<Havvy> ubsandroid: Wouldn't do what?
<Havvy> awygle: Well, theoretically could have been &mut str.
<ubsandroid> Havvy: wouldn't be able to return anything but String
<ubsandroid> yeah but it's to_...
<ubsandroid> which is an &T -> U conversion
<Havvy> ubsandroid: Oh, right.
<Havvy> I missed that part of the convention.
<Havvy> Should at least document that the String could have more unicode characters than it started with.
<ubsandroid> yeah
<ubsandroid> sure

tbu- added a commit to tbu-/rust that referenced this issue Mar 7, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 8, 2017
…eklabnik

Document why `str.to_{lower,upper}case` return `String`

Fixes rust-lang#39201.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 8, 2017
…eklabnik

Document why `str.to_{lower,upper}case` return `String`

Fixes rust-lang#39201.
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 8, 2017
…eklabnik

Document why `str.to_{lower,upper}case` return `String`

Fixes rust-lang#39201.
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

No branches or pull requests

1 participant