Skip to content

Commit b3444db

Browse files
committed
core: added a rough char::is_ascii
1 parent 4339307 commit b3444db

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libcore/char.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export is_alphabetic,
3737
is_XID_start, is_XID_continue,
3838
is_lowercase, is_uppercase,
3939
is_whitespace, is_alphanumeric,
40+
is_ascii,
4041
to_digit, to_lower, to_upper, maybe_digit, cmp;
4142

4243
import is_alphabetic = unicode::derived_property::Alphabetic;
@@ -84,6 +85,9 @@ pure fn is_alphanumeric(c: char) -> bool {
8485
unicode::general_category::No(c);
8586
}
8687

88+
pure fn is_ascii(c: char) -> bool {
89+
c - ('\x7F' & c) == '\x00'
90+
}
8791

8892
#[doc(
8993
brief = "Convert a char to the corresponding digit. \
@@ -221,3 +225,10 @@ fn test_to_upper() {
221225
//assert (to_upper('ü') == 'Ü');
222226
assert (to_upper('ß') == 'ß');
223227
}
228+
229+
#[test]
230+
fn test_ascii() unsafe {
231+
assert str::all("banana", char::is_ascii);
232+
assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii);
233+
}
234+

0 commit comments

Comments
 (0)