diff options
| author | Lenny222 <github@kudling.de> | 2011-12-24 10:41:11 +0100 |
|---|---|---|
| committer | Lenny222 <github@kudling.de> | 2011-12-24 10:41:11 +0100 |
| commit | eb0cdc02e3b443fe119cb4957856a63dbd5923d4 (patch) | |
| tree | 9cf0ac2bce40110667e28b044566cbaea3a51524 /src | |
| parent | 47271ab4c85ecc4b7c3f1c079f8bc221a5d7ca0d (diff) | |
| download | rust-eb0cdc02e3b443fe119cb4957856a63dbd5923d4.tar.gz rust-eb0cdc02e3b443fe119cb4957856a63dbd5923d4.zip | |
char: add is_lowercase(), is_uppercase()
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/char.rs | 22 | ||||
| -rw-r--r-- | src/test/stdtest/char.rs | 18 |
2 files changed, 39 insertions, 1 deletions
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 @@ -42,6 +42,26 @@ 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 Indicates whether a character is whitespace, defined in terms of @@ -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 @@ -4,6 +4,24 @@ 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(' '); assert char::is_whitespace('\u2007'); |
