diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 134819ad02757..ed86ad52bb5d4 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -26,7 +26,6 @@ pub use self::Alignment::*; pub use self::Flag::*; pub use self::Count::*; -use std::char; use std::str; use std::string; @@ -221,7 +220,7 @@ impl<'a> Parser<'a> { fn ws(&mut self) { loop { match self.cur.clone().next() { - Some((_, c)) if char::is_whitespace(c) => { self.cur.next(); } + Some((_, c)) if c.is_whitespace() => { self.cur.next(); } Some(..) | None => { return } } } @@ -261,7 +260,7 @@ impl<'a> Parser<'a> { Some(i) => { ArgumentIs(i) } None => { match self.cur.clone().next() { - Some((_, c)) if char::is_alphabetic(c) => { + Some((_, c)) if c.is_alphabetic() => { ArgumentNamed(self.word()) } _ => ArgumentNext @@ -384,7 +383,7 @@ impl<'a> Parser<'a> { /// characters. fn word(&mut self) -> &'a str { let start = match self.cur.clone().next() { - Some((pos, c)) if char::is_XID_start(c) => { + Some((pos, c)) if c.is_XID_start() => { self.cur.next(); pos } @@ -393,7 +392,7 @@ impl<'a> Parser<'a> { let mut end; loop { match self.cur.clone().next() { - Some((_, c)) if char::is_XID_continue(c) => { + Some((_, c)) if c.is_XID_continue() => { self.cur.next(); } Some((pos, _)) => { end = pos; break } diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index c4d712cb67362..a182f582b5f34 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -886,7 +886,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) } let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| { - let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr }; + let whitespace = if c.is_whitespace() { Ws } else { Cr }; let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; state = match (state, whitespace, limit) { diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 6a8074b99585c..db9ebac163c73 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -27,7 +27,6 @@ use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; -use std::char; use std::io::fs::PathExtensions; use std::io::{fs, TempDir, Command}; use std::io; @@ -272,7 +271,7 @@ pub fn sanitize(s: &str) -> String { // Underscore-qualify anything that didn't start as an ident. if result.len() > 0u && result.as_bytes()[0] != '_' as u8 && - ! char::is_XID_start(result.as_bytes()[0] as char) { + ! (result.as_bytes()[0] as char).is_XID_start() { return format!("_{}", result.as_slice()); } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2dc1bcf776eb8..63007cf15c651 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -9,7 +9,6 @@ // except according to those terms. use std::cell::RefCell; -use std::char; use std::dynamic_lib::DynamicLibrary; use std::io::{Command, TempDir}; use std::io; @@ -300,8 +299,8 @@ impl Collector { // we use these headings as test names, so it's good if // they're valid identifiers. let name = name.chars().enumerate().map(|(i, c)| { - if (i == 0 && char::is_XID_start(c)) || - (i != 0 && char::is_XID_continue(c)) { + if (i == 0 && c.is_XID_start()) || + (i != 0 && c.is_XID_continue()) { c } else { '_' diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 4c759cfc4fd0a..9b3e25c5851c9 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1385,7 +1385,7 @@ fn ident_start(c: Option) -> bool { (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' - || (c > '\x7f' && char::is_XID_start(c)) + || (c > '\x7f' && c.is_XID_start()) } fn ident_continue(c: Option) -> bool { @@ -1395,7 +1395,7 @@ fn ident_continue(c: Option) -> bool { || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' - || (c > '\x7f' && char::is_XID_continue(c)) + || (c > '\x7f' && c.is_XID_continue()) } #[cfg(test)] diff --git a/src/libunicode/u_char.rs b/src/libunicode/u_char.rs index 1e81916a2c6e0..f347ab6a21e22 100644 --- a/src/libunicode/u_char.rs +++ b/src/libunicode/u_char.rs @@ -20,12 +20,9 @@ use tables::{derived_property, property, general_category, conversions, charwidt /// Returns whether the specified `char` is considered a Unicode alphabetic /// code point +#[deprecated = "use UnicodeChar::is_alphabetic"] pub fn is_alphabetic(c: char) -> bool { - match c { - 'a' ... 'z' | 'A' ... 'Z' => true, - c if c > '\x7f' => derived_property::Alphabetic(c), - _ => false - } + c.is_alphabetic() } /// Returns whether the specified `char` satisfies the 'XID_Start' Unicode property @@ -34,6 +31,7 @@ pub fn is_alphabetic(c: char) -> bool { /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. #[allow(non_snake_case)] +#[deprecated = "use UnicodeChar::is_XID_start"] pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) } /// 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) } /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. #[allow(non_snake_case)] +#[deprecated = "use UnicodeChar::is_XID_continue"] pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) } /// @@ -50,12 +49,9 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) } /// This is defined according to the terms of the Unicode Derived Core Property 'Lowercase'. /// #[inline] +#[deprecated = "use UnicodeChar::is_lowercase"] pub fn is_lowercase(c: char) -> bool { - match c { - 'a' ... 'z' => true, - c if c > '\x7f' => derived_property::Lowercase(c), - _ => false - } + c.is_lowercase() } /// @@ -64,12 +60,9 @@ pub fn is_lowercase(c: char) -> bool { /// This is defined according to the terms of the Unicode Derived Core Property 'Uppercase'. /// #[inline] +#[deprecated = "use UnicodeChar::is_uppercase"] pub fn is_uppercase(c: char) -> bool { - match c { - 'A' ... 'Z' => true, - c if c > '\x7f' => derived_property::Uppercase(c), - _ => false - } + c.is_uppercase() } /// @@ -78,12 +71,9 @@ pub fn is_uppercase(c: char) -> bool { /// Whitespace is defined in terms of the Unicode Property 'White_Space'. /// #[inline] +#[deprecated = "use UnicodeChar::is_whitespace"] pub fn is_whitespace(c: char) -> bool { - match c { - ' ' | '\x09' ... '\x0d' => true, - c if c > '\x7f' => property::White_Space(c), - _ => false - } + c.is_whitespace() } /// @@ -93,9 +83,9 @@ pub fn is_whitespace(c: char) -> bool { /// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'. /// #[inline] +#[deprecated = "use UnicodeChar::is_alphanumeric"] pub fn is_alphanumeric(c: char) -> bool { - is_alphabetic(c) - || is_digit(c) + c.is_alphanumeric() } /// @@ -105,16 +95,14 @@ pub fn is_alphanumeric(c: char) -> bool { /// 'Cc'. /// #[inline] +#[deprecated = "use UnicodeChar::is_control"] pub fn is_control(c: char) -> bool { general_category::Cc(c) } /// Indicates whether the `char` is numeric (Nd, Nl, or No) #[inline] +#[deprecated = "use UnicodeChar::is_numeric"] pub fn is_digit(c: char) -> bool { - match c { - '0' ... '9' => true, - c if c > '\x7f' => general_category::N(c), - _ => false - } + c.is_numeric() } /// Convert a char to its uppercase equivalent @@ -132,6 +120,7 @@ pub fn is_digit(c: char) -> bool { /// /// Returns the char itself if no conversion was made #[inline] +#[deprecated = "use UnicodeChar::to_uppercase"] pub fn to_uppercase(c: char) -> char { conversions::to_upper(c) } @@ -145,6 +134,7 @@ pub fn to_uppercase(c: char) -> char { /// /// Returns the char itself if no conversion if possible #[inline] +#[deprecated = "use UnicodeChar::to_lowercase"] pub fn to_lowercase(c: char) -> char { conversions::to_lower(c) } @@ -158,11 +148,13 @@ pub fn to_lowercase(c: char) -> char { /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) /// recommends that these characters be treated as 1 column (i.e., /// `is_cjk` = `false`) if the context cannot be reliably determined. +#[deprecated = "use UnicodeChar::width"] pub fn width(c: char, is_cjk: bool) -> Option { charwidth::width(c, is_cjk) } /// Useful functions for Unicode characters. +#[experimental = "pending prelude organization"] pub trait UnicodeChar { /// Returns whether the specified character is considered a Unicode /// alphabetic code point. @@ -265,29 +257,62 @@ pub trait UnicodeChar { fn width(self, is_cjk: bool) -> Option; } +#[experimental = "pending prelude organization"] impl UnicodeChar for char { - fn is_alphabetic(self) -> bool { is_alphabetic(self) } + fn is_alphabetic(self) -> bool { + match self { + 'a' ... 'z' | 'A' ... 'Z' => true, + c if c > '\x7f' => derived_property::Alphabetic(c), + _ => false + } + } - fn is_XID_start(self) -> bool { is_XID_start(self) } + fn is_XID_start(self) -> bool { derived_property::XID_Start(self) } - fn is_XID_continue(self) -> bool { is_XID_continue(self) } + fn is_XID_continue(self) -> bool { derived_property::XID_Continue(self) } - fn is_lowercase(self) -> bool { is_lowercase(self) } + fn is_lowercase(self) -> bool { + match self { + 'a' ... 'z' => true, + c if c > '\x7f' => derived_property::Lowercase(c), + _ => false + } + } - fn is_uppercase(self) -> bool { is_uppercase(self) } + fn is_uppercase(self) -> bool { + match self { + 'A' ... 'Z' => true, + c if c > '\x7f' => derived_property::Uppercase(c), + _ => false + } + } - fn is_whitespace(self) -> bool { is_whitespace(self) } + fn is_whitespace(self) -> bool { + match self { + ' ' | '\x09' ... '\x0d' => true, + c if c > '\x7f' => property::White_Space(c), + _ => false + } + } - fn is_alphanumeric(self) -> bool { is_alphanumeric(self) } + fn is_alphanumeric(self) -> bool { + self.is_alphabetic() || self.is_numeric() + } - fn is_control(self) -> bool { is_control(self) } + fn is_control(self) -> bool { general_category::Cc(self) } - fn is_numeric(self) -> bool { is_digit(self) } + fn is_numeric(self) -> bool { + match self { + '0' ... '9' => true, + c if c > '\x7f' => general_category::N(c), + _ => false + } + } - fn to_lowercase(self) -> char { to_lowercase(self) } + fn to_lowercase(self) -> char { conversions::to_lower(self) } - fn to_uppercase(self) -> char { to_uppercase(self) } + fn to_uppercase(self) -> char { conversions::to_upper(self) } #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"] - fn width(self, is_cjk: bool) -> Option { width(self, is_cjk) } + fn width(self, is_cjk: bool) -> Option { charwidth::width(self, is_cjk) } } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 99c1ce503cc4d..56b1f0907d5a4 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -24,13 +24,13 @@ use core::iter::{Filter, AdditiveIterator, Iterator, DoubleEndedIterator}; use core::kinds::Sized; use core::option::{Option, None, Some}; use core::str::{CharSplits, StrPrelude}; -use u_char; use u_char::UnicodeChar; use tables::grapheme::GraphemeCat; /// An iterator over the words of a string, separated by a sequence of whitespace +/// FIXME: This should be opaque pub type Words<'a> = - Filter<'a, &'a str, CharSplits<'a, extern "Rust" fn(char) -> bool>>; + Filter<'a, &'a str, CharSplits<'a, |char|:'a -> bool>>; /// Methods for Unicode string slices pub trait UnicodeStrPrelude for Sized? { @@ -143,14 +143,15 @@ impl UnicodeStrPrelude for str { #[inline] fn words(&self) -> Words { - self.split(u_char::is_whitespace).filter(|s| !s.is_empty()) + let f = |c: char| c.is_whitespace(); + self.split(f).filter(|s| !s.is_empty()) } #[inline] - fn is_whitespace(&self) -> bool { self.chars().all(u_char::is_whitespace) } + fn is_whitespace(&self) -> bool { self.chars().all(|c| c.is_whitespace()) } #[inline] - fn is_alphanumeric(&self) -> bool { self.chars().all(u_char::is_alphanumeric) } + fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) } #[inline] fn width(&self, is_cjk: bool) -> uint { @@ -164,12 +165,12 @@ impl UnicodeStrPrelude for str { #[inline] fn trim_left(&self) -> &str { - self.trim_left_chars(u_char::is_whitespace) + self.trim_left_chars(|c: char| c.is_whitespace()) } #[inline] fn trim_right(&self) -> &str { - self.trim_right_chars(u_char::is_whitespace) + self.trim_right_chars(|c: char| c.is_whitespace()) } }