Skip to content

Commit d6f2364

Browse files
committed
auto merge of #8260 : omasanori/rust/fix-extra-unicode, r=pcwalton
WIth this patch `RUSTFLAGS='--cfg unicode' make check"` passed successfully. * Why doesn't `#[link_name="icuuc"]` make libextra to link against libicuuc.so? * In `extra::unicode::tests`, `use unicode; unicode::is_foo('a')` failed but `use unicode::*; is_foo('a')` succeeded. Is it right?
2 parents 3d14470 + c1ad16d commit d6f2364

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/libextra/unicode.rs

+33-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[forbid(deprecated_mode)];
1211
#[allow(missing_doc)];
1312

1413
pub mod icu {
@@ -159,7 +158,10 @@ pub mod icu {
159158
pub static UCHAR_INVALID_CODE : UProperty = -1;
160159

161160
pub mod libicu {
162-
#[link_name = "icuuc"]
161+
use unicode::icu::*;
162+
163+
// #[link_name = "icuuc"]
164+
#[link_args = "-licuuc"]
163165
#[abi = "cdecl"]
164166
extern {
165167
pub fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool;
@@ -174,13 +176,17 @@ pub mod icu {
174176
}
175177

176178
pub fn is_XID_start(c: char) -> bool {
177-
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
178-
== icu::TRUE;
179+
unsafe {
180+
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
181+
== icu::TRUE;
182+
}
179183
}
180184

181185
pub fn is_XID_continue(c: char) -> bool {
182-
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
183-
== icu::TRUE;
186+
unsafe {
187+
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
188+
== icu::TRUE;
189+
}
184190
}
185191

186192
/*
@@ -189,7 +195,9 @@ Function: is_digit
189195
Returns true if a character is a digit.
190196
*/
191197
pub fn is_digit(c: char) -> bool {
192-
return icu::libicu::u_isdigit(c) == icu::TRUE;
198+
unsafe {
199+
return icu::libicu::u_isdigit(c) == icu::TRUE;
200+
}
193201
}
194202

195203
/*
@@ -198,7 +206,9 @@ Function: is_lower
198206
Returns true if a character is a lowercase letter.
199207
*/
200208
pub fn is_lower(c: char) -> bool {
201-
return icu::libicu::u_islower(c) == icu::TRUE;
209+
unsafe {
210+
return icu::libicu::u_islower(c) == icu::TRUE;
211+
}
202212
}
203213

204214
/*
@@ -207,7 +217,9 @@ Function: is_space
207217
Returns true if a character is space.
208218
*/
209219
pub fn is_space(c: char) -> bool {
210-
return icu::libicu::u_isspace(c) == icu::TRUE;
220+
unsafe {
221+
return icu::libicu::u_isspace(c) == icu::TRUE;
222+
}
211223
}
212224

213225
/*
@@ -216,33 +228,36 @@ Function: is_upper
216228
Returns true if a character is an uppercase letter.
217229
*/
218230
pub fn is_upper(c: char) -> bool {
219-
return icu::libicu::u_isupper(c) == icu::TRUE;
231+
unsafe {
232+
return icu::libicu::u_isupper(c) == icu::TRUE;
233+
}
220234
}
221235

222236
#[cfg(test)]
223237
mod tests {
238+
use unicode::*;
224239

225240
#[test]
226241
fn test_is_digit() {
227-
assert!((unicode::icu::is_digit('0')));
228-
assert!((!unicode::icu::is_digit('m')));
242+
assert!((is_digit('0')));
243+
assert!((!is_digit('m')));
229244
}
230245

231246
#[test]
232247
fn test_is_lower() {
233-
assert!((unicode::icu::is_lower('m')));
234-
assert!((!unicode::icu::is_lower('M')));
248+
assert!((is_lower('m')));
249+
assert!((!is_lower('M')));
235250
}
236251

237252
#[test]
238253
fn test_is_space() {
239-
assert!((unicode::icu::is_space(' ')));
240-
assert!((!unicode::icu::is_space('m')));
254+
assert!((is_space(' ')));
255+
assert!((!is_space('m')));
241256
}
242257

243258
#[test]
244259
fn test_is_upper() {
245-
assert!((unicode::icu::is_upper('M')));
246-
assert!((!unicode::icu::is_upper('m')));
260+
assert!((is_upper('M')));
261+
assert!((!is_upper('m')));
247262
}
248263
}

0 commit comments

Comments
 (0)