Skip to content

Commit b3eb9a0

Browse files
committed
Merge pull request #1382 from Lenny222/char
"char": add is_lowercase(), is_uppercase()
2 parents 900bc12 + eb0cdc0 commit b3eb9a0

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/libcore/char.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ import is_alphabetic = unicode::derived_property::Alphabetic;
4141
import is_XID_start = unicode::derived_property::XID_Start;
4242
import is_XID_continue = unicode::derived_property::XID_Continue;
4343

44+
/*
45+
Function: is_lowercase
46+
47+
Indicates whether a character is in lower case, defined in terms of the
48+
Unicode General Category 'Ll'.
49+
*/
50+
pure fn is_lowercase(c: char) -> bool {
51+
ret unicode::general_category::Ll(c);
52+
}
53+
54+
/*
55+
Function: is_uppercase
56+
57+
Indicates whether a character is in upper case, defined in terms of the
58+
Unicode General Category 'Lu'.
59+
*/
60+
pure fn is_uppercase(c: char) -> bool {
61+
ret unicode::general_category::Lu(c);
62+
}
63+
4464
/*
4565
Function: is_whitespace
4666
@@ -126,4 +146,4 @@ pure fn cmp(a: char, b: char) -> int {
126146
ret if b > a { -1 }
127147
else if b < a { 1 }
128148
else { 0 }
129-
}
149+
}

src/test/stdtest/char.rs

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ import core::*;
33
use std;
44
import char;
55

6+
#[test]
7+
fn test_is_lowercase() {
8+
assert char::is_lowercase('a');
9+
assert char::is_lowercase('ö');
10+
assert char::is_lowercase('ß');
11+
assert !char::is_lowercase('Ü');
12+
assert !char::is_lowercase('P');
13+
}
14+
15+
#[test]
16+
fn test_is_uppercase() {
17+
assert !char::is_uppercase('h');
18+
assert !char::is_uppercase('ä');
19+
assert !char::is_uppercase('ß');
20+
assert char::is_uppercase('Ö');
21+
assert char::is_uppercase('T');
22+
}
23+
624
#[test]
725
fn test_is_whitespace() {
826
assert char::is_whitespace(' ');

0 commit comments

Comments
 (0)