@@ -34,44 +34,122 @@ pub trait OwnedAsciiExt {
34
34
fn into_ascii_lowercase ( self ) -> Self ;
35
35
}
36
36
37
- /// Extension methods for ASCII-subset only operations on string slices
37
+ /// Extension methods for ASCII-subset only operations on string slices.
38
38
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
39
39
pub trait AsciiExt {
40
40
/// Container type for copied ASCII characters.
41
41
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
42
42
type Owned ;
43
43
44
44
/// 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
+ /// ```
45
57
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
46
58
fn is_ascii ( & self ) -> bool ;
47
59
48
- /// Makes a copy of the string in ASCII upper case:
60
+ /// Makes a copy of the string in ASCII upper case.
61
+ ///
49
62
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
50
63
/// 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
+ /// ```
51
76
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
52
77
fn to_ascii_uppercase ( & self ) -> Self :: Owned ;
53
78
54
- /// Makes a copy of the string in ASCII lower case:
79
+ /// Makes a copy of the string in ASCII lower case.
80
+ ///
55
81
/// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z',
56
82
/// 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
+ /// ```
57
95
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
58
96
fn to_ascii_lowercase ( & self ) -> Self :: Owned ;
59
97
60
98
/// Check that two strings are an ASCII case-insensitive match.
99
+ ///
61
100
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
62
101
/// 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
+ /// ```
63
117
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
64
118
fn eq_ignore_ascii_case ( & self , other : & Self ) -> bool ;
65
119
66
120
/// Convert this type to its ASCII upper case equivalent in-place.
67
121
///
68
122
/// 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
+ /// ```
69
135
#[ unstable( feature = "ascii" ) ]
70
136
fn make_ascii_uppercase ( & mut self ) ;
71
137
72
138
/// Convert this type to its ASCII lower case equivalent in-place.
73
139
///
74
140
/// 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
+ /// ```
75
153
#[ unstable( feature = "ascii" ) ]
76
154
fn make_ascii_lowercase ( & mut self ) ;
77
155
}
@@ -246,7 +324,7 @@ pub struct EscapeDefault {
246
324
data : [ u8 ; 4 ] ,
247
325
}
248
326
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`.
250
328
///
251
329
/// The default is chosen with a bias toward producing literals that are
252
330
/// legal in a variety of languages, including C++11 and similar C-family
@@ -257,6 +335,20 @@ pub struct EscapeDefault {
257
335
/// - Any other chars in the range [0x20,0x7e] are not escaped.
258
336
/// - Any other chars are given hex escapes of the form '\xNN'.
259
337
/// - 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
+ /// ```
260
352
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
261
353
pub fn escape_default ( c : u8 ) -> EscapeDefault {
262
354
let ( data, len) = match c {
0 commit comments