From bc09c1ddc5604642926428d69f2ebd7557b3230b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Wed, 14 Jan 2015 19:34:39 +0100 Subject: [PATCH] Made str::MatchIndices a private implementantion detail --- src/libcore/str/mod.rs | 30 ++++++++++++++++++++++-------- src/libcore/str/pattern.rs | 4 ++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index fb0c4c4f34f..cbd103ee765 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -931,29 +931,43 @@ impl Searcher { } } -/// An iterator over the start and end indices of the matches of a -/// substring within a larger string #[derive(Clone)] #[unstable(feature = "core", reason = "type may be removed")] -pub struct MatchIndices<'a> { +struct OldMatchIndices<'a> { // constants haystack: &'a str, needle: &'a str, searcher: Searcher } +/// An iterator over the start and end indices of the matches of a +/// substring within a larger string +#[derive(Clone)] +#[unstable(feature = "core", reason = "type may be removed")] +pub struct MatchIndices<'a>(OldMatchIndices<'a>); + +#[stable] +impl<'a> Iterator for MatchIndices<'a> { + type Item = (uint, uint); + + #[inline] + fn next(&mut self) -> Option<(uint, uint)> { + self.0.next() + } +} + /// An iterator over the substrings of a string separated by a given /// search string #[derive(Clone)] #[unstable(feature = "core", reason = "type may be removed")] pub struct SplitStr<'a> { - it: MatchIndices<'a>, + it: OldMatchIndices<'a>, last_end: uint, finished: bool } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Iterator for MatchIndices<'a> { +impl<'a> Iterator for OldMatchIndices<'a> { type Item = (uint, uint); #[inline] @@ -1465,17 +1479,17 @@ impl StrExt for str { #[inline] fn match_indices<'a>(&'a self, sep: &'a str) -> MatchIndices<'a> { - MatchIndices { + MatchIndices(OldMatchIndices { haystack: self, needle: sep, searcher: Searcher::new(self.as_bytes(), sep.as_bytes()) - } + }) } #[inline] fn split_str<'a>(&'a self, sep: &'a str) -> SplitStr<'a> { SplitStr { - it: self.match_indices(sep), + it: self.match_indices(sep).0, last_end: 0, finished: false } diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 13b0d1df45e..4eff47f3820 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -84,14 +84,14 @@ impl<'a, C: CharEq> DoubleEndedMatcher<'a> for CharEqMatcher<'a, C> {} // Impl for &str -struct StrMatcher<'a>(super::MatchIndices<'a>); +struct StrMatcher<'a>(super::OldMatchIndices<'a>); impl<'a> Pattern<'a> for &'a str { type Matcher = StrMatcher<'a>; #[inline] fn into_matcher(self, haystack: &'a str) -> StrMatcher<'a> { - let mi = super::MatchIndices { + let mi = super::OldMatchIndices { haystack: haystack, needle: self, searcher: super::Searcher::new(haystack.as_bytes(), self.as_bytes())