about summary refs log tree commit diff
path: root/src/libstd/path
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-26 01:07:40 -0800
committerbors <bors@rust-lang.org>2013-11-26 01:07:40 -0800
commit21990cdda624f5eee340311b7f8e542ab8a218e1 (patch)
tree567d9df8a078d09fc610ea3e0b301f5cb6fb63d8 /src/libstd/path
parentb42c4388927db75f9a38edbeafbfe13775b1773d (diff)
parent24b316a3b9567cb2cc2fb6644bd891dbf8855c18 (diff)
downloadrust-21990cdda624f5eee340311b7f8e542ab8a218e1.tar.gz
rust-21990cdda624f5eee340311b7f8e542ab8a218e1.zip
auto merge of #10622 : Kimundi/rust/str_de_iter, r=alexcrichton
This PR removes almost all `_iter` suffixes in various APIs of the codebase that return Iterators, as discussed in #9440.

As a summarize for the intend behind this PR:

- Iterators are the recommended way to provide a potentially lazy list of values, no need to name them painfully verbose. If anything, functions that return a specific container type should have more verbose names.
- We have a static type system, so no need to encode the return value of a constructor function into its name.

Following is a possibly incomplete list of all renamings I performed in the codebase. For a few of them I'm a bit unsure whether the new name still properly expresses their functionality, so feedback would be welcome:

~~~
&str : word_iter()             -> words()
       line_iter()             -> lines()
       any_line_iter()         -> lines_any()
       iter()                  -> chars()
       char_offset_iter()      -> char_indices()
       byte_iter()             -> bytes()
       split_iter()            -> split()
       splitn_iter()           -> splitn()
       split_str_iter()        -> split_str()
       split_terminator_iter() -> split_terminator()
       matches_index_iter()    -> match_indices()
       nfd_iter()              -> nfd_chars()
       nfkd_iter()             -> nfkd_chars()
      
&[T] : split_iter()        -> split()
       splitn_iter()       -> splitn()
       window_iter()       -> windows()
       chunk_iter()        -> chunks()
       permutations_iter() -> permutations()
      
extra:bitv::Bitv :  rev_liter()    -> rev_iter()
                    common_iter()  -> commons()
                    outlier_iter() -> outliers()

extra::treemap::{...} : lower_bound_iter() -> lower_bound()
                        upper_bound_iter() -> upper_bound()
                       
std::trie::{...} : bound_iter()       -> bound()
                   lower_bound_iter() -> lower_bound()
                   upper_bound_iter() -> upper_bound()

rustpkg::package_id::{...} : prefixes_iter() -> prefixes()

std::hashmap::{...} : difference_iter()           -> difference()
                      symmetric_difference_iter() -> symmetric_difference()
                      intersection_iter()         -> intersection()
                      union_iter()                -> union()
                     
std::path::{posix, windows} : component_iter()     -> components()
                              str_component_iter() -> str_components()

... not showing all identical renamings for reverse versions
~~~

---

I'm also planning a few more changes, like removing all unnecessary `_rev` constructors (#9391), or reducing the `split` variants on `&str` to a more versatile and concise system.
Diffstat (limited to 'src/libstd/path')
-rw-r--r--src/libstd/path/mod.rs2
-rw-r--r--src/libstd/path/posix.rs66
-rw-r--r--src/libstd/path/windows.rs66
3 files changed, 67 insertions, 67 deletions
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
     }
 }