Skip to content

Commit bc4def9

Browse files
committed
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.
1 parent 763f923 commit bc4def9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/librustc_unicode/char.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,13 @@ impl char {
668668
/// Basic usage:
669669
///
670670
/// ```
671-
/// assert_eq!('C'.to_lowercase().next(), Some('c'));
671+
/// assert_eq!('C'.to_lowercase().collect::<String>(), "c");
672+
///
673+
/// // Sometimes the result is more than one character:
674+
/// assert_eq!('İ'.to_lowercase().collect::<String>(), "i\u{307}");
672675
///
673676
/// // Japanese scripts do not have case, and so:
674-
/// assert_eq!('山'.to_lowercase().next(), Some('山'));
677+
/// assert_eq!('山'.to_lowercase().collect::<String>(), "山");
675678
/// ```
676679
#[stable(feature = "rust1", since = "1.0.0")]
677680
#[inline]
@@ -702,10 +705,13 @@ impl char {
702705
/// Basic usage:
703706
///
704707
/// ```
705-
/// assert_eq!('c'.to_uppercase().next(), Some('C'));
708+
/// assert_eq!('c'.to_uppercase().collect::<String>(), "C");
709+
///
710+
/// // Sometimes the result is more than one character:
711+
/// assert_eq!('ß'.to_uppercase().collect::<String>(), "SS");
706712
///
707713
/// // Japanese does not have case, and so:
708-
/// assert_eq!('山'.to_uppercase().next(), Some('山'));
714+
/// assert_eq!('山'.to_uppercase().collect::<String>(), "山");
709715
/// ```
710716
///
711717
/// In Turkish, the equivalent of 'i' in Latin has five forms instead of two:
@@ -716,17 +722,17 @@ impl char {
716722
/// Note that the lowercase dotted 'i' is the same as the Latin. Therefore:
717723
///
718724
/// ```
719-
/// let upper_i = 'i'.to_uppercase().next();
725+
/// let upper_i: String = 'i'.to_uppercase().collect();
720726
/// ```
721727
///
722728
/// The value of `upper_i` here relies on the language of the text: if we're
723-
/// in `en-US`, it should be `Some('I')`, but if we're in `tr_TR`, it should
724-
/// be `Some('İ')`. `to_uppercase()` does not take this into account, and so:
729+
/// in `en-US`, it should be `"I"`, but if we're in `tr_TR`, it should
730+
/// be `"İ"`. `to_uppercase()` does not take this into account, and so:
725731
///
726732
/// ```
727-
/// let upper_i = 'i'.to_uppercase().next();
733+
/// let upper_i: String = 'i'.to_uppercase().collect();
728734
///
729-
/// assert_eq!(Some('I'), upper_i);
735+
/// assert_eq!(upper_i, "I");
730736
/// ```
731737
///
732738
/// holds across languages.

0 commit comments

Comments
 (0)