Skip to content

Commit b29cd22

Browse files
committed
std: replace str::all/any fns and methods with iterators
1 parent 1e8982b commit b29cd22

File tree

10 files changed

+15
-60
lines changed

10 files changed

+15
-60
lines changed

src/compiletest/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use core::prelude::*;
1313
use common::config;
1414
use common;
1515

16+
use core::iterator::IteratorUtil;
1617
use core::io;
1718
use core::os;
1819
use core::str;

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
735735
let cmdline = make_cmdline("", args.prog, args.args);
736736

737737
// get bare program string
738-
let tvec: ~[~str] = args.prog.split_iter('/').transform(|ts| ts.to_owned()).collect();
738+
let mut tvec: ~[~str] = args.prog.split_iter('/').transform(|ts| ts.to_owned()).collect();
739739
let prog_short = tvec.pop();
740740

741741
// copy to target

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl Parser {
567567
}
568568

569569
fn parse_ident(&mut self, ident: &str, value: Json) -> Result<Json, Error> {
570-
if str::all(ident, |c| c == self.next_char()) {
570+
if ident.iter().all(|c| c == self.next_char()) {
571571
self.bump();
572572
Ok(value)
573573
} else {

src/libextra/semver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use core::prelude::*;
1616

17+
use core::iterator::IteratorUtil;
1718
use core::char;
1819
use core::cmp;
1920
use core::io::{ReaderUtil};
@@ -168,7 +169,7 @@ fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
168169

169170
fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
170171
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
171-
if s.all(char::is_digit) {
172+
if s.iter().all(char::is_digit) {
172173
match uint::from_str(s) {
173174
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
174175
Some(i) => (Numeric(i), ch)

src/librustdoc/unindent_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn unindent(s: &str) -> ~str {
6363
} else {
6464
saw_first_line = true;
6565
let mut spaces = 0;
66-
do str::all(*line) |char| {
66+
do line.iter().all |char| {
6767
// Only comparing against space because I wouldn't
6868
// know what to do with mixed whitespace chars
6969
if char == ' ' {

src/libstd/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl GenericPath for PosixPath {
508508
}
509509

510510
fn with_filename(&self, f: &str) -> PosixPath {
511-
assert!(! str::any(f, |c| windows::is_sep(c)));
511+
assert!(! f.iter().all(windows::is_sep));
512512
self.dir_path().push(f)
513513
}
514514

@@ -722,7 +722,7 @@ impl GenericPath for WindowsPath {
722722
}
723723

724724
fn with_filename(&self, f: &str) -> WindowsPath {
725-
assert!(! str::any(f, |c| windows::is_sep(c)));
725+
assert!(! f.iter().all(windows::is_sep));
726726
self.dir_path().push(f)
727727
}
728728

src/libstd/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str {
588588
return cmd;
589589

590590
fn append_arg(cmd: &mut ~str, arg: &str) {
591-
let quote = arg.any(|c| c == ' ' || c == '\t');
591+
let quote = arg.iter().any(|c| c == ' ' || c == '\t');
592592
if quote {
593593
cmd.push_char('"');
594594
}

src/libstd/str.rs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,22 +1175,6 @@ impl<'self> Equiv<~str> for &'self str {
11751175
Section: Iterating through strings
11761176
*/
11771177

1178-
/**
1179-
* Return true if a predicate matches all characters or if the string
1180-
* contains no characters
1181-
*/
1182-
pub fn all(s: &str, it: &fn(char) -> bool) -> bool {
1183-
all_between(s, 0u, len(s), it)
1184-
}
1185-
1186-
/**
1187-
* Return true if a predicate matches any character (and false if it
1188-
* matches none or there are no characters)
1189-
*/
1190-
pub fn any(ss: &str, pred: &fn(char) -> bool) -> bool {
1191-
!all(ss, |cc| !pred(cc))
1192-
}
1193-
11941178
/// Apply a function to each character
11951179
pub fn map(ss: &str, ff: &fn(char) -> char) -> ~str {
11961180
let mut result = ~"";
@@ -1675,7 +1659,7 @@ pub fn is_empty(s: &str) -> bool { len(s) == 0u }
16751659
* Whitespace characters are determined by `char::is_whitespace`
16761660
*/
16771661
pub fn is_whitespace(s: &str) -> bool {
1678-
return all(s, char::is_whitespace);
1662+
s.iter().all(char::is_whitespace)
16791663
}
16801664

16811665
/**
@@ -1684,7 +1668,7 @@ pub fn is_whitespace(s: &str) -> bool {
16841668
* Alphanumeric characters are determined by `char::is_alphanumeric`
16851669
*/
16861670
fn is_alphanumeric(s: &str) -> bool {
1687-
return all(s, char::is_alphanumeric);
1671+
s.iter().all(char::is_alphanumeric)
16881672
}
16891673

16901674
/// Returns the string length/size in bytes not counting the null terminator
@@ -2467,8 +2451,6 @@ pub mod traits {}
24672451
24682452
#[allow(missing_doc)]
24692453
pub trait StrSlice<'self> {
2470-
fn all(&self, it: &fn(char) -> bool) -> bool;
2471-
fn any(&self, it: &fn(char) -> bool) -> bool;
24722454
fn contains<'a>(&self, needle: &'a str) -> bool;
24732455
fn contains_char(&self, needle: char) -> bool;
24742456
fn iter(&self) -> StrCharIterator<'self>;
@@ -2514,18 +2496,6 @@ pub trait StrSlice<'self> {
25142496
25152497
/// Extension methods for strings
25162498
impl<'self> StrSlice<'self> for &'self str {
2517-
/**
2518-
* Return true if a predicate matches all characters or if the string
2519-
* contains no characters
2520-
*/
2521-
#[inline]
2522-
fn all(&self, it: &fn(char) -> bool) -> bool { all(*self, it) }
2523-
/**
2524-
* Return true if a predicate matches any character (and false if it
2525-
* matches none or there are no characters)
2526-
*/
2527-
#[inline]
2528-
fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) }
25292499
/// Returns true if one string contains another
25302500
#[inline]
25312501
fn contains<'a>(&self, needle: &'a str) -> bool {
@@ -3522,24 +3492,6 @@ mod tests {
35223492
assert_eq!(~"YMCA", map("ymca", |c| unsafe {libc::toupper(c as c_char)} as char));
35233493
}
35243494
3525-
#[test]
3526-
fn test_all() {
3527-
assert_eq!(true, all("", char::is_uppercase));
3528-
assert_eq!(false, all("ymca", char::is_uppercase));
3529-
assert_eq!(true, all("YMCA", char::is_uppercase));
3530-
assert_eq!(false, all("yMCA", char::is_uppercase));
3531-
assert_eq!(false, all("YMCy", char::is_uppercase));
3532-
}
3533-
3534-
#[test]
3535-
fn test_any() {
3536-
assert_eq!(false, any("", char::is_uppercase));
3537-
assert_eq!(false, any("ymca", char::is_uppercase));
3538-
assert_eq!(true, any("YMCA", char::is_uppercase));
3539-
assert_eq!(true, any("yMCA", char::is_uppercase));
3540-
assert_eq!(true, any("Ymcy", char::is_uppercase));
3541-
}
3542-
35433495
#[test]
35443496
fn test_chars() {
35453497
let ss = ~"ศไทย中华Việt Nam";

src/libstd/str/ascii.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ mod tests {
226226
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
227227
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
228228

229-
assert!(str::all("banana", |c| c.is_ascii()));
230-
assert!(! str::all("ประเทศไทย中华Việt Nam", |c| c.is_ascii()));
229+
assert!("banana".iter().all(|c| c.is_ascii()));
230+
assert!(!"ประเทศไทย中华Việt Nam".iter().all(|c| c.is_ascii()));
231231
}
232232

233233
#[test]

src/libsyntax/parse/lexer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use ext::tt::transcribe::{dup_tt_reader};
1919
use parse::token;
2020
use parse::token::{str_to_ident};
2121

22+
use core::iterator::IteratorUtil;
2223
use core::char;
2324
use core::either;
2425
use core::str;
@@ -245,7 +246,7 @@ fn consume_whitespace_and_comments(rdr: @mut StringReader)
245246

246247
pub fn is_line_non_doc_comment(s: &str) -> bool {
247248
let s = s.trim_right();
248-
s.len() > 3 && s.all(|ch| ch == '/')
249+
s.len() > 3 && s.iter().all(|ch| ch == '/')
249250
}
250251

251252
// PRECONDITION: rdr.curr is not whitespace

0 commit comments

Comments
 (0)