Skip to content

Commit c04f22a

Browse files
committed
Refactored core::str::pattern to become a user-facing module and hide away
CharEq.
1 parent 91d1aa7 commit c04f22a

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/libcollections/str.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ use core::iter::{Iterator, Extend};
5858
use core::option::Option::{self, Some, None};
5959
use core::result::Result;
6060
use core::str as core_str;
61+
use core::str::pattern::Pattern;
62+
use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
6163
use unicode::str::{UnicodeStr, Utf16Encoder};
6264

6365
use core::convert::AsRef;
@@ -78,8 +80,7 @@ pub use core::str::{MatchIndices, RMatchIndices};
7880
pub use core::str::{from_utf8, Chars, CharIndices, Bytes};
7981
pub use core::str::{from_utf8_unchecked, ParseBoolError};
8082
pub use unicode::str::{Words, Graphemes, GraphemeIndices};
81-
pub use core::str::Pattern;
82-
pub use core::str::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
83+
pub use core::str::pattern;
8384

8485
/*
8586
Section: Creating a string

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use core::mem;
2424
use core::ops::{self, Deref, Add, Index};
2525
use core::ptr;
2626
use core::slice;
27-
use core::str::Pattern;
27+
use core::str::pattern::Pattern;
2828
use unicode::str as unicode_str;
2929
use unicode::str::Utf16Item;
3030

src/libcore/str/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#![doc(primitive = "str")]
1818

1919
use self::OldSearcher::{TwoWay, TwoWayLong};
20+
use self::pattern::Pattern;
21+
use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
2022

2123
use char::CharExt;
2224
use clone::Clone;
@@ -34,10 +36,7 @@ use result::Result::{self, Ok, Err};
3436
use slice::{self, SliceExt};
3537
use usize;
3638

37-
pub use self::pattern::Pattern;
38-
pub use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
39-
40-
mod pattern;
39+
pub mod pattern;
4140

4241
/// A trait to abstract the idea of creating a new instance of a type from a
4342
/// string.

src/libcore/str/pattern.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,29 +471,28 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
471471

472472
macro_rules! pattern_methods {
473473
($t:ty, $pmap:expr, $smap:expr) => {
474-
// FIXME: #22463
475-
//type Searcher = $t;
474+
type Searcher = $t;
476475

477476
#[inline]
478477
fn into_searcher(self, haystack: &'a str) -> $t {
479-
$smap($pmap(self).into_searcher(haystack))
478+
($smap)(($pmap)(self).into_searcher(haystack))
480479
}
481480

482481
#[inline]
483482
fn is_contained_in(self, haystack: &'a str) -> bool {
484-
$pmap(self).is_contained_in(haystack)
483+
($pmap)(self).is_contained_in(haystack)
485484
}
486485

487486
#[inline]
488487
fn is_prefix_of(self, haystack: &'a str) -> bool {
489-
$pmap(self).is_prefix_of(haystack)
488+
($pmap)(self).is_prefix_of(haystack)
490489
}
491490

492491
#[inline]
493492
fn is_suffix_of(self, haystack: &'a str) -> bool
494493
where $t: ReverseSearcher<'a>
495494
{
496-
$pmap(self).is_suffix_of(haystack)
495+
($pmap)(self).is_suffix_of(haystack)
497496
}
498497
}
499498
}
@@ -553,7 +552,6 @@ impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
553552

554553
/// Searches for chars that are equal to a given char
555554
impl<'a> Pattern<'a> for char {
556-
type Searcher = CharSearcher<'a>;
557555
pattern_methods!(CharSearcher<'a>, CharEqPattern, CharSearcher);
558556
}
559557

@@ -579,7 +577,6 @@ impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
579577

580578
/// Searches for chars that are equal to any of the chars in the array
581579
impl<'a, 'b> Pattern<'a> for &'b [char] {
582-
type Searcher = CharSliceSearcher<'a, 'b>;
583580
pattern_methods!(CharSliceSearcher<'a, 'b>, CharEqPattern, CharSliceSearcher);
584581
}
585582

@@ -609,6 +606,14 @@ impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F>
609606

610607
/// Searches for chars that match the given predicate
611608
impl<'a, F> Pattern<'a> for F where F: FnMut(char) -> bool {
612-
type Searcher = CharPredicateSearcher<'a, F>;
613609
pattern_methods!(CharPredicateSearcher<'a, F>, CharEqPattern, CharPredicateSearcher);
614610
}
611+
612+
/////////////////////////////////////////////////////////////////////////////
613+
// Impl for &&str
614+
/////////////////////////////////////////////////////////////////////////////
615+
616+
/// Delegates to the `&str` impl.
617+
impl<'a, 'b> Pattern<'a> for &'b &'b str {
618+
pattern_methods!(StrSearcher<'a, 'b>, |&s| s, |s| s);
619+
}

src/libcoretest/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ fn trim_ws() {
185185
}
186186

187187
mod pattern {
188-
use std::str::Pattern;
189-
use std::str::{Searcher, ReverseSearcher};
190-
use std::str::SearchStep::{self, Match, Reject, Done};
188+
use std::str::pattern::Pattern;
189+
use std::str::pattern::{Searcher, ReverseSearcher};
190+
use std::str::pattern::SearchStep::{self, Match, Reject, Done};
191191

192192
macro_rules! make_test {
193193
($name:ident, $p:expr, $h:expr, [$($e:expr,)*]) => {
194194
mod $name {
195-
use std::str::SearchStep::{Match, Reject};
195+
use std::str::pattern::SearchStep::{Match, Reject};
196196
use super::{cmp_search_to_vec};
197197
#[test]
198198
fn fwd() {

0 commit comments

Comments
 (0)