Skip to content

Commit df50510

Browse files
committed
rollup merge of #23665: steveklabnik/doc_std_ascii
Also tweaked a few things.
2 parents ac24a51 + 528a5e2 commit df50510

File tree

1 file changed

+96
-4
lines changed

1 file changed

+96
-4
lines changed

src/libstd/ascii.rs

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,122 @@ pub trait OwnedAsciiExt {
3434
fn into_ascii_lowercase(self) -> Self;
3535
}
3636

37-
/// Extension methods for ASCII-subset only operations on string slices
37+
/// Extension methods for ASCII-subset only operations on string slices.
3838
#[stable(feature = "rust1", since = "1.0.0")]
3939
pub trait AsciiExt {
4040
/// Container type for copied ASCII characters.
4141
#[stable(feature = "rust1", since = "1.0.0")]
4242
type Owned;
4343

4444
/// Check if within the ASCII range.
45+
///
46+
/// # Examples
47+
///
48+
/// ```
49+
/// use std::ascii::AsciiExt;
50+
///
51+
/// let ascii = 'a';
52+
/// let utf8 = '❤';
53+
///
54+
/// assert_eq!(true, ascii.is_ascii());
55+
/// assert_eq!(false, utf8.is_ascii())
56+
/// ```
4557
#[stable(feature = "rust1", since = "1.0.0")]
4658
fn is_ascii(&self) -> bool;
4759

48-
/// Makes a copy of the string in ASCII upper case:
60+
/// Makes a copy of the string in ASCII upper case.
61+
///
4962
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
5063
/// but non-ASCII letters are unchanged.
64+
///
65+
/// # Examples
66+
///
67+
/// ```
68+
/// use std::ascii::AsciiExt;
69+
///
70+
/// let ascii = 'a';
71+
/// let utf8 = '❤';
72+
///
73+
/// assert_eq!('A', ascii.to_ascii_uppercase());
74+
/// assert_eq!('❤', utf8.to_ascii_uppercase());
75+
/// ```
5176
#[stable(feature = "rust1", since = "1.0.0")]
5277
fn to_ascii_uppercase(&self) -> Self::Owned;
5378

54-
/// Makes a copy of the string in ASCII lower case:
79+
/// Makes a copy of the string in ASCII lower case.
80+
///
5581
/// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z',
5682
/// but non-ASCII letters are unchanged.
83+
///
84+
/// # Examples
85+
///
86+
/// ```
87+
/// use std::ascii::AsciiExt;
88+
///
89+
/// let ascii = 'A';
90+
/// let utf8 = '❤';
91+
///
92+
/// assert_eq!('a', ascii.to_ascii_lowercase());
93+
/// assert_eq!('❤', utf8.to_ascii_lowercase());
94+
/// ```
5795
#[stable(feature = "rust1", since = "1.0.0")]
5896
fn to_ascii_lowercase(&self) -> Self::Owned;
5997

6098
/// Check that two strings are an ASCII case-insensitive match.
99+
///
61100
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
62101
/// but without allocating and copying temporary strings.
102+
///
103+
/// # Examples
104+
///
105+
/// ```
106+
/// use std::ascii::AsciiExt;
107+
///
108+
/// let ascii1 = 'A';
109+
/// let ascii2 = 'a';
110+
/// let ascii3 = 'A';
111+
/// let ascii4 = 'z';
112+
///
113+
/// assert_eq!(true, ascii1.eq_ignore_ascii_case(&ascii2));
114+
/// assert_eq!(true, ascii1.eq_ignore_ascii_case(&ascii3));
115+
/// assert_eq!(false, ascii1.eq_ignore_ascii_case(&ascii4));
116+
/// ```
63117
#[stable(feature = "rust1", since = "1.0.0")]
64118
fn eq_ignore_ascii_case(&self, other: &Self) -> bool;
65119

66120
/// Convert this type to its ASCII upper case equivalent in-place.
67121
///
68122
/// See `to_ascii_uppercase` for more information.
123+
///
124+
/// # Examples
125+
///
126+
/// ```
127+
/// use std::ascii::AsciiExt;
128+
///
129+
/// let mut ascii = 'a';
130+
///
131+
/// ascii.make_ascii_uppercase();
132+
///
133+
/// assert_eq!('A', ascii);
134+
/// ```
69135
#[unstable(feature = "ascii")]
70136
fn make_ascii_uppercase(&mut self);
71137

72138
/// Convert this type to its ASCII lower case equivalent in-place.
73139
///
74140
/// See `to_ascii_lowercase` for more information.
141+
///
142+
/// # Examples
143+
///
144+
/// ```
145+
/// use std::ascii::AsciiExt;
146+
///
147+
/// let mut ascii = 'A';
148+
///
149+
/// ascii.make_ascii_lowercase();
150+
///
151+
/// assert_eq!('a', ascii);
152+
/// ```
75153
#[unstable(feature = "ascii")]
76154
fn make_ascii_lowercase(&mut self);
77155
}
@@ -246,7 +324,7 @@ pub struct EscapeDefault {
246324
data: [u8; 4],
247325
}
248326

249-
/// Returns a 'default' ASCII and C++11-like literal escape of a `u8`
327+
/// Returns an iterator that produces an escaped version of a `u8`.
250328
///
251329
/// The default is chosen with a bias toward producing literals that are
252330
/// legal in a variety of languages, including C++11 and similar C-family
@@ -257,6 +335,20 @@ pub struct EscapeDefault {
257335
/// - Any other chars in the range [0x20,0x7e] are not escaped.
258336
/// - Any other chars are given hex escapes of the form '\xNN'.
259337
/// - Unicode escapes are never generated by this function.
338+
///
339+
/// # Examples
340+
///
341+
/// ```
342+
/// use std::ascii;
343+
///
344+
/// let escaped = ascii::escape_default(b'0').next().unwrap();
345+
/// assert_eq!(b'0', escaped);
346+
///
347+
/// let mut escaped = ascii::escape_default(b'\t');
348+
///
349+
/// assert_eq!(b'\\', escaped.next().unwrap());
350+
/// assert_eq!(b't', escaped.next().unwrap());
351+
/// ```
260352
#[stable(feature = "rust1", since = "1.0.0")]
261353
pub fn escape_default(c: u8) -> EscapeDefault {
262354
let (data, len) = match c {

0 commit comments

Comments
 (0)