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

str::encode_utf16 should have a doc example #44419

Closed
frewsxcv opened this issue Sep 8, 2017 · 3 comments
Closed

str::encode_utf16 should have a doc example #44419

frewsxcv opened this issue Sep 8, 2017 · 3 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Sep 8, 2017

https://doc.rust-lang.org/nightly/std/primitive.str.html#method.encode_utf16

If anyone anyone wants to work on this, just mention it in a comment to prevent duplicate work. If you need any help or have any questions, don't hesitate to ping me :)

@frewsxcv frewsxcv added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Sep 8, 2017
@alexcrichton alexcrichton added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Sep 8, 2017
@rwakulszowa
Copy link
Contributor

This seems easy, I'd like to give it a shot.

@rwakulszowa
Copy link
Contributor

Will something like this be okay?

let text = "Zażółć gęślą jaźń";

let utf8_len = text.len();
let utf16_len = text.encode_utf16().count();

assert!(utf16_len <= utf8_len);

I assumed the most obvious difference between utf8 and utf16 is the length of a non-Ascii string (hence the <= assertion). Technically I could assert for exact values, but that sounds like an overkill to me.

@steveklabnik
Copy link
Member

I assumed the most obvious difference between utf8 and utf16 is the length of a non-Ascii string

Agreed!

Technically I could assert for exact values, but that sounds like an overkill to me.

Same, this sounds good to me!

rwakulszowa added a commit to rwakulszowa/rust that referenced this issue Sep 12, 2017
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 13, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 14, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority
Projects
None yet
Development

No branches or pull requests

4 participants