diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-10 00:34:23 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-10 23:02:54 +1000 |
| commit | b29cd22bce6325a60788ab84f989bd2e82fcaaf4 (patch) | |
| tree | dfa42affe6369b9595b462b4ee15fdaf88ff8b3a /src/libstd/str.rs | |
| parent | 1e8982bdb26208d9d9ed4cdcbcd21cc9ef35bd46 (diff) | |
| download | rust-b29cd22bce6325a60788ab84f989bd2e82fcaaf4.tar.gz rust-b29cd22bce6325a60788ab84f989bd2e82fcaaf4.zip | |
std: replace str::all/any fns and methods with iterators
Diffstat (limited to 'src/libstd/str.rs')
| -rw-r--r-- | src/libstd/str.rs | 52 |
1 files changed, 2 insertions, 50 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 930026fa4f7..09ea6a5dfa9 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1175,22 +1175,6 @@ impl<'self> Equiv<~str> for &'self str { Section: Iterating through strings */ -/** - * Return true if a predicate matches all characters or if the string - * contains no characters - */ -pub fn all(s: &str, it: &fn(char) -> bool) -> bool { - all_between(s, 0u, len(s), it) -} - -/** - * Return true if a predicate matches any character (and false if it - * matches none or there are no characters) - */ -pub fn any(ss: &str, pred: &fn(char) -> bool) -> bool { - !all(ss, |cc| !pred(cc)) -} - /// Apply a function to each character pub fn map(ss: &str, ff: &fn(char) -> char) -> ~str { let mut result = ~""; @@ -1675,7 +1659,7 @@ pub fn is_empty(s: &str) -> bool { len(s) == 0u } * Whitespace characters are determined by `char::is_whitespace` */ pub fn is_whitespace(s: &str) -> bool { - return all(s, char::is_whitespace); + s.iter().all(char::is_whitespace) } /** @@ -1684,7 +1668,7 @@ pub fn is_whitespace(s: &str) -> bool { * Alphanumeric characters are determined by `char::is_alphanumeric` */ fn is_alphanumeric(s: &str) -> bool { - return all(s, char::is_alphanumeric); + s.iter().all(char::is_alphanumeric) } /// Returns the string length/size in bytes not counting the null terminator @@ -2467,8 +2451,6 @@ pub mod traits {} #[allow(missing_doc)] pub trait StrSlice<'self> { - fn all(&self, it: &fn(char) -> bool) -> bool; - fn any(&self, it: &fn(char) -> bool) -> bool; fn contains<'a>(&self, needle: &'a str) -> bool; fn contains_char(&self, needle: char) -> bool; fn iter(&self) -> StrCharIterator<'self>; @@ -2514,18 +2496,6 @@ pub trait StrSlice<'self> { /// Extension methods for strings impl<'self> StrSlice<'self> for &'self str { - /** - * Return true if a predicate matches all characters or if the string - * contains no characters - */ - #[inline] - fn all(&self, it: &fn(char) -> bool) -> bool { all(*self, it) } - /** - * Return true if a predicate matches any character (and false if it - * matches none or there are no characters) - */ - #[inline] - fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) } /// Returns true if one string contains another #[inline] fn contains<'a>(&self, needle: &'a str) -> bool { @@ -3523,24 +3493,6 @@ mod tests { } #[test] - fn test_all() { - assert_eq!(true, all("", char::is_uppercase)); - assert_eq!(false, all("ymca", char::is_uppercase)); - assert_eq!(true, all("YMCA", char::is_uppercase)); - assert_eq!(false, all("yMCA", char::is_uppercase)); - assert_eq!(false, all("YMCy", char::is_uppercase)); - } - - #[test] - fn test_any() { - assert_eq!(false, any("", char::is_uppercase)); - assert_eq!(false, any("ymca", char::is_uppercase)); - assert_eq!(true, any("YMCA", char::is_uppercase)); - assert_eq!(true, any("yMCA", char::is_uppercase)); - assert_eq!(true, any("Ymcy", char::is_uppercase)); - } - - #[test] fn test_chars() { let ss = ~"ศไทย中华Việt Nam"; assert!(~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a', |
