Skip to content

Commit 73db842

Browse files
committed
Rollup merge of #31401 - frewsxcv:clarify-ascii, r=steveklabnik
Fixes #31203
2 parents 3cccf26 + 93d6425 commit 73db842

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libstd/ascii.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ use mem;
1818
use ops::Range;
1919

2020
/// Extension methods for ASCII-subset only operations on string slices.
21+
///
22+
/// Be aware that operations on seemingly non-ASCII characters can sometimes
23+
/// have unexpected results. Consider this example:
24+
///
25+
/// ```
26+
/// use std::ascii::AsciiExt;
27+
///
28+
/// assert_eq!("café".to_ascii_uppercase(), "CAFÉ");
29+
/// assert_eq!("café".to_ascii_uppercase(), "CAFé");
30+
/// ```
31+
///
32+
/// In the first example, the lowercased string is represented `"cafe\u{301}"`
33+
/// (the last character is an acute accent [combining character]). Unlike the
34+
/// other characters in the string, the combining character will not get mapped
35+
/// to an uppercase variant, resulting in `"CAFE\u{301}"`. In the second
36+
/// example, the lowercased string is represented `"caf\u{e9}"` (the last
37+
/// character is a single Unicode character representing an 'e' with an acute
38+
/// accent). Since the last character is defined outside the scope of ASCII,
39+
/// it will not get mapped to an uppercase variant, resulting in `"CAF\u{e9}"`.
40+
///
41+
/// [combining character]: https://en.wikipedia.org/wiki/Combining_character
2142
#[stable(feature = "rust1", since = "1.0.0")]
2243
pub trait AsciiExt {
2344
/// Container type for copied ASCII characters.

0 commit comments

Comments
 (0)