@@ -88,42 +88,108 @@ impl Ascii {
88
88
}
89
89
90
90
/// Check if the character is a control character
91
+ ///
92
+ /// # Examples
93
+ ///
94
+ /// ```
95
+ /// use ascii::AsciiCast;
96
+ /// assert_eq!('\0'.to_ascii().unwrap().is_control(), true);
97
+ /// assert_eq!('n'.to_ascii().unwrap().is_control(), false);
98
+ /// assert_eq!(' '.to_ascii().unwrap().is_control(), false);
99
+ /// assert_eq!('\n'.to_ascii().unwrap().is_control(), true);
100
+ /// ```
91
101
#[ inline]
92
102
pub fn is_control ( & self ) -> bool {
93
103
self . chr < 0x20 || self . chr == 0x7F
94
104
}
95
105
96
106
/// Checks if the character is printable (except space)
107
+ ///
108
+ /// # Examples
109
+ ///
110
+ /// ```
111
+ /// use ascii::AsciiCast;
112
+ /// assert_eq!('n'.to_ascii().unwrap().is_graph(), true);
113
+ /// assert_eq!(' '.to_ascii().unwrap().is_graph(), false);
114
+ /// assert_eq!('\n'.to_ascii().unwrap().is_graph(), false);
115
+ /// ```
97
116
#[ inline]
98
117
pub fn is_graph ( & self ) -> bool {
99
118
self . chr . wrapping_sub ( 0x21 ) < 0x5E
100
119
}
101
120
102
121
/// Checks if the character is printable (including space)
122
+ ///
123
+ /// # Examples
124
+ ///
125
+ /// ```
126
+ /// use ascii::AsciiCast;
127
+ /// assert_eq!('n'.to_ascii().unwrap().is_print(), true);
128
+ /// assert_eq!(' '.to_ascii().unwrap().is_print(), true);
129
+ /// assert_eq!('\n'.to_ascii().unwrap().is_print(), false);
130
+ /// ```
103
131
#[ inline]
104
132
pub fn is_print ( & self ) -> bool {
105
133
self . chr . wrapping_sub ( 0x20 ) < 0x5F
106
134
}
107
135
108
136
/// Checks if the character is alphabetic and lowercase
137
+ ///
138
+ /// # Examples
139
+ ///
140
+ /// ```
141
+ /// use ascii::AsciiCast;
142
+ /// assert_eq!('a'.to_ascii().unwrap().is_lowercase(), true);
143
+ /// assert_eq!('A'.to_ascii().unwrap().is_lowercase(), false);
144
+ /// assert_eq!('@'.to_ascii().unwrap().is_lowercase(), false);
145
+ /// ```
109
146
#[ inline]
110
147
pub fn is_lowercase ( & self ) -> bool {
111
148
self . chr . wrapping_sub ( b'a' ) < 26
112
149
}
113
150
114
151
/// Checks if the character is alphabetic and uppercase
152
+ ///
153
+ /// # Examples
154
+ ///
155
+ /// ```
156
+ /// use ascii::AsciiCast;
157
+ /// assert_eq!('A'.to_ascii().unwrap().is_uppercase(), true);
158
+ /// assert_eq!('a'.to_ascii().unwrap().is_uppercase(), false);
159
+ /// assert_eq!('@'.to_ascii().unwrap().is_uppercase(), false);
160
+ /// ```
115
161
#[ inline]
116
162
pub fn is_uppercase ( & self ) -> bool {
117
163
self . chr . wrapping_sub ( b'A' ) < 26
118
164
}
119
165
120
166
/// Checks if the character is punctuation
167
+ ///
168
+ /// # Examples
169
+ ///
170
+ /// ```
171
+ /// use ascii::AsciiCast;
172
+ /// assert_eq!('n'.to_ascii().unwrap().is_punctuation(), false);
173
+ /// assert_eq!(' '.to_ascii().unwrap().is_punctuation(), false);
174
+ /// assert_eq!('_'.to_ascii().unwrap().is_punctuation(), true);
175
+ /// assert_eq!('~'.to_ascii().unwrap().is_punctuation(), true);
176
+ /// ```
121
177
#[ inline]
122
178
pub fn is_punctuation ( & self ) -> bool {
123
179
self . is_graph ( ) && !self . is_alphanumeric ( )
124
180
}
125
181
126
182
/// Checks if the character is a valid hex digit
183
+ ///
184
+ /// # Examples
185
+ ///
186
+ /// ```
187
+ /// use ascii::AsciiCast;
188
+ /// assert_eq!('5'.to_ascii().unwrap().is_hex(), true);
189
+ /// assert_eq!('a'.to_ascii().unwrap().is_hex(), true);
190
+ /// assert_eq!('F'.to_ascii().unwrap().is_hex(), true);
191
+ /// assert_eq!(32u8.to_ascii().unwrap().is_hex(), false);
192
+ /// ```
127
193
#[ inline]
128
194
pub fn is_hex ( & self ) -> bool {
129
195
self . is_digit ( ) || ( self . chr | 32u8 ) . wrapping_sub ( b'a' ) < 6
0 commit comments