From b3444db1614a85afd9f306459595c2870a6b2047 Mon Sep 17 00:00:00 2001 From: Kevin Cantu Date: Wed, 8 Feb 2012 01:28:23 -0800 Subject: [PATCH] core: added a rough char::is_ascii --- src/libcore/char.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 21028655626..2544550bd57 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -37,6 +37,7 @@ is_XID_start, is_XID_continue, is_lowercase, is_uppercase, is_whitespace, is_alphanumeric, + is_ascii, to_digit, to_lower, to_upper, maybe_digit, cmp; import is_alphabetic = unicode::derived_property::Alphabetic; @@ -84,6 +85,9 @@ unicode::general_category::No(c); } +pure fn is_ascii(c: char) -> bool { + c - ('\x7F' & c) == '\x00' +} #[doc( brief = "Convert a char to the corresponding digit. \ @@ -221,3 +225,10 @@ fn test_to_upper() { //assert (to_upper('ü') == 'Ü'); assert (to_upper('ß') == 'ß'); } + +#[test] +fn test_ascii() unsafe { + assert str::all("banana", char::is_ascii); + assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii); +} +