pub use self::Flag::*;
pub use self::Count::*;
-use std::char;
use std::str;
use std::string;
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 }
}
}
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
/// 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
}
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 }
/// 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
/// [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
/// [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) }
///
/// 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()
}
///
/// 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()
}
///
/// 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()
}
///
/// '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()
}
///
/// '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
///
/// 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)
}
///
/// 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)
}
/// [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<uint> {
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.
fn width(self, is_cjk: bool) -> Option<uint>;
}
+#[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<uint> { width(self, is_cjk) }
+ fn width(self, is_cjk: bool) -> Option<uint> { charwidth::width(self, is_cjk) }
}
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? {
#[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 {
#[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())
}
}