Skip to content

Commit 0e88712

Browse files
authored
Rollup merge of #72371 - Elrendio:char_documentation, r=steveklabnik
FIX - Char documentation for unexperienced users This is my first PR on rust and even if I've read [CONTRIBUTING.md](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#pull-requests) I'm ensure everything is perfect. Sorry if I didn't follow the exact procedure. **What it does:** - Add an example in the char documentation **Explanation** Unexperienced users might not know that punctuation is `Case_Ignorable` and not `Uppercase` and `Lowercase` which mean that when checking if a string is uppercase one might be tempted to write: ```rust my_string.chars().all(char::is_uppercase) ``` However this will return false for `"HELLO WORLD"` which is not intuitive. Since the function `is_case_ignorable` doesn't exists I believe the correct way to check is: ```rust !my_string.chars().any(char::is_lowercase) ``` The aim of this example is to prevent unexperienced users to make an error which punctuation chars.
2 parents 4f9fe91 + f5b4957 commit 0e88712

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcore/char/methods.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,9 @@ impl char {
812812
/// assert!(!'A'.is_lowercase());
813813
/// assert!(!'Δ'.is_lowercase());
814814
///
815-
/// // The various Chinese scripts do not have case, and so:
815+
/// // The various Chinese scripts and punctuation do not have case, and so:
816816
/// assert!(!'中'.is_lowercase());
817+
/// assert!(!' '.is_lowercase());
817818
/// ```
818819
#[stable(feature = "rust1", since = "1.0.0")]
819820
#[inline]
@@ -843,8 +844,9 @@ impl char {
843844
/// assert!('A'.is_uppercase());
844845
/// assert!('Δ'.is_uppercase());
845846
///
846-
/// // The various Chinese scripts do not have case, and so:
847+
/// // The various Chinese scripts and punctuation do not have case, and so:
847848
/// assert!(!'中'.is_uppercase());
849+
/// assert!(!' '.is_uppercase());
848850
/// ```
849851
#[stable(feature = "rust1", since = "1.0.0")]
850852
#[inline]

0 commit comments

Comments
 (0)