diff options
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/posix.rs | 23 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 14 |
2 files changed, 11 insertions, 26 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 4affea37e35..eceeb73a015 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -16,11 +16,11 @@ use clone::Clone; use cmp::{Eq, TotalEq}; use from_str::FromStr; use io::Writer; -use iter::{AdditiveIterator, Extendable, Iterator, Map}; +use iter::{DoubleEndedIterator, Rev, AdditiveIterator, Extendable, Iterator, Map}; use option::{Option, None, Some}; use str; use str::Str; -use slice::{CloneableVector, RevSplits, Splits, Vector, VectorVector, +use slice::{CloneableVector, Splits, Vector, VectorVector, ImmutableEqVector, OwnedVector, ImmutableVector}; use vec::Vec; @@ -29,14 +29,13 @@ use super::{BytesContainer, GenericPath, GenericPathUnsafe}; /// Iterator that yields successive components of a Path as &[u8] pub type Components<'a> = Splits<'a, u8>; /// Iterator that yields components of a Path in reverse as &[u8] -pub type RevComponents<'a> = RevSplits<'a, u8>; +pub type RevComponents<'a> = Rev<Components<'a>>; /// Iterator that yields successive components of a Path as Option<&str> pub type StrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>, Components<'a>>; /// Iterator that yields components of a Path in reverse as Option<&str> -pub type RevStrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>, - RevComponents<'a>>; +pub type RevStrComponents<'a> = Rev<StrComponents<'a>>; /// Represents a POSIX file path #[deriving(Clone)] @@ -397,15 +396,7 @@ impl Path { /// Returns an iterator that yields each component of the path in reverse. /// See components() for details. pub fn rev_components<'a>(&'a self) -> RevComponents<'a> { - let v = if *self.repr.get(0) == SEP_BYTE { - self.repr.slice_from(1) - } else { self.repr.as_slice() }; - let mut ret = v.rsplit(is_sep_byte); - if v.is_empty() { - // consume the empty "" component - ret.next(); - } - ret + self.components().rev() } /// Returns an iterator that yields each component of the path as Option<&str>. @@ -417,7 +408,7 @@ impl Path { /// Returns an iterator that yields each component of the path in reverse as Option<&str>. /// See components() for details. pub fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a> { - self.rev_components().map(str::from_utf8) + self.str_components().rev() } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 74ca8dc5785..679075fe6ca 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -37,15 +37,13 @@ pub type StrComponents<'a> = Map<'a, &'a str, Option<&'a str>, /// /// Each component is yielded as Option<&str> for compatibility with PosixPath, but /// every component in WindowsPath is guaranteed to be Some. -pub type RevStrComponents<'a> = Rev<Map<'a, &'a str, Option<&'a str>, - CharSplits<'a, char>>>; +pub type RevStrComponents<'a> = Rev<StrComponents<'a>>; /// Iterator that yields successive components of a Path as &[u8] pub type Components<'a> = Map<'a, Option<&'a str>, &'a [u8], StrComponents<'a>>; /// Iterator that yields components of a Path in reverse as &[u8] -pub type RevComponents<'a> = Map<'a, Option<&'a str>, &'a [u8], - RevStrComponents<'a>>; +pub type RevComponents<'a> = Rev<Components<'a>>; /// Represents a Windows path // Notes for Windows path impl: @@ -650,11 +648,7 @@ impl Path { /// Returns an iterator that yields each component of the path in reverse as a &[u8]. /// See str_components() for details. pub fn rev_components<'a>(&'a self) -> RevComponents<'a> { - fn convert<'a>(x: Option<&'a str>) -> &'a [u8] { - #![inline] - x.unwrap().as_bytes() - } - self.rev_str_components().map(convert) + self.components().rev() } fn equiv_prefix(&self, other: &Path) -> bool { |
