mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-06 20:13:42 +00:00
unicode: Rename UnicodeChar::is_digit to is_numeric
'Numeric' is the proper name of the unicode character class, and this frees up the word 'digit' for ascii use in libcore. Since I'm going to rename `Char::is_digit_radix` to `is_digit`, I am not leaving a deprecated method in place, because that would just cause name clashes, as both `Char` and `UnicodeChar` are in the prelude. [breaking-change]
This commit is contained in:
parent
ac2f379abb
commit
c2aff692fa
@ -1566,7 +1566,7 @@ fn _arm_exec_compiled_test(config: &Config,
|
||||
|
||||
let mut exitcode: int = 0;
|
||||
for c in exitcode_out.as_slice().chars() {
|
||||
if !c.is_digit() { break; }
|
||||
if !c.is_numeric() { break; }
|
||||
exitcode = exitcode * 10 + match c {
|
||||
'0' ... '9' => c as int - ('0' as int),
|
||||
_ => 101,
|
||||
|
@ -1189,7 +1189,7 @@ mod tests {
|
||||
assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11");
|
||||
let chars: &[char] = &['1', '2'];
|
||||
assert_eq!("12foo1bar12".trim_left_chars(chars), "foo1bar12");
|
||||
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123");
|
||||
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1204,7 +1204,7 @@ mod tests {
|
||||
assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar");
|
||||
let chars: &[char] = &['1', '2'];
|
||||
assert_eq!("12foo1bar12".trim_right_chars(chars), "12foo1bar");
|
||||
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar");
|
||||
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1219,7 +1219,7 @@ mod tests {
|
||||
assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar");
|
||||
let chars: &[char] = &['1', '2'];
|
||||
assert_eq!("12foo1bar12".trim_chars(chars), "foo1bar");
|
||||
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar");
|
||||
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1315,7 +1315,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// let v: Vec<&str> = "Mary had a little lamb".split(' ').collect();
|
||||
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).collect();
|
||||
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_numeric()).collect();
|
||||
/// assert_eq!(v, vec!["abc", "def", "ghi"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect();
|
||||
@ -1336,7 +1336,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect();
|
||||
/// assert_eq!(v, vec!["Mary", "had", "a little lambda"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_digit()).collect();
|
||||
/// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_numeric()).collect();
|
||||
/// assert_eq!(v, vec!["abc", "def2ghi"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect();
|
||||
@ -1368,7 +1368,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// let v: Vec<&str> = "Mary had a little lamb".split(' ').rev().collect();
|
||||
/// assert_eq!(v, vec!["lamb", "little", "a", "had", "Mary"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).rev().collect();
|
||||
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_numeric()).rev().collect();
|
||||
/// assert_eq!(v, vec!["ghi", "def", "abc"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
|
||||
@ -1386,7 +1386,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect();
|
||||
/// assert_eq!(v, vec!["lamb", "little", "Mary had a"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_digit()).collect();
|
||||
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_numeric()).collect();
|
||||
/// assert_eq!(v, vec!["ghi", "abc1def"]);
|
||||
///
|
||||
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
|
||||
@ -1596,7 +1596,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar")
|
||||
/// let x: &[_] = &['1', '2'];
|
||||
/// assert_eq!("12foo1bar12".trim_chars(x), "foo1bar")
|
||||
/// assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar")
|
||||
/// assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar")
|
||||
/// ```
|
||||
fn trim_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str;
|
||||
|
||||
@ -1612,7 +1612,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11")
|
||||
/// let x: &[_] = &['1', '2'];
|
||||
/// assert_eq!("12foo1bar12".trim_left_chars(x), "foo1bar12")
|
||||
/// assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123")
|
||||
/// assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123")
|
||||
/// ```
|
||||
fn trim_left_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str;
|
||||
|
||||
@ -1628,7 +1628,7 @@ pub trait StrPrelude for Sized? {
|
||||
/// assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar")
|
||||
/// let x: &[_] = &['1', '2'];
|
||||
/// assert_eq!("12foo1bar12".trim_right_chars(x), "12foo1bar")
|
||||
/// assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar")
|
||||
/// assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar")
|
||||
/// ```
|
||||
fn trim_right_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str;
|
||||
|
||||
|
@ -105,12 +105,12 @@ fn test_is_control() {
|
||||
|
||||
#[test]
|
||||
fn test_is_digit() {
|
||||
assert!('2'.is_digit());
|
||||
assert!('7'.is_digit());
|
||||
assert!(!'c'.is_digit());
|
||||
assert!(!'i'.is_digit());
|
||||
assert!(!'z'.is_digit());
|
||||
assert!(!'Q'.is_digit());
|
||||
assert!('2'.is_numeric());
|
||||
assert!('7'.is_numeric());
|
||||
assert!(!'c'.is_numeric());
|
||||
assert!(!'i'.is_numeric());
|
||||
assert!(!'z'.is_numeric());
|
||||
assert!(!'Q'.is_numeric());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -920,7 +920,7 @@ impl NonSnakeCase {
|
||||
let mut allow_underscore = true;
|
||||
ident.chars().all(|c| {
|
||||
allow_underscore = match c {
|
||||
c if c.is_lowercase() || c.is_digit() => true,
|
||||
c if c.is_lowercase() || c.is_numeric() => true,
|
||||
'_' if allow_underscore => false,
|
||||
_ => return false,
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
|
||||
while valid {
|
||||
let mut i = 0;
|
||||
for c in chars {
|
||||
if c.is_digit() {
|
||||
if c.is_numeric() {
|
||||
i = i * 10 + c as uint - '0' as uint;
|
||||
} else {
|
||||
break
|
||||
@ -101,7 +101,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
|
||||
first = false;
|
||||
}
|
||||
let mut rest = s;
|
||||
while rest.char_at(0).is_digit() {
|
||||
while rest.char_at(0).is_numeric() {
|
||||
rest = rest.slice_from(1);
|
||||
}
|
||||
let i: uint = from_str(s.slice_to(s.len() - rest.len())).unwrap();
|
||||
|
@ -217,7 +217,7 @@ pub trait UnicodeChar {
|
||||
fn is_control(&self) -> bool;
|
||||
|
||||
/// Indicates whether the character is numeric (Nd, Nl, or No).
|
||||
fn is_digit(&self) -> bool;
|
||||
fn is_numeric(&self) -> bool;
|
||||
|
||||
/// Converts a character to its lowercase equivalent.
|
||||
///
|
||||
@ -281,7 +281,7 @@ impl UnicodeChar for char {
|
||||
|
||||
fn is_control(&self) -> bool { is_control(*self) }
|
||||
|
||||
fn is_digit(&self) -> bool { is_digit(*self) }
|
||||
fn is_numeric(&self) -> bool { is_digit(*self) }
|
||||
|
||||
fn to_lowercase(&self) -> char { to_lowercase(*self) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user