diff options
| author | Marvin Löbel <loebel.marvin@gmail.com> | 2013-11-23 11:18:51 +0100 |
|---|---|---|
| committer | Marvin Löbel <loebel.marvin@gmail.com> | 2013-11-26 10:02:26 +0100 |
| commit | 24b316a3b9567cb2cc2fb6644bd891dbf8855c18 (patch) | |
| tree | 567d9df8a078d09fc610ea3e0b301f5cb6fb63d8 /src/libstd | |
| parent | b42c4388927db75f9a38edbeafbfe13775b1773d (diff) | |
| download | rust-24b316a3b9567cb2cc2fb6644bd891dbf8855c18.tar.gz rust-24b316a3b9567cb2cc2fb6644bd891dbf8855c18.zip | |
Removed unneccessary `_iter` suffixes from various APIs
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 8 | ||||
| -rw-r--r-- | src/libstd/fmt/parse.rs | 2 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 20 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/native/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 66 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 66 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/logging.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 338 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 36 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 125 |
16 files changed, 342 insertions, 337 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index fb1cb26ec5d..5d4f6ee1121 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -180,7 +180,7 @@ impl<'self> AsciiCast<&'self [Ascii]> for &'self str { #[inline] fn is_ascii(&self) -> bool { - self.byte_iter().all(|b| b.is_ascii()) + self.bytes().all(|b| b.is_ascii()) } } @@ -394,7 +394,7 @@ unsafe fn str_map_bytes(string: ~str, map: &'static [u8]) -> ~str { #[inline] unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> ~str { - let bytes = string.byte_iter().map(|b| map[b]).to_owned_vec(); + let bytes = string.bytes().map(|b| map[b]).to_owned_vec(); str::raw::from_utf8_owned(bytes) } @@ -498,8 +498,8 @@ mod tests { assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); - assert!("banana".iter().all(|c| c.is_ascii())); - assert!(!"ประเทศไทย中华Việt Nam".iter().all(|c| c.is_ascii())); + assert!("banana".chars().all(|c| c.is_ascii())); + assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii())); } #[test] diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 401ddfe67f5..885fe75fb9f 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -196,7 +196,7 @@ impl<'self> Parser<'self> { pub fn new<'a>(s: &'a str) -> Parser<'a> { Parser { input: s, - cur: s.char_offset_iter(), + cur: s.char_indices(), depth: 0, } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 50aa9289838..0bc1aa89353 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -736,7 +736,7 @@ impl<T:Hash + Eq> HashSet<T> { } /// Visit the values representing the difference - pub fn difference_iter<'a>(&'a self, other: &'a HashSet<T>) -> SetAlgebraIter<'a, T> { + pub fn difference<'a>(&'a self, other: &'a HashSet<T>) -> SetAlgebraIter<'a, T> { Repeat::new(other) .zip(self.iter()) .filter_map(|(other, elt)| { @@ -745,13 +745,13 @@ impl<T:Hash + Eq> HashSet<T> { } /// Visit the values representing the symmetric difference - pub fn symmetric_difference_iter<'a>(&'a self, other: &'a HashSet<T>) + pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T>) -> Chain<SetAlgebraIter<'a, T>, SetAlgebraIter<'a, T>> { - self.difference_iter(other).chain(other.difference_iter(self)) + self.difference(other).chain(other.difference(self)) } /// Visit the values representing the intersection - pub fn intersection_iter<'a>(&'a self, other: &'a HashSet<T>) + pub fn intersection<'a>(&'a self, other: &'a HashSet<T>) -> SetAlgebraIter<'a, T> { Repeat::new(other) .zip(self.iter()) @@ -761,9 +761,9 @@ impl<T:Hash + Eq> HashSet<T> { } /// Visit the values representing the union - pub fn union_iter<'a>(&'a self, other: &'a HashSet<T>) + pub fn union<'a>(&'a self, other: &'a HashSet<T>) -> Chain<HashSetIterator<'a, T>, SetAlgebraIter<'a, T>> { - self.iter().chain(other.difference_iter(self)) + self.iter().chain(other.difference(self)) } } @@ -1114,7 +1114,7 @@ mod test_set { let mut i = 0; let expected = [3, 5, 11, 77]; - for x in a.intersection_iter(&b) { + for x in a.intersection(&b) { assert!(expected.contains(x)); i += 1 } @@ -1137,7 +1137,7 @@ mod test_set { let mut i = 0; let expected = [1, 5, 11]; - for x in a.difference_iter(&b) { + for x in a.difference(&b) { assert!(expected.contains(x)); i += 1 } @@ -1163,7 +1163,7 @@ mod test_set { let mut i = 0; let expected = [-2, 1, 5, 11, 14, 22]; - for x in a.symmetric_difference_iter(&b) { + for x in a.symmetric_difference(&b) { assert!(expected.contains(x)); i += 1 } @@ -1193,7 +1193,7 @@ mod test_set { let mut i = 0; let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]; - for x in a.union_iter(&b) { + for x in a.union(&b) { assert!(expected.contains(x)); i += 1 } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 1d0fef48890..8f66215105a 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -46,7 +46,7 @@ Some examples of obvious things you might want to do * Pull the lines of a file into a vector of strings - let lines = File::open("message.txt").line_iter().to_vec(); + let lines = File::open("message.txt").lines().to_vec(); * Make an simple HTTP request diff --git a/src/libstd/io/native/process.rs b/src/libstd/io/native/process.rs index 292b0a2e78f..6f726d1a45e 100644 --- a/src/libstd/io/native/process.rs +++ b/src/libstd/io/native/process.rs @@ -315,7 +315,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str { return cmd; fn append_arg(cmd: &mut ~str, arg: &str) { - let quote = arg.iter().any(|c| c == ' ' || c == '\t'); + let quote = arg.chars().any(|c| c == ' ' || c == '\t'); if quote { cmd.push_char('"'); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3692bc303fb..f4576499652 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -200,7 +200,7 @@ pub fn env() -> ~[(~str,~str)] { fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] { let mut pairs = ~[]; for p in input.iter() { - let vs: ~[&str] = p.splitn_iter('=', 1).collect(); + let vs: ~[&str] = p.splitn('=', 1).collect(); debug!("splitting: len: {}", vs.len()); assert_eq!(vs.len(), 2); pairs.push((vs[0].to_owned(), vs[1].to_owned())); diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 6f152fa2a41..f58db55d4c5 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -20,7 +20,7 @@ appropriate platform-specific path variant. Both `PosixPath` and `WindowsPath` implement a trait `GenericPath`, which contains the set of methods that behave the same for both paths. They each also implement some methods that could not be expressed in `GenericPath`, yet behave -identically for both path flavors, such as `.component_iter()`. +identically for both path flavors, such as `.components()`. The three main design goals of this module are 1) to avoid unnecessary allocation, 2) to behave the same regardless of which flavor of path is being diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 37329a3cfbd..dcd08295331 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -233,8 +233,8 @@ impl GenericPath for Path { if self.is_absolute() != other.is_absolute() { false } else { - let mut ita = self.component_iter(); - let mut itb = other.component_iter(); + let mut ita = self.components(); + let mut itb = other.components(); if bytes!(".") == self.repr { return itb.next() != Some(bytes!("..")); } @@ -261,8 +261,8 @@ impl GenericPath for Path { None } } else { - let mut ita = self.component_iter(); - let mut itb = base.component_iter(); + let mut ita = self.components(); + let mut itb = base.components(); let mut comps = ~[]; loop { match (ita.next(), itb.next()) { @@ -293,8 +293,8 @@ impl GenericPath for Path { fn ends_with_path(&self, child: &Path) -> bool { if !child.is_relative() { return false; } - let mut selfit = self.rev_component_iter(); - let mut childit = child.rev_component_iter(); + let mut selfit = self.rev_components(); + let mut childit = child.rev_components(); loop { match (selfit.next(), childit.next()) { (Some(a), Some(b)) => if a != b { return false; }, @@ -367,11 +367,11 @@ impl Path { /// Does not distinguish between absolute and relative paths, e.g. /// /a/b/c and a/b/c yield the same set of components. /// A path of "/" yields no components. A path of "." yields one component. - pub fn component_iter<'a>(&'a self) -> ComponentIter<'a> { + pub fn components<'a>(&'a self) -> ComponentIter<'a> { let v = if self.repr[0] == sep_byte { self.repr.slice_from(1) } else { self.repr.as_slice() }; - let mut ret = v.split_iter(is_sep_byte); + let mut ret = v.split(is_sep_byte); if v.is_empty() { // consume the empty "" component ret.next(); @@ -380,12 +380,12 @@ impl Path { } /// Returns an iterator that yields each component of the path in reverse. - /// See component_iter() for details. - pub fn rev_component_iter<'a>(&'a self) -> RevComponentIter<'a> { + /// See components() for details. + pub fn rev_components<'a>(&'a self) -> RevComponentIter<'a> { let v = if self.repr[0] == sep_byte { self.repr.slice_from(1) } else { self.repr.as_slice() }; - let mut ret = v.rsplit_iter(is_sep_byte); + let mut ret = v.rsplit(is_sep_byte); if v.is_empty() { // consume the empty "" component ret.next(); @@ -394,15 +394,15 @@ impl Path { } /// Returns an iterator that yields each component of the path as Option<&str>. - /// See component_iter() for details. - pub fn str_component_iter<'a>(&'a self) -> StrComponentIter<'a> { - self.component_iter().map(str::from_utf8_slice_opt) + /// See components() for details. + pub fn str_components<'a>(&'a self) -> StrComponentIter<'a> { + self.components().map(str::from_utf8_slice_opt) } /// Returns an iterator that yields each component of the path in reverse as Option<&str>. - /// See component_iter() for details. - pub fn rev_str_component_iter<'a>(&'a self) -> RevStrComponentIter<'a> { - self.rev_component_iter().map(str::from_utf8_slice_opt) + /// See components() for details. + pub fn rev_str_components<'a>(&'a self) -> RevStrComponentIter<'a> { + self.rev_components().map(str::from_utf8_slice_opt) } } @@ -414,7 +414,7 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<~[&'a [u8]]> { let mut comps: ~[&'a [u8]] = ~[]; let mut n_up = 0u; let mut changed = false; - for comp in v.split_iter(is_sep_byte) { + for comp in v.split(is_sep_byte) { if comp.is_empty() { changed = true } else if comp == bytes!(".") { changed = true } else if comp == bytes!("..") { @@ -1245,33 +1245,33 @@ mod tests { } #[test] - fn test_component_iter() { + fn test_components_iter() { macro_rules! t( (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); - let comps = path.component_iter().to_owned_vec(); + let comps = path.components().to_owned_vec(); let exp: &[&str] = $exp; let exps = exp.iter().map(|x| x.as_bytes()).to_owned_vec(); - assert!(comps == exps, "component_iter: Expected {:?}, found {:?}", + assert!(comps == exps, "components: Expected {:?}, found {:?}", comps, exps); - let comps = path.rev_component_iter().to_owned_vec(); + let comps = path.rev_components().to_owned_vec(); let exps = exps.move_rev_iter().to_owned_vec(); - assert!(comps == exps, "rev_component_iter: Expected {:?}, found {:?}", + assert!(comps == exps, "rev_components: Expected {:?}, found {:?}", comps, exps); } ); (v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.component_iter().to_owned_vec(); + let comps = path.components().to_owned_vec(); let exp: &[&[u8]] = [$(b!($($exp),*)),*]; - assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}", + assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", comps.as_slice(), exp); - let comps = path.rev_component_iter().to_owned_vec(); + let comps = path.rev_components().to_owned_vec(); let exp = exp.rev_iter().map(|&x|x).to_owned_vec(); assert!(comps.as_slice() == exp, - "rev_component_iter: Expected {:?}, found {:?}", + "rev_components: Expected {:?}, found {:?}", comps.as_slice(), exp); } ) @@ -1294,20 +1294,20 @@ mod tests { } #[test] - fn test_str_component_iter() { + fn test_str_components() { macro_rules! t( (v: [$($arg:expr),+], $exp:expr) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.str_component_iter().to_owned_vec(); + let comps = path.str_components().to_owned_vec(); let exp: &[Option<&str>] = $exp; assert!(comps.as_slice() == exp, - "str_component_iter: Expected {:?}, found {:?}", + "str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); - let comps = path.rev_str_component_iter().to_owned_vec(); + let comps = path.rev_str_components().to_owned_vec(); let exp = exp.rev_iter().map(|&x|x).to_owned_vec(); assert!(comps.as_slice() == exp, - "rev_str_component_iter: Expected {:?}, found {:?}", + "rev_str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); } ) @@ -1316,7 +1316,7 @@ mod tests { t!(v: ["a/b/c"], [Some("a"), Some("b"), Some("c")]); t!(v: ["/", 0xff, "/a/", 0x80], [None, Some("a"), None]); t!(v: ["../../foo", 0xcd, "bar"], [Some(".."), Some(".."), None]); - // str_component_iter is a wrapper around component_iter, so no need to do + // str_components is a wrapper around components, so no need to do // the full set of tests } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 4ee490a303b..4e736458fd8 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -472,8 +472,8 @@ impl GenericPath for Path { is_vol_relative(self) != is_vol_relative(other) { false } else { - let mut ita = self.str_component_iter().map(|x|x.unwrap()); - let mut itb = other.str_component_iter().map(|x|x.unwrap()); + let mut ita = self.str_components().map(|x|x.unwrap()); + let mut itb = other.str_components().map(|x|x.unwrap()); if "." == self.repr { return itb.next() != Some(".."); } @@ -520,8 +520,8 @@ impl GenericPath for Path { None } } else { - let mut ita = self.str_component_iter().map(|x|x.unwrap()); - let mut itb = base.str_component_iter().map(|x|x.unwrap()); + let mut ita = self.str_components().map(|x|x.unwrap()); + let mut itb = base.str_components().map(|x|x.unwrap()); let mut comps = ~[]; let a_verb = is_verbatim(self); @@ -569,8 +569,8 @@ impl GenericPath for Path { fn ends_with_path(&self, child: &Path) -> bool { if !child.is_relative() { return false; } - let mut selfit = self.str_component_iter().invert(); - let mut childit = child.str_component_iter().invert(); + let mut selfit = self.str_components().invert(); + let mut childit = child.str_components().invert(); loop { match (selfit.next(), childit.next()) { (Some(a), Some(b)) => if a != b { return false; }, @@ -608,7 +608,7 @@ impl Path { /// \a\b\c and a\b\c. /// Does not distinguish between absolute and cwd-relative paths, e.g. /// C:\foo and C:foo. - pub fn str_component_iter<'a>(&'a self) -> StrComponentIter<'a> { + pub fn str_components<'a>(&'a self) -> StrComponentIter<'a> { let s = match self.prefix { Some(_) => { let plen = self.prefix_len(); @@ -619,34 +619,34 @@ impl Path { None if self.repr[0] == sep as u8 => self.repr.slice_from(1), None => self.repr.as_slice() }; - let ret = s.split_terminator_iter(sep).map(Some); + let ret = s.split_terminator(sep).map(Some); ret } /// Returns an iterator that yields each component of the path in reverse as an Option<&str> - /// See str_component_iter() for details. - pub fn rev_str_component_iter<'a>(&'a self) -> RevStrComponentIter<'a> { - self.str_component_iter().invert() + /// See str_components() for details. + pub fn rev_str_components<'a>(&'a self) -> RevStrComponentIter<'a> { + self.str_components().invert() } /// Returns an iterator that yields each component of the path in turn as a &[u8]. - /// See str_component_iter() for details. - pub fn component_iter<'a>(&'a self) -> ComponentIter<'a> { + /// See str_components() for details. + pub fn components<'a>(&'a self) -> ComponentIter<'a> { fn convert<'a>(x: Option<&'a str>) -> &'a [u8] { #[inline]; x.unwrap().as_bytes() } - self.str_component_iter().map(convert) + self.str_components().map(convert) } /// Returns an iterator that yields each component of the path in reverse as a &[u8]. - /// See str_component_iter() for details. - pub fn rev_component_iter<'a>(&'a self) -> RevComponentIter<'a> { + /// See str_components() for details. + pub fn rev_components<'a>(&'a self) -> RevComponentIter<'a> { fn convert<'a>(x: Option<&'a str>) -> &'a [u8] { #[inline]; x.unwrap().as_bytes() } - self.rev_str_component_iter().map(convert) + self.rev_str_components().map(convert) } fn equiv_prefix(&self, other: &Path) -> bool { @@ -999,7 +999,7 @@ fn normalize_helper<'a>(s: &'a str, prefix: Option<PathPrefix>) -> (bool,Option< let mut comps: ~[&'a str] = ~[]; let mut n_up = 0u; let mut changed = false; - for comp in s_.split_iter(f) { + for comp in s_.split(f) { if comp.is_empty() { changed = true } else if comp == "." { changed = true } else if comp == ".." { @@ -2260,35 +2260,35 @@ mod tests { } #[test] - fn test_str_component_iter() { + fn test_str_components() { macro_rules! t( (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); - let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec(); + let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, - "str_component_iter: Expected {:?}, found {:?}", + "str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); - let comps = path.rev_str_component_iter().map(|x|x.unwrap()).to_owned_vec(); + let comps = path.rev_str_components().map(|x|x.unwrap()).to_owned_vec(); let exp = exp.rev_iter().map(|&x|x).to_owned_vec(); assert!(comps.as_slice() == exp, - "rev_str_component_iter: Expected {:?}, found {:?}", + "rev_str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); } ); (v: [$($arg:expr),+], $exp:expr) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec(); + let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, - "str_component_iter: Expected {:?}, found {:?}", + "str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); - let comps = path.rev_str_component_iter().map(|x|x.unwrap()).to_owned_vec(); + let comps = path.rev_str_components().map(|x|x.unwrap()).to_owned_vec(); let exp = exp.rev_iter().map(|&x|x).to_owned_vec(); assert!(comps.as_slice() == exp, - "rev_str_component_iter: Expected {:?}, found {:?}", + "rev_str_components: Expected {:?}, found {:?}", comps.as_slice(), exp); } ) @@ -2335,19 +2335,19 @@ mod tests { } #[test] - fn test_component_iter() { + fn test_components_iter() { macro_rules! t( (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); - let comps = path.component_iter().to_owned_vec(); + let comps = path.components().to_owned_vec(); let exp: &[&[u8]] = $exp; - assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}", + assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", comps.as_slice(), exp); - let comps = path.rev_component_iter().to_owned_vec(); + let comps = path.rev_components().to_owned_vec(); let exp = exp.rev_iter().map(|&x|x).to_owned_vec(); assert!(comps.as_slice() == exp, - "rev_component_iter: Expected {:?}, found {:?}", + "rev_components: Expected {:?}, found {:?}", comps.as_slice(), exp); } ) @@ -2355,6 +2355,6 @@ mod tests { t!(s: "a\\b\\c", [b!("a"), b!("b"), b!("c")]); t!(s: ".", [b!(".")]); - // since this is really a wrapper around str_component_iter, those tests suffice + // since this is really a wrapper around str_components, those tests suffice } } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 33e80d7fcae..d30d0887066 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -170,7 +170,7 @@ impl<'self> ReprVisitor<'self> { pub fn write_escaped_slice(&mut self, slice: &str) { self.writer.write(['"' as u8]); - for ch in slice.iter() { + for ch in slice.chars() { self.write_escaped_char(ch, true); } self.writer.write(['"' as u8]); diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index d1f69ada301..2c78a32a4b6 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -17,7 +17,7 @@ use rt::env; use rt::local::Local; use rt::task; use rt::task::Task; -use str::{OwnedStr, StrSlice}; +use str::OwnedStr; use str; use uint; use unstable::raw; diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 55a6280a1f4..2ca47dbff59 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -63,8 +63,8 @@ fn parse_log_level(level: &str) -> Option<u32> { /// Also supports string log levels of error, warn, info, and debug fn parse_logging_spec(spec: ~str) -> ~[LogDirective]{ let mut dirs = ~[]; - for s in spec.split_iter(',') { - let parts: ~[&str] = s.split_iter('=').collect(); + for s in spec.split(',') { + let parts: ~[&str] = s.split('=').collect(); let mut log_level; let mut name = Some(parts[0].to_owned()); match parts.len() { diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index a1f867fd5f3..93721986f3c 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -77,7 +77,7 @@ pub fn dumb_println(args: &fmt::Arguments) { pub fn abort(msg: &str) -> ! { let msg = if !msg.is_empty() { msg } else { "aborted" }; - let hash = msg.iter().fold(0, |accum, val| accum + (val as uint) ); + let hash = msg.chars().fold(0, |accum, val| accum + (val as uint) ); let quote = match hash % 10 { 0 => " It was from the artists and poets that the pertinent answers came, and I diff --git a/src/libstd/str.rs b/src/libstd/str.rs index c567fd0a8b3..3582782fc5e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -508,14 +508,14 @@ impl<'self, Sep: CharEq> Iterator<&'self str> for CharSplitIterator<'self, Sep> let mut next_split = None; if self.only_ascii { - for (idx, byte) in self.string.byte_iter().enumerate() { + for (idx, byte) in self.string.bytes().enumerate() { if self.sep.matches(byte as char) && byte < 128u8 { next_split = Some((idx, idx + 1)); break; } } } else { - for (idx, ch) in self.string.char_offset_iter() { + for (idx, ch) in self.string.char_indices() { if self.sep.matches(ch) { next_split = Some((idx, self.string.char_range_at(idx).next)); break; @@ -550,14 +550,14 @@ for CharSplitIterator<'self, Sep> { let mut next_split = None; if self.only_ascii { - for (idx, byte) in self.string.byte_iter().enumerate().invert() { + for (idx, byte) in self.string.bytes().enumerate().invert() { if self.sep.matches(byte as char) && byte < 128u8 { next_split = Some((idx, idx + 1)); break; } } } else { - for (idx, ch) in self.string.char_offset_rev_iter() { + for (idx, ch) in self.string.char_indices_rev() { if self.sep.matches(ch) { next_split = Some((idx, self.string.char_range_at(idx).next)); break; @@ -763,7 +763,7 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> { pub fn replace(s: &str, from: &str, to: &str) -> ~str { let mut result = ~""; let mut last_end = 0; - for (start, end) in s.matches_index_iter(from) { + for (start, end) in s.match_indices(from) { result.push_str(unsafe{raw::slice_bytes(s, last_end, start)}); result.push_str(to); last_end = end; @@ -1211,7 +1211,7 @@ pub mod traits { impl<'self> TotalOrd for &'self str { #[inline] fn cmp(&self, other: & &'self str) -> Ordering { - for (s_b, o_b) in self.byte_iter().zip(other.byte_iter()) { + for (s_b, o_b) in self.bytes().zip(other.bytes()) { match s_b.cmp(&o_b) { Greater => return Greater, Less => return Less, @@ -1397,26 +1397,26 @@ pub trait StrSlice<'self> { /// # Example /// /// ```rust - /// let v: ~[char] = "abc åäö".iter().collect(); + /// let v: ~[char] = "abc åäö".chars().collect(); /// assert_eq!(v, ~['a', 'b', 'c', ' ', 'å', 'ä', 'ö']); /// ``` - fn iter(&self) -> CharIterator<'self>; + fn chars(&self) -> CharIterator<'self>; /// An iterator over the characters of `self`, in reverse order. - fn rev_iter(&self) -> CharRevIterator<'self>; + fn chars_rev(&self) -> CharRevIterator<'self>; /// An iterator over the bytes of `self` - fn byte_iter(&self) -> ByteIterator<'self>; + fn bytes(&self) -> ByteIterator<'self>; /// An iterator over the bytes of `self`, in reverse order - fn byte_rev_iter(&self) -> ByteRevIterator<'self>; + fn bytes_rev(&self) -> ByteRevIterator<'self>; /// An iterator over the characters of `self` and their byte offsets. - fn char_offset_iter(&self) -> CharOffsetIterator<'self>; + fn char_indices(&self) -> CharOffsetIterator<'self>; /// An iterator over the characters of `self` and their byte offsets, /// in reverse order. - fn char_offset_rev_iter(&self) -> CharOffsetRevIterator<'self>; + fn char_indices_rev(&self) -> CharOffsetRevIterator<'self>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`. @@ -1424,32 +1424,32 @@ pub trait StrSlice<'self> { /// # Example /// /// ```rust - /// let v: ~[&str] = "Mary had a little lamb".split_iter(' ').collect(); + /// let v: ~[&str] = "Mary had a little lamb".split(' ').collect(); /// assert_eq!(v, ~["Mary", "had", "a", "little", "lamb"]); /// - /// let v: ~[&str] = "abc1def2ghi".split_iter(|c: char| c.is_digit()).collect(); + /// let v: ~[&str] = "abc1def2ghi".split(|c: char| c.is_digit()).collect(); /// assert_eq!(v, ~["abc", "def", "ghi"]); /// ``` - fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>; + fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`, restricted to splitting at most `count` /// times. - fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>; + fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`. /// - /// Equivalent to `split_iter`, except that the trailing substring + /// Equivalent to `split`, except that the trailing substring /// is skipped if empty (terminator semantics). /// /// # Example /// /// ```rust - /// let v: ~[&str] = "A.B.".split_terminator_iter('.').collect(); + /// let v: ~[&str] = "A.B.".split_terminator('.').collect(); /// assert_eq!(v, ~["A", "B"]); /// ``` - fn split_terminator_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>; + fn split_terminator<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`, in reverse order @@ -1457,47 +1457,47 @@ pub trait StrSlice<'self> { /// # Example /// /// ```rust - /// let v: ~[&str] = "Mary had a little lamb".rsplit_iter(' ').collect(); + /// let v: ~[&str] = "Mary had a little lamb".rsplit(' ').collect(); /// assert_eq!(v, ~["lamb", "little", "a", "had", "Mary"]); /// ``` - fn rsplit_iter<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep>; + fn rsplit<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`, starting from the end of the string. /// Restricted to splitting at most `count` times. - fn rsplitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>; + fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>; /// An iterator over the start and end indices of each match of /// `sep` within `self`. - fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self>; + fn match_indices(&self, sep: &'self str) -> MatchesIndexIterator<'self>; /// An iterator over the substrings of `self` separated by `sep`. /// /// # Example /// /// ```rust - /// let v: ~[&str] = "abcXXXabcYYYabc".split_str_iter("abc").collect() + /// let v: ~[&str] = "abcXXXabcYYYabc".split_str("abc").collect() /// assert_eq!(v, ["", "XXX", "YYY", ""]); /// ``` - fn split_str_iter(&self, &'self str) -> StrSplitIterator<'self>; + fn split_str(&self, &'self str) -> StrSplitIterator<'self>; /// An iterator over the lines of a string (subsequences separated /// by `\n`). - fn line_iter(&self) -> CharSplitIterator<'self, char>; + fn lines(&self) -> CharSplitIterator<'self, char>; /// An iterator over the lines of a string, separated by either /// `\n` or (`\r\n`). - fn any_line_iter(&self) -> AnyLineIterator<'self>; + fn lines_any(&self) -> AnyLineIterator<'self>; /// An iterator over the words of a string (subsequences separated /// by any sequence of whitespace). - fn word_iter(&self) -> WordIterator<'self>; + fn words(&self) -> WordIterator<'self>; /// An Iterator over the string in Unicode Normalization Form D (canonical decomposition) - fn nfd_iter(&self) -> NormalizationIterator<'self>; + fn nfd_chars(&self) -> NormalizationIterator<'self>; /// An Iterator over the string in Unicode Normalization Form KD (compatibility decomposition) - fn nfkd_iter(&self) -> NormalizationIterator<'self>; + fn nfkd_chars(&self) -> NormalizationIterator<'self>; /// Returns true if the string contains only whitespace /// @@ -1751,7 +1751,7 @@ pub trait StrSlice<'self> { /// ```rust /// let string = "a\nb\nc"; /// let mut lines = ~[]; - /// for line in string.line_iter() { lines.push(line) } + /// for line in string.lines() { lines.push(line) } /// /// assert!(string.subslice_offset(lines[0]) == 0); // &"a" /// assert!(string.subslice_offset(lines[1]) == 2); // &"b" @@ -1777,37 +1777,37 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn iter(&self) -> CharIterator<'self> { + fn chars(&self) -> CharIterator<'self> { CharIterator{string: *self} } #[inline] - fn rev_iter(&self) -> CharRevIterator<'self> { - self.iter().invert() + fn chars_rev(&self) -> CharRevIterator<'self> { + self.chars().invert() } #[inline] - fn byte_iter(&self) -> ByteIterator<'self> { + fn bytes(&self) -> ByteIterator<'self> { self.as_bytes().iter().map(|&b| b) } #[inline] - fn byte_rev_iter(&self) -> ByteRevIterator<'self> { - self.byte_iter().invert() + fn bytes_rev(&self) -> ByteRevIterator<'self> { + self.bytes().invert() } #[inline] - fn char_offset_iter(&self) -> CharOffsetIterator<'self> { - CharOffsetIterator{string: *self, iter: self.iter()} + fn char_indices(&self) -> CharOffsetIterator<'self> { + CharOffsetIterator{string: *self, iter: self.chars()} } #[inline] - fn char_offset_rev_iter(&self) -> CharOffsetRevIterator<'self> { - self.char_offset_iter().invert() + fn char_indices_rev(&self) -> CharOffsetRevIterator<'self> { + self.char_indices().invert() } #[inline] - fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> { + fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> { CharSplitIterator { string: *self, only_ascii: sep.only_ascii(), @@ -1818,41 +1818,41 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) + fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep> { CharSplitNIterator { - iter: self.split_iter(sep), + iter: self.split(sep), count: count, invert: false, } } #[inline] - fn split_terminator_iter<Sep: CharEq>(&self, sep: Sep) + fn split_terminator<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> { CharSplitIterator { allow_trailing_empty: false, - ..self.split_iter(sep) + ..self.split(sep) } } #[inline] - fn rsplit_iter<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep> { - self.split_iter(sep).invert() + fn rsplit<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep> { + self.split(sep).invert() } #[inline] - fn rsplitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) + fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep> { CharSplitNIterator { - iter: self.split_iter(sep), + iter: self.split(sep), count: count, invert: true, } } #[inline] - fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self> { + fn match_indices(&self, sep: &'self str) -> MatchesIndexIterator<'self> { assert!(!sep.is_empty()) MatchesIndexIterator { haystack: *self, @@ -1862,21 +1862,21 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn split_str_iter(&self, sep: &'self str) -> StrSplitIterator<'self> { + fn split_str(&self, sep: &'self str) -> StrSplitIterator<'self> { StrSplitIterator { - it: self.matches_index_iter(sep), + it: self.match_indices(sep), last_end: 0, finished: false } } #[inline] - fn line_iter(&self) -> CharSplitIterator<'self, char> { - self.split_terminator_iter('\n') + fn lines(&self) -> CharSplitIterator<'self, char> { + self.split_terminator('\n') } - fn any_line_iter(&self) -> AnyLineIterator<'self> { - do self.line_iter().map |line| { + fn lines_any(&self) -> AnyLineIterator<'self> { + do self.lines().map |line| { let l = line.len(); if l > 0 && line[l - 1] == '\r' as u8 { line.slice(0, l - 1) } else { line } @@ -1884,14 +1884,14 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn word_iter(&self) -> WordIterator<'self> { - self.split_iter(char::is_whitespace).filter(|s| !s.is_empty()) + fn words(&self) -> WordIterator<'self> { + self.split(char::is_whitespace).filter(|s| !s.is_empty()) } #[inline] - fn nfd_iter(&self) -> NormalizationIterator<'self> { + fn nfd_chars(&self) -> NormalizationIterator<'self> { NormalizationIterator { - iter: self.iter(), + iter: self.chars(), buffer: ~[], sorted: false, kind: NFD @@ -1899,9 +1899,9 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn nfkd_iter(&self) -> NormalizationIterator<'self> { + fn nfkd_chars(&self) -> NormalizationIterator<'self> { NormalizationIterator { - iter: self.iter(), + iter: self.chars(), buffer: ~[], sorted: false, kind: NFKD @@ -1909,13 +1909,13 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn is_whitespace(&self) -> bool { self.iter().all(char::is_whitespace) } + fn is_whitespace(&self) -> bool { self.chars().all(char::is_whitespace) } #[inline] - fn is_alphanumeric(&self) -> bool { self.iter().all(char::is_alphanumeric) } + fn is_alphanumeric(&self) -> bool { self.chars().all(char::is_alphanumeric) } #[inline] - fn char_len(&self) -> uint { self.iter().len() } + fn char_len(&self) -> uint { self.chars().len() } #[inline] fn slice(&self, begin: uint, end: uint) -> &'self str { @@ -1942,7 +1942,7 @@ impl<'self> StrSlice<'self> for &'self str { // This could be even more efficient by not decoding, // only finding the char boundaries - for (idx, _) in self.char_offset_iter() { + for (idx, _) in self.char_indices() { if count == begin { begin_byte = Some(idx); } if count == end { end_byte = Some(idx); break; } count += 1; @@ -1972,7 +1972,7 @@ impl<'self> StrSlice<'self> for &'self str { fn escape_default(&self) -> ~str { let mut out: ~str = ~""; out.reserve_at_least(self.len()); - for c in self.iter() { + for c in self.chars() { do c.escape_default |c| { out.push_char(c); } @@ -1983,7 +1983,7 @@ impl<'self> StrSlice<'self> for &'self str { fn escape_unicode(&self) -> ~str { let mut out: ~str = ~""; out.reserve_at_least(self.len()); - for c in self.iter() { + for c in self.chars() { do c.escape_unicode |c| { out.push_char(c); } @@ -2033,7 +2033,7 @@ impl<'self> StrSlice<'self> for &'self str { fn replace(&self, from: &str, to: &str) -> ~str { let mut result = ~""; let mut last_end = 0; - for (start, end) in self.matches_index_iter(from) { + for (start, end) in self.match_indices(from) { result.push_str(unsafe{raw::slice_bytes(*self, last_end, start)}); result.push_str(to); last_end = end; @@ -2067,7 +2067,7 @@ impl<'self> StrSlice<'self> for &'self str { fn to_utf16(&self) -> ~[u16] { let mut u = ~[]; - for ch in self.iter() { + for ch in self.chars() { // Arithmetic with u32 literals is easier on the eyes than chars. let mut ch = ch as u32; @@ -2172,9 +2172,9 @@ impl<'self> StrSlice<'self> for &'self str { fn find<C: CharEq>(&self, search: C) -> Option<uint> { if search.only_ascii() { - self.byte_iter().position(|b| search.matches(b as char)) + self.bytes().position(|b| search.matches(b as char)) } else { - for (index, c) in self.char_offset_iter() { + for (index, c) in self.char_indices() { if search.matches(c) { return Some(index); } } None @@ -2183,9 +2183,9 @@ impl<'self> StrSlice<'self> for &'self str { fn rfind<C: CharEq>(&self, search: C) -> Option<uint> { if search.only_ascii() { - self.byte_iter().rposition(|b| search.matches(b as char)) + self.bytes().rposition(|b| search.matches(b as char)) } else { - for (index, c) in self.char_offset_rev_iter() { + for (index, c) in self.char_indices_rev() { if search.matches(c) { return Some(index); } } None @@ -2196,7 +2196,7 @@ impl<'self> StrSlice<'self> for &'self str { if needle.is_empty() { Some(0) } else { - self.matches_index_iter(needle) + self.match_indices(needle) .next() .map(|(start, _end)| start) } @@ -2226,12 +2226,12 @@ impl<'self> StrSlice<'self> for &'self str { let mut dcol = vec::from_fn(tlen + 1, |x| x); - for (i, sc) in self.iter().enumerate() { + for (i, sc) in self.chars().enumerate() { let mut current = i; dcol[0] = current + 1; - for (j, tc) in t.iter().enumerate() { + for (j, tc) in t.chars().enumerate() { let next = dcol[j + 1]; @@ -2674,10 +2674,10 @@ mod tests { #[test] fn test_collect() { let empty = ~""; - let s: ~str = empty.iter().collect(); + let s: ~str = empty.chars().collect(); assert_eq!(empty, s); let data = ~"ประเทศไทย中"; - let s: ~str = data.iter().collect(); + let s: ~str = data.chars().collect(); assert_eq!(data, s); } @@ -2686,7 +2686,7 @@ mod tests { let data = ~"ประเทศไทย中"; let mut cpy = data.clone(); let other = "abc"; - let mut it = other.iter(); + let mut it = other.chars(); cpy.extend(&mut it); assert_eq!(cpy, data + other); } @@ -3227,7 +3227,7 @@ mod tests { let string = "a\nb\nc"; let mut lines = ~[]; - for line in string.line_iter() { lines.push(line) } + for line in string.lines() { lines.push(line) } assert_eq!(string.subslice_offset(lines[0]), 0); assert_eq!(string.subslice_offset(lines[1]), 2); assert_eq!(string.subslice_offset(lines[2]), 4); @@ -3443,7 +3443,7 @@ mod tests { let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; - let mut it = s.iter(); + let mut it = s.chars(); for c in it { assert_eq!(c, v[pos]); @@ -3459,7 +3459,7 @@ mod tests { let v = ~['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ']; let mut pos = 0; - let mut it = s.rev_iter(); + let mut it = s.chars_rev(); for c in it { assert_eq!(c, v[pos]); @@ -3471,13 +3471,13 @@ mod tests { #[test] fn test_iterator_clone() { let s = "ศไทย中华Việt Nam"; - let mut it = s.iter(); + let mut it = s.chars(); it.next(); assert!(it.zip(it.clone()).all(|(x,y)| x == y)); } #[test] - fn test_byte_iterator() { + fn test_bytesator() { let s = ~"ศไทย中华Việt Nam"; let v = [ 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228, @@ -3486,14 +3486,14 @@ mod tests { ]; let mut pos = 0; - for b in s.byte_iter() { + for b in s.bytes() { assert_eq!(b, v[pos]); pos += 1; } } #[test] - fn test_byte_rev_iterator() { + fn test_bytes_revator() { let s = ~"ศไทย中华Việt Nam"; let v = [ 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228, @@ -3502,21 +3502,21 @@ mod tests { ]; let mut pos = v.len(); - for b in s.byte_rev_iter() { + for b in s.bytes_rev() { pos -= 1; assert_eq!(b, v[pos]); } } #[test] - fn test_char_offset_iterator() { + fn test_char_indicesator() { use iter::*; let s = "ศไทย中华Việt Nam"; let p = [0, 3, 6, 9, 12, 15, 18, 19, 20, 23, 24, 25, 26, 27]; let v = ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; - let mut it = s.char_offset_iter(); + let mut it = s.char_indices(); for c in it { assert_eq!(c, (p[pos], v[pos])); @@ -3527,14 +3527,14 @@ mod tests { } #[test] - fn test_char_offset_rev_iterator() { + fn test_char_indices_revator() { use iter::*; let s = "ศไทย中华Việt Nam"; let p = [27, 26, 25, 24, 23, 20, 19, 18, 15, 12, 9, 6, 3, 0]; let v = ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ']; let mut pos = 0; - let mut it = s.char_offset_rev_iter(); + let mut it = s.char_indices_rev(); for c in it { assert_eq!(c, (p[pos], v[pos])); @@ -3548,32 +3548,32 @@ mod tests { fn test_split_char_iterator() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let split: ~[&str] = data.split_iter(' ').collect(); + let split: ~[&str] = data.split(' ').collect(); assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]); - let mut rsplit: ~[&str] = data.rsplit_iter(' ').collect(); + let mut rsplit: ~[&str] = data.rsplit(' ').collect(); rsplit.reverse(); assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]); - let split: ~[&str] = data.split_iter(|c: char| c == ' ').collect(); + let split: ~[&str] = data.split(|c: char| c == ' ').collect(); assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]); - let mut rsplit: ~[&str] = data.rsplit_iter(|c: char| c == ' ').collect(); + let mut rsplit: ~[&str] = data.rsplit(|c: char| c == ' ').collect(); rsplit.reverse(); assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]); // Unicode - let split: ~[&str] = data.split_iter('ä').collect(); + let split: ~[&str] = data.split('ä').collect(); assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]); - let mut rsplit: ~[&str] = data.rsplit_iter('ä').collect(); + let mut rsplit: ~[&str] = data.rsplit('ä').collect(); rsplit.reverse(); assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]); - let split: ~[&str] = data.split_iter(|c: char| c == 'ä').collect(); + let split: ~[&str] = data.split(|c: char| c == 'ä').collect(); assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]); - let mut rsplit: ~[&str] = data.rsplit_iter(|c: char| c == 'ä').collect(); + let mut rsplit: ~[&str] = data.rsplit(|c: char| c == 'ä').collect(); rsplit.reverse(); assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]); } @@ -3582,17 +3582,17 @@ mod tests { fn test_splitn_char_iterator() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let split: ~[&str] = data.splitn_iter(' ', 3).collect(); + let split: ~[&str] = data.splitn(' ', 3).collect(); assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]); - let split: ~[&str] = data.splitn_iter(|c: char| c == ' ', 3).collect(); + let split: ~[&str] = data.splitn(|c: char| c == ' ', 3).collect(); assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]); // Unicode - let split: ~[&str] = data.splitn_iter('ä', 3).collect(); + let split: ~[&str] = data.splitn('ä', 3).collect(); assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]); - let split: ~[&str] = data.splitn_iter(|c: char| c == 'ä', 3).collect(); + let split: ~[&str] = data.splitn(|c: char| c == 'ä', 3).collect(); assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]); } @@ -3600,20 +3600,20 @@ mod tests { fn test_rsplitn_char_iterator() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let mut split: ~[&str] = data.rsplitn_iter(' ', 3).collect(); + let mut split: ~[&str] = data.rsplitn(' ', 3).collect(); split.reverse(); assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]); - let mut split: ~[&str] = data.rsplitn_iter(|c: char| c == ' ', 3).collect(); + let mut split: ~[&str] = data.rsplitn(|c: char| c == ' ', 3).collect(); split.reverse(); assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]); // Unicode - let mut split: ~[&str] = data.rsplitn_iter('ä', 3).collect(); + let mut split: ~[&str] = data.rsplitn('ä', 3).collect(); split.reverse(); assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]); - let mut split: ~[&str] = data.rsplitn_iter(|c: char| c == 'ä', 3).collect(); + let mut split: ~[&str] = data.rsplitn(|c: char| c == 'ä', 3).collect(); split.reverse(); assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]); } @@ -3622,10 +3622,10 @@ mod tests { fn test_split_char_iterator_no_trailing() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let split: ~[&str] = data.split_iter('\n').collect(); + let split: ~[&str] = data.split('\n').collect(); assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]); - let split: ~[&str] = data.split_terminator_iter('\n').collect(); + let split: ~[&str] = data.split_terminator('\n').collect(); assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]); } @@ -3633,65 +3633,65 @@ mod tests { fn test_rev_split_char_iterator_no_trailing() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let mut split: ~[&str] = data.split_iter('\n').invert().collect(); + let mut split: ~[&str] = data.split('\n').invert().collect(); split.reverse(); assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]); - let mut split: ~[&str] = data.split_terminator_iter('\n').invert().collect(); + let mut split: ~[&str] = data.split_terminator('\n').invert().collect(); split.reverse(); assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]); } #[test] - fn test_word_iter() { + fn test_words() { let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n"; - let words: ~[&str] = data.word_iter().collect(); + let words: ~[&str] = data.words().collect(); assert_eq!(words, ~["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"]) } #[test] - fn test_nfd_iter() { - assert_eq!("abc".nfd_iter().collect::<~str>(), ~"abc"); - assert_eq!("\u1e0b\u01c4".nfd_iter().collect::<~str>(), ~"d\u0307\u01c4"); - assert_eq!("\u2026".nfd_iter().collect::<~str>(), ~"\u2026"); - assert_eq!("\u2126".nfd_iter().collect::<~str>(), ~"\u03a9"); - assert_eq!("\u1e0b\u0323".nfd_iter().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("\u1e0d\u0307".nfd_iter().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("a\u0301".nfd_iter().collect::<~str>(), ~"a\u0301"); - assert_eq!("\u0301a".nfd_iter().collect::<~str>(), ~"\u0301a"); - assert_eq!("\ud4db".nfd_iter().collect::<~str>(), ~"\u1111\u1171\u11b6"); - assert_eq!("\uac1c".nfd_iter().collect::<~str>(), ~"\u1100\u1162"); + fn test_nfd_chars() { + assert_eq!("abc".nfd_chars().collect::<~str>(), ~"abc"); + assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<~str>(), ~"d\u0307\u01c4"); + assert_eq!("\u2026".nfd_chars().collect::<~str>(), ~"\u2026"); + assert_eq!("\u2126".nfd_chars().collect::<~str>(), ~"\u03a9"); + assert_eq!("\u1e0b\u0323".nfd_chars().collect::<~str>(), ~"d\u0323\u0307"); + assert_eq!("\u1e0d\u0307".nfd_chars().collect::<~str>(), ~"d\u0323\u0307"); + assert_eq!("a\u0301".nfd_chars().collect::<~str>(), ~"a\u0301"); + assert_eq!("\u0301a".nfd_chars().collect::<~str>(), ~"\u0301a"); + assert_eq!("\ud4db".nfd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6"); + assert_eq!("\uac1c".nfd_chars().collect::<~str>(), ~"\u1100\u1162"); } #[test] - fn test_nfkd_iter() { - assert_eq!("abc".nfkd_iter().collect::<~str>(), ~"abc"); - assert_eq!("\u1e0b\u01c4".nfkd_iter().collect::<~str>(), ~"d\u0307DZ\u030c"); - assert_eq!("\u2026".nfkd_iter().collect::<~str>(), ~"..."); - assert_eq!("\u2126".nfkd_iter().collect::<~str>(), ~"\u03a9"); - assert_eq!("\u1e0b\u0323".nfkd_iter().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("\u1e0d\u0307".nfkd_iter().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("a\u0301".nfkd_iter().collect::<~str>(), ~"a\u0301"); - assert_eq!("\u0301a".nfkd_iter().collect::<~str>(), ~"\u0301a"); - assert_eq!("\ud4db".nfkd_iter().collect::<~str>(), ~"\u1111\u1171\u11b6"); - assert_eq!("\uac1c".nfkd_iter().collect::<~str>(), ~"\u1100\u1162"); + fn test_nfkd_chars() { + assert_eq!("abc".nfkd_chars().collect::<~str>(), ~"abc"); + assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<~str>(), ~"d\u0307DZ\u030c"); + assert_eq!("\u2026".nfkd_chars().collect::<~str>(), ~"..."); + assert_eq!("\u2126".nfkd_chars().collect::<~str>(), ~"\u03a9"); + assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307"); + assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307"); + assert_eq!("a\u0301".nfkd_chars().collect::<~str>(), ~"a\u0301"); + assert_eq!("\u0301a".nfkd_chars().collect::<~str>(), ~"\u0301a"); + assert_eq!("\ud4db".nfkd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6"); + assert_eq!("\uac1c".nfkd_chars().collect::<~str>(), ~"\u1100\u1162"); } #[test] - fn test_line_iter() { + fn test_lines() { let data = "\nMäry häd ä little lämb\n\nLittle lämb\n"; - let lines: ~[&str] = data.line_iter().collect(); + let lines: ~[&str] = data.lines().collect(); assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]); let data = "\nMäry häd ä little lämb\n\nLittle lämb"; // no trailing \n - let lines: ~[&str] = data.line_iter().collect(); + let lines: ~[&str] = data.lines().collect(); assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]); } #[test] - fn test_split_str_iterator() { + fn test_split_strator() { fn t<'a>(s: &str, sep: &'a str, u: ~[&str]) { - let v: ~[&str] = s.split_str_iter(sep).collect(); + let v: ~[&str] = s.split_str(sep).collect(); assert_eq!(v, u); } t("--1233345--", "12345", ~["--1233345--"]); @@ -3865,7 +3865,7 @@ mod bench { let len = s.char_len(); do bh.iter { - assert_eq!(s.iter().len(), len); + assert_eq!(s.chars().len(), len); } } @@ -3880,7 +3880,7 @@ mod bench { let len = s.char_len(); do bh.iter { - assert_eq!(s.iter().len(), len); + assert_eq!(s.chars().len(), len); } } @@ -3890,41 +3890,41 @@ mod bench { let len = s.char_len(); do bh.iter { - assert_eq!(s.rev_iter().len(), len); + assert_eq!(s.chars_rev().len(), len); } } #[bench] - fn char_offset_iterator(bh: &mut BenchHarness) { + fn char_indicesator(bh: &mut BenchHarness) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); do bh.iter { - assert_eq!(s.char_offset_iter().len(), len); + assert_eq!(s.char_indices().len(), len); } } #[bench] - fn char_offset_iterator_rev(bh: &mut BenchHarness) { + fn char_indicesator_rev(bh: &mut BenchHarness) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); do bh.iter { - assert_eq!(s.char_offset_rev_iter().len(), len); + assert_eq!(s.char_indices_rev().len(), len); } } #[bench] - fn split_iter_unicode_ascii(bh: &mut BenchHarness) { + fn split_unicode_ascii(bh: &mut BenchHarness) { let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam"; do bh.iter { - assert_eq!(s.split_iter('V').len(), 3); + assert_eq!(s.split('V').len(), 3); } } #[bench] - fn split_iter_unicode_not_ascii(bh: &mut BenchHarness) { + fn split_unicode_not_ascii(bh: &mut BenchHarness) { struct NotAscii(char); impl CharEq for NotAscii { fn matches(&self, c: char) -> bool { @@ -3935,23 +3935,23 @@ mod bench { let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam"; do bh.iter { - assert_eq!(s.split_iter(NotAscii('V')).len(), 3); + assert_eq!(s.split(NotAscii('V')).len(), 3); } } #[bench] - fn split_iter_ascii(bh: &mut BenchHarness) { + fn split_ascii(bh: &mut BenchHarness) { let s = "Mary had a little lamb, Little lamb, little-lamb."; - let len = s.split_iter(' ').len(); + let len = s.split(' ').len(); do bh.iter { - assert_eq!(s.split_iter(' ').len(), len); + assert_eq!(s.split(' ').len(), len); } } #[bench] - fn split_iter_not_ascii(bh: &mut BenchHarness) { + fn split_not_ascii(bh: &mut BenchHarness) { struct NotAscii(char); impl CharEq for NotAscii { #[inline] @@ -3959,41 +3959,41 @@ mod bench { fn only_ascii(&self) -> bool { false } } let s = "Mary had a little lamb, Little lamb, little-lamb."; - let len = s.split_iter(' ').len(); + let len = s.split(' ').len(); do bh.iter { - assert_eq!(s.split_iter(NotAscii(' ')).len(), len); + assert_eq!(s.split(NotAscii(' ')).len(), len); } } #[bench] - fn split_iter_extern_fn(bh: &mut BenchHarness) { + fn split_extern_fn(bh: &mut BenchHarness) { let s = "Mary had a little lamb, Little lamb, little-lamb."; - let len = s.split_iter(' ').len(); + let len = s.split(' ').len(); fn pred(c: char) -> bool { c == ' ' } do bh.iter { - assert_eq!(s.split_iter(pred).len(), len); + assert_eq!(s.split(pred).len(), len); } } #[bench] - fn split_iter_closure(bh: &mut BenchHarness) { + fn split_closure(bh: &mut BenchHarness) { let s = "Mary had a little lamb, Little lamb, little-lamb."; - let len = s.split_iter(' ').len(); + let len = s.split(' ').len(); do bh.iter { - assert_eq!(s.split_iter(|c: char| c == ' ').len(), len); + assert_eq!(s.split(|c: char| c == ' ').len(), len); } } #[bench] - fn split_iter_slice(bh: &mut BenchHarness) { + fn split_slice(bh: &mut BenchHarness) { let s = "Mary had a little lamb, Little lamb, little-lamb."; - let len = s.split_iter(' ').len(); + let len = s.split(' ').len(); do bh.iter { - assert_eq!(s.split_iter(&[' ']).len(), len); + assert_eq!(s.split(&[' ']).len(), len); } } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 98f5baf1e2b..9f5ee752089 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -158,7 +158,7 @@ impl<T> TrieMap<T> { // If `upper` is true then returns upper_bound else returns lower_bound. #[inline] - fn bound_iter<'a>(&'a self, key: uint, upper: bool) -> TrieMapIterator<'a, T> { + fn bound<'a>(&'a self, key: uint, upper: bool) -> TrieMapIterator<'a, T> { let mut node: &'a TrieNode<T> = &self.root; let mut idx = 0; let mut it = TrieMapIterator { @@ -193,14 +193,14 @@ impl<T> TrieMap<T> { /// Get an iterator pointing to the first key-value pair whose key is not less than `key`. /// If all keys in the map are less than `key` an empty iterator is returned. - pub fn lower_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { - self.bound_iter(key, false) + pub fn lower_bound<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { + self.bound(key, false) } /// Get an iterator pointing to the first key-value pair whose key is greater than `key`. /// If all keys in the map are not greater than `key` an empty iterator is returned. - pub fn upper_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { - self.bound_iter(key, true) + pub fn upper_bound<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { + self.bound(key, true) } } @@ -282,14 +282,14 @@ impl TrieSet { /// Get an iterator pointing to the first value that is not less than `val`. /// If all values in the set are less than `val` an empty iterator is returned. - pub fn lower_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { - TrieSetIterator{iter: self.map.lower_bound_iter(val)} + pub fn lower_bound<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { + TrieSetIterator{iter: self.map.lower_bound(val)} } /// Get an iterator pointing to the first value that key is greater than `val`. /// If all values in the set are not greater than `val` an empty iterator is returned. - pub fn upper_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { - TrieSetIterator{iter: self.map.upper_bound_iter(val)} + pub fn upper_bound<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { + TrieSetIterator{iter: self.map.upper_bound(val)} } } @@ -713,10 +713,10 @@ mod test_map { } #[test] - fn test_bound_iter() { + fn test_bound() { let empty_map : TrieMap<uint> = TrieMap::new(); - assert_eq!(empty_map.lower_bound_iter(0).next(), None); - assert_eq!(empty_map.upper_bound_iter(0).next(), None); + assert_eq!(empty_map.lower_bound(0).next(), None); + assert_eq!(empty_map.upper_bound(0).next(), None); let last = 999u; let step = 3u; @@ -729,8 +729,8 @@ mod test_map { } for i in range(0u, last - step) { - let mut lb = map.lower_bound_iter(i); - let mut ub = map.upper_bound_iter(i); + let mut lb = map.lower_bound(i); + let mut ub = map.upper_bound(i); let next_key = i - i % step + step; let next_pair = (next_key, &value); if (i % step == 0) { @@ -741,15 +741,15 @@ mod test_map { assert_eq!(ub.next(), Some(next_pair)); } - let mut lb = map.lower_bound_iter(last - step); + let mut lb = map.lower_bound(last - step); assert_eq!(lb.next(), Some((last - step, &value))); - let mut ub = map.upper_bound_iter(last - step); + let mut ub = map.upper_bound(last - step); assert_eq!(ub.next(), None); for i in range(last - step + 1, last) { - let mut lb = map.lower_bound_iter(i); + let mut lb = map.lower_bound(i); assert_eq!(lb.next(), None); - let mut ub = map.upper_bound_iter(i); + let mut ub = map.upper_bound(i); assert_eq!(ub.next(), None); } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 7e797cec03f..5fbf03c3cbb 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -859,20 +859,20 @@ pub trait ImmutableVector<'self, T> { fn rev_iter(self) -> RevIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. - fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; + fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`, limited to splitting /// at most `n` times. - fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; + fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. This starts at the /// end of the vector and works backwards. - fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; + fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred` limited to splitting /// at most `n` times. This starts at the end of the vector and /// works backwards. - fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; + fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; /** * Returns an iterator over all contiguous windows of length @@ -890,13 +890,13 @@ pub trait ImmutableVector<'self, T> { * * ```rust * let v = &[1,2,3,4]; - * for win in v.window_iter() { + * for win in v.windows(2) { * println!("{:?}", win); * } * ``` * */ - fn window_iter(self, size: uint) -> WindowIter<'self, T>; + fn windows(self, size: uint) -> WindowIter<'self, T>; /** * * Returns an iterator over `size` elements of the vector at a @@ -915,13 +915,13 @@ pub trait ImmutableVector<'self, T> { * * ```rust * let v = &[1,2,3,4,5]; - * for win in v.chunk_iter() { + * for win in v.chunks(2) { * println!("{:?}", win); * } * ``` * */ - fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>; + fn chunks(self, size: uint) -> ChunkIter<'self, T>; /// Returns the element of a vector at the given index, or `None` if the /// index is out of bounds @@ -1024,11 +1024,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } #[inline] - fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { - self.splitn_iter(uint::max_value, pred) + fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { + self.splitn(uint::max_value, pred) } + #[inline] - fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { + fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { SplitIterator { v: self, n: n, @@ -1036,12 +1037,14 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { finished: false } } + #[inline] - fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { - self.rsplitn_iter(uint::max_value, pred) + fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { + self.rsplitn(uint::max_value, pred) } + #[inline] - fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { + fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { RSplitIterator { v: self, n: n, @@ -1050,12 +1053,14 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } } - fn window_iter(self, size: uint) -> WindowIter<'self, T> { + #[inline] + fn windows(self, size: uint) -> WindowIter<'self, T> { assert!(size != 0); WindowIter { v: self, size: size } } - fn chunk_iter(self, size: uint) -> ChunkIter<'self, T> { + #[inline] + fn chunks(self, size: uint) -> ChunkIter<'self, T> { assert!(size != 0); ChunkIter { v: self, size: size } } @@ -1218,7 +1223,7 @@ pub trait ImmutableCopyableVector<T> { /// Create an iterator that yields every possible permutation of the /// vector in succession. - fn permutations_iter(self) -> Permutations<T>; + fn permutations(self) -> Permutations<T>; } impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] { @@ -1243,7 +1248,7 @@ impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] { (*self.unsafe_ref(index)).clone() } - fn permutations_iter(self) -> Permutations<T> { + fn permutations(self) -> Permutations<T> { Permutations{ swaps: ElementSwaps::new(self.len()), v: self.to_owned(), @@ -3035,17 +3040,17 @@ mod tests { use hashmap; { let v: [int, ..0] = []; - let mut it = v.permutations_iter(); + let mut it = v.permutations(); assert_eq!(it.next(), None); } { let v = [~"Hello"]; - let mut it = v.permutations_iter(); + let mut it = v.permutations(); assert_eq!(it.next(), None); } { let v = [1, 2, 3]; - let mut it = v.permutations_iter(); + let mut it = v.permutations(); assert_eq!(it.next(), Some(~[1,2,3])); assert_eq!(it.next(), Some(~[1,3,2])); assert_eq!(it.next(), Some(~[3,1,2])); @@ -3058,7 +3063,7 @@ mod tests { // check that we have N! unique permutations let mut set = hashmap::HashSet::new(); let v = ['A', 'B', 'C', 'D', 'E', 'F']; - for perm in v.permutations_iter() { + for perm in v.permutations() { set.insert(perm); } assert_eq!(set.len(), 2 * 3 * 4 * 5 * 6); @@ -3357,7 +3362,7 @@ mod tests { fn test_permute_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - for _ in v.permutations_iter() { + for _ in v.permutations() { if i == 2 { fail!() } @@ -3530,97 +3535,97 @@ mod tests { } #[test] - fn test_split_iterator() { + fn test_splitator() { let xs = &[1i,2,3,4,5]; - assert_eq!(xs.split_iter(|x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.split(|x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[1], &[3], &[5]]); - assert_eq!(xs.split_iter(|x| *x == 1).collect::<~[&[int]]>(), + assert_eq!(xs.split(|x| *x == 1).collect::<~[&[int]]>(), ~[&[], &[2,3,4,5]]); - assert_eq!(xs.split_iter(|x| *x == 5).collect::<~[&[int]]>(), + assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(), ~[&[1,2,3,4], &[]]); - assert_eq!(xs.split_iter(|x| *x == 10).collect::<~[&[int]]>(), + assert_eq!(xs.split(|x| *x == 10).collect::<~[&[int]]>(), ~[&[1,2,3,4,5]]); - assert_eq!(xs.split_iter(|_| true).collect::<~[&[int]]>(), + assert_eq!(xs.split(|_| true).collect::<~[&[int]]>(), ~[&[], &[], &[], &[], &[], &[]]); let xs: &[int] = &[]; - assert_eq!(xs.split_iter(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); + assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); } #[test] - fn test_splitn_iterator() { + fn test_splitnator() { let xs = &[1i,2,3,4,5]; - assert_eq!(xs.splitn_iter(0, |x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[1,2,3,4,5]]); - assert_eq!(xs.splitn_iter(1, |x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[1], &[3,4,5]]); - assert_eq!(xs.splitn_iter(3, |_| true).collect::<~[&[int]]>(), + assert_eq!(xs.splitn(3, |_| true).collect::<~[&[int]]>(), ~[&[], &[], &[], &[4,5]]); let xs: &[int] = &[]; - assert_eq!(xs.splitn_iter(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); + assert_eq!(xs.splitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); } #[test] - fn test_rsplit_iterator() { + fn test_rsplitator() { let xs = &[1i,2,3,4,5]; - assert_eq!(xs.rsplit_iter(|x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.rsplit(|x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[5], &[3], &[1]]); - assert_eq!(xs.rsplit_iter(|x| *x == 1).collect::<~[&[int]]>(), + assert_eq!(xs.rsplit(|x| *x == 1).collect::<~[&[int]]>(), ~[&[2,3,4,5], &[]]); - assert_eq!(xs.rsplit_iter(|x| *x == 5).collect::<~[&[int]]>(), + assert_eq!(xs.rsplit(|x| *x == 5).collect::<~[&[int]]>(), ~[&[], &[1,2,3,4]]); - assert_eq!(xs.rsplit_iter(|x| *x == 10).collect::<~[&[int]]>(), + assert_eq!(xs.rsplit(|x| *x == 10).collect::<~[&[int]]>(), ~[&[1,2,3,4,5]]); let xs: &[int] = &[]; - assert_eq!(xs.rsplit_iter(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); + assert_eq!(xs.rsplit(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); } #[test] - fn test_rsplitn_iterator() { + fn test_rsplitnator() { let xs = &[1,2,3,4,5]; - assert_eq!(xs.rsplitn_iter(0, |x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[1,2,3,4,5]]); - assert_eq!(xs.rsplitn_iter(1, |x| *x % 2 == 0).collect::<~[&[int]]>(), + assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(), ~[&[5], &[1,2,3]]); - assert_eq!(xs.rsplitn_iter(3, |_| true).collect::<~[&[int]]>(), + assert_eq!(xs.rsplitn(3, |_| true).collect::<~[&[int]]>(), ~[&[], &[], &[], &[1,2]]); let xs: &[int] = &[]; - assert_eq!(xs.rsplitn_iter(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); + assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]); } #[test] - fn test_window_iterator() { + fn test_windowsator() { let v = &[1i,2,3,4]; - assert_eq!(v.window_iter(2).collect::<~[&[int]]>(), ~[&[1,2], &[2,3], &[3,4]]); - assert_eq!(v.window_iter(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[2,3,4]]); - assert!(v.window_iter(6).next().is_none()); + assert_eq!(v.windows(2).collect::<~[&[int]]>(), ~[&[1,2], &[2,3], &[3,4]]); + assert_eq!(v.windows(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[2,3,4]]); + assert!(v.windows(6).next().is_none()); } #[test] #[should_fail] - fn test_window_iterator_0() { + fn test_windowsator_0() { let v = &[1i,2,3,4]; - let _it = v.window_iter(0); + let _it = v.windows(0); } #[test] - fn test_chunk_iterator() { + fn test_chunksator() { let v = &[1i,2,3,4,5]; - assert_eq!(v.chunk_iter(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]); - assert_eq!(v.chunk_iter(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]); - assert_eq!(v.chunk_iter(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]); + assert_eq!(v.chunks(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]); + assert_eq!(v.chunks(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]); + assert_eq!(v.chunks(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]); - assert_eq!(v.chunk_iter(2).invert().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]); - let it = v.chunk_iter(2); + assert_eq!(v.chunks(2).invert().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]); + let it = v.chunks(2); assert_eq!(it.indexable(), 3); assert_eq!(it.idx(0).unwrap(), &[1,2]); assert_eq!(it.idx(1).unwrap(), &[3,4]); @@ -3630,9 +3635,9 @@ mod tests { #[test] #[should_fail] - fn test_chunk_iterator_0() { + fn test_chunksator_0() { let v = &[1i,2,3,4]; - let _it = v.chunk_iter(0); + let _it = v.chunks(0); } #[test] |
