@@ -82,6 +82,8 @@ pub use core::str::{SplitN, RSplitN};
82
82
pub use core:: str:: { from_utf8, CharEq , Chars , CharIndices , Bytes } ;
83
83
pub use core:: str:: { from_utf8_unchecked, from_c_str, ParseBoolError } ;
84
84
pub use unicode:: str:: { Words , Graphemes , GraphemeIndices } ;
85
+ pub use core:: str:: Pattern ;
86
+ pub use core:: str:: { Searcher , ReverseSearcher , DoubleEndedSearcher , SearchStep } ;
85
87
86
88
/*
87
89
Section: Creating a string
@@ -530,7 +532,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
530
532
/// assert!("bananas".contains("nana"));
531
533
/// ```
532
534
#[ 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 {
534
536
core_str:: StrExt :: contains ( & self [ ..] , pat)
535
537
}
536
538
@@ -547,7 +549,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
547
549
/// ```
548
550
#[ unstable( feature = "collections" ,
549
551
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 {
551
553
core_str:: StrExt :: contains_char ( & self [ ..] , pat)
552
554
}
553
555
@@ -603,7 +605,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
603
605
/// assert_eq!(v, vec![""]);
604
606
/// ```
605
607
#[ 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 > {
607
609
core_str:: StrExt :: split ( & self [ ..] , pat)
608
610
}
609
611
@@ -630,7 +632,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
630
632
/// assert_eq!(v, vec![""]);
631
633
/// ```
632
634
#[ 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 > {
634
636
core_str:: StrExt :: splitn ( & self [ ..] , count, pat)
635
637
}
636
638
@@ -659,7 +661,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
659
661
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
660
662
/// ```
661
663
#[ 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 > {
663
665
core_str:: StrExt :: split_terminator ( & self [ ..] , pat)
664
666
}
665
667
@@ -680,7 +682,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
680
682
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
681
683
/// ```
682
684
#[ 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 > {
684
686
core_str:: StrExt :: rsplitn ( & self [ ..] , count, pat)
685
687
}
686
688
@@ -706,7 +708,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
706
708
/// ```
707
709
#[ unstable( feature = "collections" ,
708
710
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 > {
710
712
core_str:: StrExt :: match_indices ( & self [ ..] , pat)
711
713
}
712
714
@@ -723,7 +725,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
723
725
/// ```
724
726
#[ unstable( feature = "collections" ,
725
727
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 > {
727
729
core_str:: StrExt :: split_str ( & self [ ..] , pat)
728
730
}
729
731
@@ -825,7 +827,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
825
827
/// assert!("banana".starts_with("ba"));
826
828
/// ```
827
829
#[ 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 {
829
831
core_str:: StrExt :: starts_with ( & self [ ..] , pat)
830
832
}
831
833
@@ -837,7 +839,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
837
839
/// assert!("banana".ends_with("nana"));
838
840
/// ```
839
841
#[ 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 > {
841
844
core_str:: StrExt :: ends_with ( & self [ ..] , pat)
842
845
}
843
846
@@ -857,7 +860,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
857
860
/// assert_eq!("123foo1bar123".trim_matches(|c: char| c.is_numeric()), "foo1bar");
858
861
/// ```
859
862
#[ 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 > {
861
865
core_str:: StrExt :: trim_matches ( & self [ ..] , pat)
862
866
}
863
867
@@ -877,7 +881,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
877
881
/// assert_eq!("123foo1bar123".trim_left_matches(|c: char| c.is_numeric()), "foo1bar123");
878
882
/// ```
879
883
#[ 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 {
881
885
core_str:: StrExt :: trim_left_matches ( & self [ ..] , pat)
882
886
}
883
887
@@ -897,7 +901,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
897
901
/// assert_eq!("123foo1bar123".trim_right_matches(|c: char| c.is_numeric()), "123foo1bar");
898
902
/// ```
899
903
#[ 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 > {
901
906
core_str:: StrExt :: trim_right_matches ( & self [ ..] , pat)
902
907
}
903
908
@@ -1074,7 +1079,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
1074
1079
/// assert_eq!(s.find(x), None);
1075
1080
/// ```
1076
1081
#[ 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 > {
1078
1083
core_str:: StrExt :: find ( & self [ ..] , pat)
1079
1084
}
1080
1085
@@ -1102,7 +1107,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
1102
1107
/// assert_eq!(s.rfind(x), None);
1103
1108
/// ```
1104
1109
#[ 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 > {
1106
1112
core_str:: StrExt :: rfind ( & self [ ..] , pat)
1107
1113
}
1108
1114
@@ -1127,7 +1133,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
1127
1133
/// ```
1128
1134
#[ unstable( feature = "collections" ,
1129
1135
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 > {
1131
1137
core_str:: StrExt :: find_str ( & self [ ..] , needle)
1132
1138
}
1133
1139
0 commit comments