File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -85,10 +85,18 @@ pure fn is_alphanumeric(c: char) -> bool {
85
85
unicode:: general_category:: No ( c) ;
86
86
}
87
87
88
+ #[ doc( brief = "Indicates whether the character is an ASCII character" ) ]
88
89
pure fn is_ascii ( c : char ) -> bool {
89
90
c - ( '\x7F' & c) == '\x00'
90
91
}
91
92
93
+ #[ doc( brief = "Indicates whether the character is numeric (Nd, Nl, or No)" ) ]
94
+ pure fn is_digit ( c : char ) -> bool {
95
+ ret unicode:: general_category:: Nd ( c) ||
96
+ unicode:: general_category:: Nl ( c) ||
97
+ unicode:: general_category:: No ( c) ;
98
+ }
99
+
92
100
#[ doc(
93
101
brief = "Convert a char to the corresponding digit. \
94
102
Safety note: This function fails if `c` is not a valid char",
@@ -227,8 +235,18 @@ fn test_to_upper() {
227
235
}
228
236
229
237
#[ test]
230
- fn test_ascii ( ) unsafe {
238
+ fn test_is_ascii ( ) unsafe {
231
239
assert str:: all ( "banana" , char:: is_ascii) ;
232
240
assert ! str:: all ( "ประเทศไทย中华Việt Nam" , char:: is_ascii) ;
233
241
}
234
242
243
+ #[ test]
244
+ fn test_is_digit ( ) {
245
+ assert is_digit ( '2' ) ;
246
+ assert is_digit ( '7' ) ;
247
+ assert ! is_digit( 'c' ) ;
248
+ assert ! is_digit( 'i' ) ;
249
+ assert ! is_digit( 'z' ) ;
250
+ assert ! is_digit( 'Q' ) ;
251
+ }
252
+
You can’t perform that action at this time.
0 commit comments