Merge pull request #1382 from Lenny222/char

"char": add is_lowercase(), is_uppercase()
This commit is contained in:
Graydon Hoare
2011-12-24 11:55:39 -08:00
2 changed files with 39 additions and 1 deletions
+21 -1
View File
@@ -41,6 +41,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
@@ -126,4 +146,4 @@
ret if b > a { -1 }
else if b < a { 1 }
else { 0 }
}
}
+18
View File
@@ -3,6 +3,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(' ');