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 | |
| 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')
| -rw-r--r-- | src/libstd/path.rs | 4 | ||||
| -rw-r--r-- | src/libstd/run.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 52 | ||||
| -rw-r--r-- | src/libstd/str/ascii.rs | 4 |
4 files changed, 7 insertions, 55 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b2f25d41157..eb78120c6be 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -508,7 +508,7 @@ impl GenericPath for PosixPath { } fn with_filename(&self, f: &str) -> PosixPath { - assert!(! str::any(f, |c| windows::is_sep(c))); + assert!(! f.iter().all(windows::is_sep)); self.dir_path().push(f) } @@ -722,7 +722,7 @@ impl GenericPath for WindowsPath { } fn with_filename(&self, f: &str) -> WindowsPath { - assert!(! str::any(f, |c| windows::is_sep(c))); + assert!(! f.iter().all(windows::is_sep)); self.dir_path().push(f) } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 3b17067feba..29598bc48fa 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -588,7 +588,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str { return cmd; fn append_arg(cmd: &mut ~str, arg: &str) { - let quote = arg.any(|c| c == ' ' || c == '\t'); + let quote = arg.iter().any(|c| c == ' ' || c == '\t'); if quote { cmd.push_char('"'); } 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', diff --git a/src/libstd/str/ascii.rs b/src/libstd/str/ascii.rs index e288d605714..a4a1b7a171d 100644 --- a/src/libstd/str/ascii.rs +++ b/src/libstd/str/ascii.rs @@ -226,8 +226,8 @@ mod tests { assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); - assert!(str::all("banana", |c| c.is_ascii())); - assert!(! str::all("ประเทศไทย中华Việt Nam", |c| c.is_ascii())); + assert!("banana".iter().all(|c| c.is_ascii())); + assert!(!"ประเทศไทย中华Việt Nam".iter().all(|c| c.is_ascii())); } #[test] |
