-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Write a bunch of docs for char #28852
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
cc @SimonSapin |
/// * `a-z` | ||
/// * `A-Z` | ||
/// | ||
/// For a more comprehensive understanding of 'digit', see [``][is_numeric]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link doesn't have a body
7fb7a95
to
d1a917a
Compare
/// | ||
/// assert_eq!(c.to_uppercase().next(), Some('C')); | ||
/// | ||
/// // 日本語 does not have case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment appears as three glyphs for me, but the character is one. Intentional?
Similar stuff happens in other Han/Kanji examples above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as the three glyphs are how you write "Japanese" and "Chinese". I thought that it would be good to write them in their own scripts, given that we're in a crate based around Unicode. Of course, maybe that means I should be using "Türkçe" too, come to think of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Probably should mention the script name, not language name (Japanese, for one, has 3+ scripts), and romanize it too because in this case it looks like it's supposed to be the same as the character below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since case is a property of a language, and not neccesarily a script, as you mention, I was using the language name, but yeah, maybe that's just too confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One difficulty is that 漢字 (the name of the writing system / script) is romanized differently depending on which language’s pronunciation you use. So maybe like this, to avoid picking sides?
/// // 漢字 (Kanji / Hanji) does not have case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since case is a property of a language, and not necessarily a script
Is it? Is there any script that has case in one language but not in another language?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing is that Japanese' Unicode representation includes special latin scripts which do have upper and lower case forms.
r=me with nits, though SImon should probably have a look first. |
/// * Single quote is escaped as `\'`. | ||
/// * Double quote is escaped as `\"`. | ||
/// * Backslash is escaped as `\\`. | ||
/// * Any character in the range `0x20` .. `0x7e` inclusive is not escaped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that this is the range of "printable" characters in ASCII.
All done reviewing. Thanks for the polish, Steve! This kind of work makes the difference between good and great documentation. |
I've done everything except @Manishearth's 'radix' bit, so please feel free to re-review those fixes to make sure they work. |
Hmm, can't tell why the build failed here, is it just buried in the output somwhere? |
👍 |
/// let c = 'Δ'; | ||
/// assert!(!c.is_lowercase()); | ||
/// | ||
/// // The various Chinese languages do not have case, and so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/language/script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm this is an interesting question, I guess it is a property of a script and not a language
nitpick: case is a property of the script, not just the language. For example, capitalization if followed in romaji (Romanized Japanese). Otherwise lgtm |
f7a32e5
to
78a71fa
Compare
still have to do the radix bit, but fixed everything else. I wonder if the tests will pass this time, I verified that they work locally, and still can't see where the error is on travis. |
@@ -195,21 +253,29 @@ impl char { | |||
#[inline] | |||
pub fn escape_unicode(self) -> EscapeUnicode { C::escape_unicode(self) } | |||
|
|||
/// Returns an iterator that yields the 'default' ASCII and | |||
/// C++11-like literal escape of a character, as `char`s. | |||
/// Returns an iterator of that yields the literal escape code of a `char`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be "iterator that"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch
@@ -234,29 +300,69 @@ impl char { | |||
#[inline] | |||
pub fn escape_default(self) -> EscapeDefault { C::escape_default(self) } | |||
|
|||
/// Returns the number of bytes this character would need if encoded in | |||
/// UTF-8. | |||
/// Returns the number of bytes the character this `char` would need if encoded in UTF-8. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be "bytes this char
would need"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, because the encoding really matters, it's not a well-formed statement otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant that the full sentence seems like it should be:
Returns the number of bytes this `char` would need if encoded in UTF-8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhhh
6858e83
to
16b2250
Compare
/// let result = thread::spawn(|| { | ||
/// let d = '1'; | ||
/// | ||
/// d.is_digit(37); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation here looks like 2 spaces instead of 4, also perhaps this could have something like // this panics
and the test could be annotated with should_panic
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test does not actually panic though, as we spin up a thread and check the error.
(the spacing is my bad though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True but it seems unidiomatic to spawn a thread in an example just to show that it fails? It seems like it may be distracting in terms of reading...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, change to that. I thought this was the preferred way to do it, but I guess I can change it if you'd prefer. We should have a good way to visually indicate this in rustdoc too...
So both
pass locally for me. So unsure about travis :/ @alexcrichton said he thinks it's due to the literal null in the source, but then not sure why it works for me. |
Ah sorry, right, it was |
The error message is amazing
Looks like I'll have to remove the NULL for now, and file a rustdoc bug |
Mostly adding examples, and reformatting for consistency.
okay, travis passed. Everyone happy now? :) |
Looks good to me. |
Mostly adding examples, and reformatting for consistency.
Mostly adding examples, and reformatting for consistency.