From bc4def9e74305112b46ca72bd47940c71480e09a Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 8 Jun 2016 19:24:03 +0100 Subject: [PATCH] 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. --- src/librustc_unicode/char.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs index 77de51b32e2..f570375de5e 100644 --- a/src/librustc_unicode/char.rs +++ b/src/librustc_unicode/char.rs @@ -668,10 +668,13 @@ pub fn is_numeric(self) -> bool { /// Basic usage: /// /// ``` - /// assert_eq!('C'.to_lowercase().next(), Some('c')); + /// assert_eq!('C'.to_lowercase().collect::(), "c"); + /// + /// // Sometimes the result is more than one character: + /// assert_eq!('İ'.to_lowercase().collect::(), "i\u{307}"); /// /// // Japanese scripts do not have case, and so: - /// assert_eq!('山'.to_lowercase().next(), Some('山')); + /// assert_eq!('山'.to_lowercase().collect::(), "山"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -702,10 +705,13 @@ pub fn to_lowercase(self) -> ToLowercase { /// Basic usage: /// /// ``` - /// assert_eq!('c'.to_uppercase().next(), Some('C')); + /// assert_eq!('c'.to_uppercase().collect::(), "C"); + /// + /// // Sometimes the result is more than one character: + /// assert_eq!('ß'.to_uppercase().collect::(), "SS"); /// /// // Japanese does not have case, and so: - /// assert_eq!('山'.to_uppercase().next(), Some('山')); + /// assert_eq!('山'.to_uppercase().collect::(), "山"); /// ``` /// /// In Turkish, the equivalent of 'i' in Latin has five forms instead of two: @@ -716,17 +722,17 @@ pub fn to_lowercase(self) -> ToLowercase { /// 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. -- 2.44.0