about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarvin Löbel <loebel.marvin@gmail.com>2015-03-23 14:21:42 +0100
committerMarvin Löbel <loebel.marvin@gmail.com>2015-04-05 18:52:57 +0200
commitc04f22a667123b39f16452af6fa65c82b2f8c0a2 (patch)
tree6ccef6b45238353636227401ba0aeebb866bc8a7
parent91d1aa71f6c4317d91bc04a53213b04f13b09c44 (diff)
downloadrust-c04f22a667123b39f16452af6fa65c82b2f8c0a2.tar.gz
rust-c04f22a667123b39f16452af6fa65c82b2f8c0a2.zip
Refactored core::str::pattern to become a user-facing module and hide away
CharEq.
-rw-r--r--src/libcollections/str.rs5
-rw-r--r--src/libcollections/string.rs2
-rw-r--r--src/libcore/str/mod.rs7
-rw-r--r--src/libcore/str/pattern.rs23
-rw-r--r--src/libcoretest/str.rs8
5 files changed, 25 insertions, 20 deletions
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index 7c562baa82b..28ba7369d52 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -58,6 +58,8 @@ use core::iter::{Iterator, Extend};
 use core::option::Option::{self, Some, None};
 use core::result::Result;
 use core::str as core_str;
+use core::str::pattern::Pattern;
+use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
 use unicode::str::{UnicodeStr, Utf16Encoder};
 
 use core::convert::AsRef;
@@ -78,8 +80,7 @@ pub use core::str::{MatchIndices, RMatchIndices};
 pub use core::str::{from_utf8, Chars, CharIndices, Bytes};
 pub use core::str::{from_utf8_unchecked, ParseBoolError};
 pub use unicode::str::{Words, Graphemes, GraphemeIndices};
-pub use core::str::Pattern;
-pub use core::str::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
+pub use core::str::pattern;
 
 /*
 Section: Creating a string
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 7a772532091..178cf5fa3fe 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -24,7 +24,7 @@ use core::mem;
 use core::ops::{self, Deref, Add, Index};
 use core::ptr;
 use core::slice;
-use core::str::Pattern;
+use core::str::pattern::Pattern;
 use unicode::str as unicode_str;
 use unicode::str::Utf16Item;
 
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index d31c1e27466..107a3376277 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -17,6 +17,8 @@
 #![doc(primitive = "str")]
 
 use self::OldSearcher::{TwoWay, TwoWayLong};
+use self::pattern::Pattern;
+use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
 
 use char::CharExt;
 use clone::Clone;
@@ -34,10 +36,7 @@ use result::Result::{self, Ok, Err};
 use slice::{self, SliceExt};
 use usize;
 
-pub use self::pattern::Pattern;
-pub use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
-
-mod pattern;
+pub mod pattern;
 
 /// A trait to abstract the idea of creating a new instance of a type from a
 /// string.
diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs
index 0c2a58f3ca7..ef10fe5e707 100644
--- a/src/libcore/str/pattern.rs
+++ b/src/libcore/str/pattern.rs
@@ -471,29 +471,28 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
 
 macro_rules! pattern_methods {
     ($t:ty, $pmap:expr, $smap:expr) => {
-        // FIXME: #22463
-        //type Searcher = $t;
+        type Searcher = $t;
 
         #[inline]
         fn into_searcher(self, haystack: &'a str) -> $t {
-            $smap($pmap(self).into_searcher(haystack))
+            ($smap)(($pmap)(self).into_searcher(haystack))
         }
 
         #[inline]
         fn is_contained_in(self, haystack: &'a str) -> bool {
-            $pmap(self).is_contained_in(haystack)
+            ($pmap)(self).is_contained_in(haystack)
         }
 
         #[inline]
         fn is_prefix_of(self, haystack: &'a str) -> bool {
-            $pmap(self).is_prefix_of(haystack)
+            ($pmap)(self).is_prefix_of(haystack)
         }
 
         #[inline]
         fn is_suffix_of(self, haystack: &'a str) -> bool
             where $t: ReverseSearcher<'a>
         {
-            $pmap(self).is_suffix_of(haystack)
+            ($pmap)(self).is_suffix_of(haystack)
         }
     }
 }
@@ -553,7 +552,6 @@ impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
 
 /// Searches for chars that are equal to a given char
 impl<'a> Pattern<'a> for char {
-    type Searcher =  CharSearcher<'a>;
     pattern_methods!(CharSearcher<'a>, CharEqPattern, CharSearcher);
 }
 
@@ -579,7 +577,6 @@ impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
 
 /// Searches for chars that are equal to any of the chars in the array
 impl<'a, 'b> Pattern<'a> for &'b [char] {
-    type Searcher =  CharSliceSearcher<'a, 'b>;
     pattern_methods!(CharSliceSearcher<'a, 'b>, CharEqPattern, CharSliceSearcher);
 }
 
@@ -609,6 +606,14 @@ impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F>
 
 /// Searches for chars that match the given predicate
 impl<'a, F> Pattern<'a> for F where F: FnMut(char) -> bool {
-    type Searcher =  CharPredicateSearcher<'a, F>;
     pattern_methods!(CharPredicateSearcher<'a, F>, CharEqPattern, CharPredicateSearcher);
 }
+
+/////////////////////////////////////////////////////////////////////////////
+// Impl for &&str
+/////////////////////////////////////////////////////////////////////////////
+
+/// Delegates to the `&str` impl.
+impl<'a, 'b> Pattern<'a> for &'b &'b str {
+    pattern_methods!(StrSearcher<'a, 'b>, |&s| s, |s| s);
+}
diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs
index 5fce527d979..e6d6a32e3ec 100644
--- a/src/libcoretest/str.rs
+++ b/src/libcoretest/str.rs
@@ -185,14 +185,14 @@ fn trim_ws() {
 }
 
 mod pattern {
-    use std::str::Pattern;
-    use std::str::{Searcher, ReverseSearcher};
-    use std::str::SearchStep::{self, Match, Reject, Done};
+    use std::str::pattern::Pattern;
+    use std::str::pattern::{Searcher, ReverseSearcher};
+    use std::str::pattern::SearchStep::{self, Match, Reject, Done};
 
     macro_rules! make_test {
         ($name:ident, $p:expr, $h:expr, [$($e:expr,)*]) => {
             mod $name {
-                use std::str::SearchStep::{Match, Reject};
+                use std::str::pattern::SearchStep::{Match, Reject};
                 use super::{cmp_search_to_vec};
                 #[test]
                 fn fwd() {