Skip to content

Commit 900bc12

Browse files
committed
Merge pull request #1377 from Lenny222/icu
std::unicode::icu: add "is*" functions + unit test
2 parents 47271ab + d812d06 commit 900bc12

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/libstd/unicode.rs

+43
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ mod icu {
152152
#[abi = "cdecl"]
153153
native mod libicu {
154154
pure fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool;
155+
pure fn u_isdigit(c: UChar32) -> UBool;
156+
pure fn u_islower(c: UChar32) -> UBool;
157+
pure fn u_isspace(c: UChar32) -> UBool;
158+
pure fn u_isupper(c: UChar32) -> UBool;
159+
pure fn u_tolower(c: UChar32) -> UChar32;
160+
pure fn u_toupper(c: UChar32) -> UChar32;
155161
}
156162
}
157163

@@ -164,3 +170,40 @@ pure fn is_XID_continue(c: char) -> bool {
164170
ret icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
165171
== icu::TRUE;
166172
}
173+
174+
/*
175+
Function: is_digit
176+
177+
Returns true if a character is a digit.
178+
*/
179+
pure fn is_digit(c: char) -> bool {
180+
ret icu::libicu::u_isdigit(c) == icu::TRUE;
181+
}
182+
183+
/*
184+
Function: is_lower
185+
186+
Returns true if a character is a lowercase letter.
187+
*/
188+
pure fn is_lower(c: char) -> bool {
189+
ret icu::libicu::u_islower(c) == icu::TRUE;
190+
}
191+
192+
/*
193+
Function: is_space
194+
195+
Returns true if a character is space.
196+
*/
197+
pure fn is_space(c: char) -> bool {
198+
ret icu::libicu::u_isspace(c) == icu::TRUE;
199+
}
200+
201+
/*
202+
Function: is_upper
203+
204+
Returns true if a character is an uppercase letter.
205+
*/
206+
pure fn is_upper(c: char) -> bool {
207+
ret icu::libicu::u_isupper(c) == icu::TRUE;
208+
}
209+

src/test/stdtest/stdtest.rc

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ mod test;
3939
mod tri;
4040
mod treemap;
4141
mod uint;
42+
43+
#[cfg(unicode)]
44+
mod unicode;
45+
4246
mod unsafe;
4347
mod uv;
4448
mod vec;

src/test/stdtest/unicode.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import core::*;
2+
3+
use std;
4+
5+
import unicode;
6+
7+
#[test]
8+
fn test_is_digit() {
9+
assert (unicode::icu::is_digit('0'));
10+
assert (!unicode::icu::is_digit('m'));
11+
}
12+
13+
#[test]
14+
fn test_is_lower() {
15+
assert (unicode::icu::is_lower('m'));
16+
assert (!unicode::icu::is_lower('M'));
17+
}
18+
19+
#[test]
20+
fn test_is_space() {
21+
assert (unicode::icu::is_space(' '));
22+
assert (!unicode::icu::is_space('m'));
23+
}
24+
25+
#[test]
26+
fn test_is_upper() {
27+
assert (unicode::icu::is_upper('M'));
28+
assert (!unicode::icu::is_upper('m'));
29+
}
30+

0 commit comments

Comments
 (0)