Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"char": add is_lowercase(), is_uppercase() #1382

Merged
merged 1 commit into from
Dec 24, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -126,4 +146,4 @@ pure fn cmp(a: char, b: char) -> int {
ret if b > a { -1 }
else if b < a { 1 }
else { 0 }
}
}
18 changes: 18 additions & 0 deletions src/test/stdtest/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down