Skip to content

Commit

Permalink
Rollup merge of rust-lang#34165 - ollie27:docs_char_case, r=steveklabnik
Browse files Browse the repository at this point in the history
docs: Improve char::to_{lower,upper}case examples

Collect the results to a String to make it clear that it will not always
return only one char and add examples showing that.

r? @steveklabnik
  • Loading branch information
sanxiyn committed Jun 10, 2016
2 parents a320467 + bc4def9 commit 2092031
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,13 @@ impl char {
/// Basic usage:
///
/// ```
/// assert_eq!('C'.to_lowercase().next(), Some('c'));
/// assert_eq!('C'.to_lowercase().collect::<String>(), "c");
///
/// // Sometimes the result is more than one character:
/// assert_eq!('İ'.to_lowercase().collect::<String>(), "i\u{307}");
///
/// // Japanese scripts do not have case, and so:
/// assert_eq!('山'.to_lowercase().next(), Some('山'));
/// assert_eq!('山'.to_lowercase().collect::<String>(), "山");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -702,10 +705,13 @@ impl char {
/// Basic usage:
///
/// ```
/// assert_eq!('c'.to_uppercase().next(), Some('C'));
/// assert_eq!('c'.to_uppercase().collect::<String>(), "C");
///
/// // Sometimes the result is more than one character:
/// assert_eq!('ß'.to_uppercase().collect::<String>(), "SS");
///
/// // Japanese does not have case, and so:
/// assert_eq!('山'.to_uppercase().next(), Some('山'));
/// assert_eq!('山'.to_uppercase().collect::<String>(), "山");
/// ```
///
/// In Turkish, the equivalent of 'i' in Latin has five forms instead of two:
Expand All @@ -716,17 +722,17 @@ impl char {
/// Note that the lowercase dotted 'i' is the same as the Latin. Therefore:
///
/// ```
/// let upper_i = 'i'.to_uppercase().next();
/// let upper_i: String = 'i'.to_uppercase().collect();
/// ```
///
/// The value of `upper_i` here relies on the language of the text: if we're
/// in `en-US`, it should be `Some('I')`, but if we're in `tr_TR`, it should
/// be `Some('İ')`. `to_uppercase()` does not take this into account, and so:
/// in `en-US`, it should be `"I"`, but if we're in `tr_TR`, it should
/// be `"İ"`. `to_uppercase()` does not take this into account, and so:
///
/// ```
/// let upper_i = 'i'.to_uppercase().next();
/// let upper_i: String = 'i'.to_uppercase().collect();
///
/// assert_eq!(Some('I'), upper_i);
/// assert_eq!(upper_i, "I");
/// ```
///
/// holds across languages.
Expand Down

0 comments on commit 2092031

Please sign in to comment.