diff --git a/src/libcore/char.rs b/src/libcore/char.rs index a0833475437..05ca5a3c59e 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -41,6 +41,26 @@ import is_alphabetic = unicode::derived_property::Alphabetic; import is_XID_start = unicode::derived_property::XID_Start; import is_XID_continue = unicode::derived_property::XID_Continue; +/* +Function: is_lowercase + +Indicates whether a character is in lower case, defined in terms of the +Unicode General Category 'Ll'. +*/ +pure fn is_lowercase(c: char) -> bool { + ret unicode::general_category::Ll(c); +} + +/* +Function: is_uppercase + +Indicates whether a character is in upper case, defined in terms of the +Unicode General Category 'Lu'. +*/ +pure fn is_uppercase(c: char) -> bool { + ret unicode::general_category::Lu(c); +} + /* Function: is_whitespace @@ -126,4 +146,4 @@ pure fn cmp(a: char, b: char) -> int { ret if b > a { -1 } else if b < a { 1 } else { 0 } -} \ No newline at end of file +} diff --git a/src/test/stdtest/char.rs b/src/test/stdtest/char.rs index a02abcb5676..1ed61f5632f 100644 --- a/src/test/stdtest/char.rs +++ b/src/test/stdtest/char.rs @@ -3,6 +3,24 @@ import core::*; use std; import char; +#[test] +fn test_is_lowercase() { + assert char::is_lowercase('a'); + assert char::is_lowercase('ö'); + assert char::is_lowercase('ß'); + assert !char::is_lowercase('Ü'); + assert !char::is_lowercase('P'); +} + +#[test] +fn test_is_uppercase() { + assert !char::is_uppercase('h'); + assert !char::is_uppercase('ä'); + assert !char::is_uppercase('ß'); + assert char::is_uppercase('Ö'); + assert char::is_uppercase('T'); +} + #[test] fn test_is_whitespace() { assert char::is_whitespace(' ');