Skip to content

Commit ee930b0

Browse files
committed
Enabled new pattern API in the libstd facade
1 parent f9ef8cd commit ee930b0

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/libcollections/str.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub use core::str::{SplitN, RSplitN};
8282
pub use core::str::{from_utf8, CharEq, Chars, CharIndices, Bytes};
8383
pub use core::str::{from_utf8_unchecked, from_c_str, ParseBoolError};
8484
pub use unicode::str::{Words, Graphemes, GraphemeIndices};
85+
pub use core::str::Pattern;
86+
pub use core::str::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
8587

8688
/*
8789
Section: Creating a string
@@ -530,7 +532,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
530532
/// assert!("bananas".contains("nana"));
531533
/// ```
532534
#[stable(feature = "rust1", since = "1.0.0")]
533-
fn contains(&self, pat: &str) -> bool {
535+
fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
534536
core_str::StrExt::contains(&self[..], pat)
535537
}
536538

@@ -547,7 +549,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
547549
/// ```
548550
#[unstable(feature = "collections",
549551
reason = "might get removed in favour of a more generic contains()")]
550-
fn contains_char<P: CharEq>(&self, pat: P) -> bool {
552+
fn contains_char<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
551553
core_str::StrExt::contains_char(&self[..], pat)
552554
}
553555

@@ -603,7 +605,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
603605
/// assert_eq!(v, vec![""]);
604606
/// ```
605607
#[stable(feature = "rust1", since = "1.0.0")]
606-
fn split<P: CharEq>(&self, pat: P) -> Split<P> {
608+
fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
607609
core_str::StrExt::split(&self[..], pat)
608610
}
609611

@@ -630,7 +632,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
630632
/// assert_eq!(v, vec![""]);
631633
/// ```
632634
#[stable(feature = "rust1", since = "1.0.0")]
633-
fn splitn<P: CharEq>(&self, count: usize, pat: P) -> SplitN<P> {
635+
fn splitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> SplitN<'a, P> {
634636
core_str::StrExt::splitn(&self[..], count, pat)
635637
}
636638

@@ -659,7 +661,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
659661
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
660662
/// ```
661663
#[unstable(feature = "collections", reason = "might get removed")]
662-
fn split_terminator<P: CharEq>(&self, pat: P) -> SplitTerminator<P> {
664+
fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P> {
663665
core_str::StrExt::split_terminator(&self[..], pat)
664666
}
665667

@@ -680,7 +682,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
680682
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
681683
/// ```
682684
#[stable(feature = "rust1", since = "1.0.0")]
683-
fn rsplitn<P: CharEq>(&self, count: usize, pat: P) -> RSplitN<P> {
685+
fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P> {
684686
core_str::StrExt::rsplitn(&self[..], count, pat)
685687
}
686688

@@ -706,7 +708,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
706708
/// ```
707709
#[unstable(feature = "collections",
708710
reason = "might have its iterator type changed")]
709-
fn match_indices<'a, 'b>(&'a self, pat: &'b str) -> MatchIndices<'a, &'b str> {
711+
fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P> {
710712
core_str::StrExt::match_indices(&self[..], pat)
711713
}
712714

@@ -723,7 +725,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
723725
/// ```
724726
#[unstable(feature = "collections",
725727
reason = "might get removed in the future in favor of a more generic split()")]
726-
fn split_str<'a, 'b>(&'a self, pat: &'b str) -> SplitStr<'a, &'b str> {
728+
fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
727729
core_str::StrExt::split_str(&self[..], pat)
728730
}
729731

@@ -825,7 +827,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
825827
/// assert!("banana".starts_with("ba"));
826828
/// ```
827829
#[stable(feature = "rust1", since = "1.0.0")]
828-
fn starts_with(&self, pat: &str) -> bool {
830+
fn starts_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
829831
core_str::StrExt::starts_with(&self[..], pat)
830832
}
831833

@@ -837,7 +839,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
837839
/// assert!("banana".ends_with("nana"));
838840
/// ```
839841
#[stable(feature = "rust1", since = "1.0.0")]
840-
fn ends_with(&self, pat: &str) -> bool {
842+
fn ends_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool
843+
where P::Searcher: ReverseSearcher<'a> {
841844
core_str::StrExt::ends_with(&self[..], pat)
842845
}
843846

@@ -857,7 +860,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
857860
/// assert_eq!("123foo1bar123".trim_matches(|c: char| c.is_numeric()), "foo1bar");
858861
/// ```
859862
#[stable(feature = "rust1", since = "1.0.0")]
860-
fn trim_matches<P: CharEq>(&self, pat: P) -> &str {
863+
fn trim_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
864+
where P::Searcher: DoubleEndedSearcher<'a> {
861865
core_str::StrExt::trim_matches(&self[..], pat)
862866
}
863867

@@ -877,7 +881,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
877881
/// assert_eq!("123foo1bar123".trim_left_matches(|c: char| c.is_numeric()), "foo1bar123");
878882
/// ```
879883
#[stable(feature = "rust1", since = "1.0.0")]
880-
fn trim_left_matches<P: CharEq>(&self, pat: P) -> &str {
884+
fn trim_left_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str {
881885
core_str::StrExt::trim_left_matches(&self[..], pat)
882886
}
883887

@@ -897,7 +901,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
897901
/// assert_eq!("123foo1bar123".trim_right_matches(|c: char| c.is_numeric()), "123foo1bar");
898902
/// ```
899903
#[stable(feature = "rust1", since = "1.0.0")]
900-
fn trim_right_matches<P: CharEq>(&self, pat: P) -> &str {
904+
fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
905+
where P::Searcher: ReverseSearcher<'a> {
901906
core_str::StrExt::trim_right_matches(&self[..], pat)
902907
}
903908

@@ -1074,7 +1079,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
10741079
/// assert_eq!(s.find(x), None);
10751080
/// ```
10761081
#[stable(feature = "rust1", since = "1.0.0")]
1077-
fn find<P: CharEq>(&self, pat: P) -> Option<usize> {
1082+
fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> {
10781083
core_str::StrExt::find(&self[..], pat)
10791084
}
10801085

@@ -1102,7 +1107,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
11021107
/// assert_eq!(s.rfind(x), None);
11031108
/// ```
11041109
#[stable(feature = "rust1", since = "1.0.0")]
1105-
fn rfind<P: CharEq>(&self, pat: P) -> Option<usize> {
1110+
fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>
1111+
where P::Searcher: ReverseSearcher<'a> {
11061112
core_str::StrExt::rfind(&self[..], pat)
11071113
}
11081114

@@ -1127,7 +1133,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
11271133
/// ```
11281134
#[unstable(feature = "collections",
11291135
reason = "might get removed in favor of a more generic find in the future")]
1130-
fn find_str(&self, needle: &str) -> Option<usize> {
1136+
fn find_str<'a, P: Pattern<'a>>(&'a self, needle: P) -> Option<usize> {
11311137
core_str::StrExt::find_str(&self[..], needle)
11321138
}
11331139

0 commit comments

Comments
 (0)