Skip to content

Commit a800e1e

Browse files
committed
unicode: Add stability attributes to u_char
Free functions deprecated. UnicodeChar experimental pending final decisions about prelude.
1 parent ad422ed commit a800e1e

File tree

7 files changed

+82
-59
lines changed

7 files changed

+82
-59
lines changed

src/libfmt_macros/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![crate_type = "dylib"]
2222
#![feature(macro_rules, globs, import_shadowing)]
2323

24-
use std::char;
2524
use std::str;
2625
use std::string;
2726

@@ -216,7 +215,7 @@ impl<'a> Parser<'a> {
216215
fn ws(&mut self) {
217216
loop {
218217
match self.cur.clone().next() {
219-
Some((_, c)) if char::is_whitespace(c) => { self.cur.next(); }
218+
Some((_, c)) if c.is_whitespace() => { self.cur.next(); }
220219
Some(..) | None => { return }
221220
}
222221
}
@@ -256,7 +255,7 @@ impl<'a> Parser<'a> {
256255
Some(i) => { ArgumentIs(i) }
257256
None => {
258257
match self.cur.clone().next() {
259-
Some((_, c)) if char::is_alphabetic(c) => {
258+
Some((_, c)) if c.is_alphabetic() => {
260259
ArgumentNamed(self.word())
261260
}
262261
_ => ArgumentNext
@@ -379,7 +378,7 @@ impl<'a> Parser<'a> {
379378
/// characters.
380379
fn word(&mut self) -> &'a str {
381380
let start = match self.cur.clone().next() {
382-
Some((pos, c)) if char::is_XID_start(c) => {
381+
Some((pos, c)) if c.is_XID_start() => {
383382
self.cur.next();
384383
pos
385384
}
@@ -388,7 +387,7 @@ impl<'a> Parser<'a> {
388387
let mut end;
389388
loop {
390389
match self.cur.clone().next() {
391-
Some((_, c)) if char::is_XID_continue(c) => {
390+
Some((_, c)) if c.is_XID_continue() => {
392391
self.cur.next();
393392
}
394393
Some((pos, _)) => { end = pos; break }

src/libgetopts/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
876876
}
877877

878878
let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| {
879-
let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr };
879+
let whitespace = if c.is_whitespace() { Ws } else { Cr };
880880
let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim };
881881

882882
state = match (state, whitespace, limit) {

src/librustc/back/link.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use util::common::time;
2727
use util::ppaux;
2828
use util::sha2::{Digest, Sha256};
2929

30-
use std::char;
3130
use std::io::fs::PathExtensions;
3231
use std::io::{fs, TempDir, Command};
3332
use std::io;
@@ -272,7 +271,7 @@ pub fn sanitize(s: &str) -> String {
272271
// Underscore-qualify anything that didn't start as an ident.
273272
if result.len() > 0u &&
274273
result.as_bytes()[0] != '_' as u8 &&
275-
! char::is_XID_start(result.as_bytes()[0] as char) {
274+
! (result.as_bytes()[0] as char).is_XID_start() {
276275
return format!("_{}", result.as_slice());
277276
}
278277

src/librustdoc/test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::cell::RefCell;
12-
use std::char;
1312
use std::dynamic_lib::DynamicLibrary;
1413
use std::io::{Command, TempDir};
1514
use std::io;
@@ -302,8 +301,8 @@ impl Collector {
302301
// we use these headings as test names, so it's good if
303302
// they're valid identifiers.
304303
let name = name.chars().enumerate().map(|(i, c)| {
305-
if (i == 0 && char::is_XID_start(c)) ||
306-
(i != 0 && char::is_XID_continue(c)) {
304+
if (i == 0 && c.is_XID_start()) ||
305+
(i != 0 && c.is_XID_continue()) {
307306
c
308307
} else {
309308
'_'

src/libsyntax/parse/lexer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ fn ident_start(c: Option<char>) -> bool {
14211421
(c >= 'a' && c <= 'z')
14221422
|| (c >= 'A' && c <= 'Z')
14231423
|| c == '_'
1424-
|| (c > '\x7f' && char::is_XID_start(c))
1424+
|| (c > '\x7f' && c.is_XID_start())
14251425
}
14261426

14271427
fn ident_continue(c: Option<char>) -> bool {
@@ -1431,7 +1431,7 @@ fn ident_continue(c: Option<char>) -> bool {
14311431
|| (c >= 'A' && c <= 'Z')
14321432
|| (c >= '0' && c <= '9')
14331433
|| c == '_'
1434-
|| (c > '\x7f' && char::is_XID_continue(c))
1434+
|| (c > '\x7f' && c.is_XID_continue())
14351435
}
14361436

14371437
#[cfg(test)]

src/libunicode/u_char.rs

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ use tables::{derived_property, property, general_category, conversions, charwidt
2020

2121
/// Returns whether the specified `char` is considered a Unicode alphabetic
2222
/// code point
23+
#[deprecated = "use UnicodeChar::is_alphabetic"]
2324
pub fn is_alphabetic(c: char) -> bool {
24-
match c {
25-
'a' ... 'z' | 'A' ... 'Z' => true,
26-
c if c > '\x7f' => derived_property::Alphabetic(c),
27-
_ => false
28-
}
25+
c.is_alphabetic()
2926
}
3027

3128
/// Returns whether the specified `char` satisfies the 'XID_Start' Unicode property
@@ -34,6 +31,7 @@ pub fn is_alphabetic(c: char) -> bool {
3431
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
3532
/// mostly similar to ID_Start but modified for closure under NFKx.
3633
#[allow(non_snake_case)]
34+
#[deprecated = "use UnicodeChar::is_XID_start"]
3735
pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) }
3836

3937
/// Returns whether the specified `char` satisfies the 'XID_Continue' Unicode property
@@ -42,6 +40,7 @@ pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) }
4240
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
4341
/// mostly similar to 'ID_Continue' but modified for closure under NFKx.
4442
#[allow(non_snake_case)]
43+
#[deprecated = "use UnicodeChar::is_XID_continue"]
4544
pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
4645

4746
///
@@ -50,12 +49,9 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
5049
/// This is defined according to the terms of the Unicode Derived Core Property 'Lowercase'.
5150
///
5251
#[inline]
52+
#[deprecated = "use UnicodeChar::is_lowercase"]
5353
pub fn is_lowercase(c: char) -> bool {
54-
match c {
55-
'a' ... 'z' => true,
56-
c if c > '\x7f' => derived_property::Lowercase(c),
57-
_ => false
58-
}
54+
c.is_lowercase()
5955
}
6056

6157
///
@@ -64,12 +60,9 @@ pub fn is_lowercase(c: char) -> bool {
6460
/// This is defined according to the terms of the Unicode Derived Core Property 'Uppercase'.
6561
///
6662
#[inline]
63+
#[deprecated = "use UnicodeChar::is_uppercase"]
6764
pub fn is_uppercase(c: char) -> bool {
68-
match c {
69-
'A' ... 'Z' => true,
70-
c if c > '\x7f' => derived_property::Uppercase(c),
71-
_ => false
72-
}
65+
c.is_uppercase()
7366
}
7467

7568
///
@@ -78,12 +71,9 @@ pub fn is_uppercase(c: char) -> bool {
7871
/// Whitespace is defined in terms of the Unicode Property 'White_Space'.
7972
///
8073
#[inline]
74+
#[deprecated = "use UnicodeChar::is_whitespace"]
8175
pub fn is_whitespace(c: char) -> bool {
82-
match c {
83-
' ' | '\x09' ... '\x0d' => true,
84-
c if c > '\x7f' => property::White_Space(c),
85-
_ => false
86-
}
76+
c.is_whitespace()
8777
}
8878

8979
///
@@ -93,9 +83,9 @@ pub fn is_whitespace(c: char) -> bool {
9383
/// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
9484
///
9585
#[inline]
86+
#[deprecated = "use UnicodeChar::is_alphanumeric"]
9687
pub fn is_alphanumeric(c: char) -> bool {
97-
is_alphabetic(c)
98-
|| is_digit(c)
88+
c.is_alphanumeric()
9989
}
10090

10191
///
@@ -105,16 +95,14 @@ pub fn is_alphanumeric(c: char) -> bool {
10595
/// 'Cc'.
10696
///
10797
#[inline]
98+
#[deprecated = "use UnicodeChar::is_control"]
10899
pub fn is_control(c: char) -> bool { general_category::Cc(c) }
109100

110101
/// Indicates whether the `char` is numeric (Nd, Nl, or No)
111102
#[inline]
103+
#[deprecated = "use UnicodeChar::is_numeric"]
112104
pub fn is_digit(c: char) -> bool {
113-
match c {
114-
'0' ... '9' => true,
115-
c if c > '\x7f' => general_category::N(c),
116-
_ => false
117-
}
105+
c.is_numeric()
118106
}
119107

120108
/// Convert a char to its uppercase equivalent
@@ -132,6 +120,7 @@ pub fn is_digit(c: char) -> bool {
132120
///
133121
/// Returns the char itself if no conversion was made
134122
#[inline]
123+
#[deprecated = "use UnicodeChar::to_uppercase"]
135124
pub fn to_uppercase(c: char) -> char {
136125
conversions::to_upper(c)
137126
}
@@ -145,6 +134,7 @@ pub fn to_uppercase(c: char) -> char {
145134
///
146135
/// Returns the char itself if no conversion if possible
147136
#[inline]
137+
#[deprecated = "use UnicodeChar::to_lowercase"]
148138
pub fn to_lowercase(c: char) -> char {
149139
conversions::to_lower(c)
150140
}
@@ -158,11 +148,13 @@ pub fn to_lowercase(c: char) -> char {
158148
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
159149
/// recommends that these characters be treated as 1 column (i.e.,
160150
/// `is_cjk` = `false`) if the context cannot be reliably determined.
151+
#[deprecated = "use UnicodeChar::width"]
161152
pub fn width(c: char, is_cjk: bool) -> Option<uint> {
162153
charwidth::width(c, is_cjk)
163154
}
164155

165156
/// Useful functions for Unicode characters.
157+
#[experimental = "pending prelude organization"]
166158
pub trait UnicodeChar {
167159
/// Returns whether the specified character is considered a Unicode
168160
/// alphabetic code point.
@@ -265,29 +257,62 @@ pub trait UnicodeChar {
265257
fn width(self, is_cjk: bool) -> Option<uint>;
266258
}
267259

260+
#[experimental = "pending prelude organization"]
268261
impl UnicodeChar for char {
269-
fn is_alphabetic(self) -> bool { is_alphabetic(self) }
262+
fn is_alphabetic(self) -> bool {
263+
match self {
264+
'a' ... 'z' | 'A' ... 'Z' => true,
265+
c if c > '\x7f' => derived_property::Alphabetic(c),
266+
_ => false
267+
}
268+
}
270269

271-
fn is_XID_start(self) -> bool { is_XID_start(self) }
270+
fn is_XID_start(self) -> bool { derived_property::XID_Start(self) }
272271

273-
fn is_XID_continue(self) -> bool { is_XID_continue(self) }
272+
fn is_XID_continue(self) -> bool { derived_property::XID_Continue(self) }
274273

275-
fn is_lowercase(self) -> bool { is_lowercase(self) }
274+
fn is_lowercase(self) -> bool {
275+
match self {
276+
'a' ... 'z' => true,
277+
c if c > '\x7f' => derived_property::Lowercase(c),
278+
_ => false
279+
}
280+
}
276281

277-
fn is_uppercase(self) -> bool { is_uppercase(self) }
282+
fn is_uppercase(self) -> bool {
283+
match self {
284+
'A' ... 'Z' => true,
285+
c if c > '\x7f' => derived_property::Uppercase(c),
286+
_ => false
287+
}
288+
}
278289

279-
fn is_whitespace(self) -> bool { is_whitespace(self) }
290+
fn is_whitespace(self) -> bool {
291+
match self {
292+
' ' | '\x09' ... '\x0d' => true,
293+
c if c > '\x7f' => property::White_Space(c),
294+
_ => false
295+
}
296+
}
280297

281-
fn is_alphanumeric(self) -> bool { is_alphanumeric(self) }
298+
fn is_alphanumeric(self) -> bool {
299+
self.is_alphabetic() || self.is_numeric()
300+
}
282301

283-
fn is_control(self) -> bool { is_control(self) }
302+
fn is_control(self) -> bool { general_category::Cc(self) }
284303

285-
fn is_numeric(self) -> bool { is_digit(self) }
304+
fn is_numeric(self) -> bool {
305+
match self {
306+
'0' ... '9' => true,
307+
c if c > '\x7f' => general_category::N(c),
308+
_ => false
309+
}
310+
}
286311

287-
fn to_lowercase(self) -> char { to_lowercase(self) }
312+
fn to_lowercase(self) -> char { conversions::to_lower(self) }
288313

289-
fn to_uppercase(self) -> char { to_uppercase(self) }
314+
fn to_uppercase(self) -> char { conversions::to_upper(self) }
290315

291316
#[experimental = "needs expert opinion. is_cjk flag stands out as ugly"]
292-
fn width(self, is_cjk: bool) -> Option<uint> { width(self, is_cjk) }
317+
fn width(self, is_cjk: bool) -> Option<uint> { charwidth::width(self, is_cjk) }
293318
}

src/libunicode/u_str.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ use core::iter::{Filter, AdditiveIterator, Iterator, DoubleEndedIterator};
2323
use core::kinds::Sized;
2424
use core::option::{Option, None, Some};
2525
use core::str::{CharSplits, StrPrelude};
26-
use u_char;
2726
use u_char::UnicodeChar;
2827
use tables::grapheme::GraphemeCat;
2928

3029
/// An iterator over the words of a string, separated by a sequence of whitespace
30+
/// FIXME: This should be opaque
3131
pub type Words<'a> =
32-
Filter<'a, &'a str, CharSplits<'a, extern "Rust" fn(char) -> bool>>;
32+
Filter<'a, &'a str, CharSplits<'a, |char|:'a -> bool>>;
3333

3434
/// Methods for Unicode string slices
3535
pub trait UnicodeStrPrelude for Sized? {
@@ -142,14 +142,15 @@ impl UnicodeStrPrelude for str {
142142

143143
#[inline]
144144
fn words(&self) -> Words {
145-
self.split(u_char::is_whitespace).filter(|s| !s.is_empty())
145+
let f = |c: char| c.is_whitespace();
146+
self.split(f).filter(|s| !s.is_empty())
146147
}
147148

148149
#[inline]
149-
fn is_whitespace(&self) -> bool { self.chars().all(u_char::is_whitespace) }
150+
fn is_whitespace(&self) -> bool { self.chars().all(|c| c.is_whitespace()) }
150151

151152
#[inline]
152-
fn is_alphanumeric(&self) -> bool { self.chars().all(u_char::is_alphanumeric) }
153+
fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) }
153154

154155
#[inline]
155156
fn width(&self, is_cjk: bool) -> uint {
@@ -163,12 +164,12 @@ impl UnicodeStrPrelude for str {
163164

164165
#[inline]
165166
fn trim_left(&self) -> &str {
166-
self.trim_left_chars(u_char::is_whitespace)
167+
self.trim_left_chars(|c: char| c.is_whitespace())
167168
}
168169

169170
#[inline]
170171
fn trim_right(&self) -> &str {
171-
self.trim_right_chars(u_char::is_whitespace)
172+
self.trim_right_chars(|c: char| c.is_whitespace())
172173
}
173174
}
174175

0 commit comments

Comments
 (0)