@@ -82,6 +82,8 @@ pub use core::str::{SplitN, RSplitN};
8282pub use core:: str:: { from_utf8, CharEq , Chars , CharIndices , Bytes } ;
8383pub use core:: str:: { from_utf8_unchecked, from_c_str, ParseBoolError } ;
8484pub use unicode:: str:: { Words , Graphemes , GraphemeIndices } ;
85+ pub use core:: str:: Pattern ;
86+ pub use core:: str:: { Searcher , ReverseSearcher , DoubleEndedSearcher , SearchStep } ;
8587
8688/*
8789Section: 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
@@ -545,9 +547,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
545547 /// ```rust
546548 /// assert!("hello".contains_char('e'));
547549 /// ```
548- #[ unstable( feature = "collections" ,
549- reason = "might get removed in favour of a more generic contains() " ) ]
550- fn contains_char < P : CharEq > ( & self , pat : P ) -> bool {
550+ #[ unstable( feature = "collections" ) ]
551+ # [ deprecated ( since = "1.0.0" , reason = "use `contains()` with a char " ) ]
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
@@ -658,8 +660,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
658660 /// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
659661 /// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
660662 /// ```
661- #[ unstable ( feature = "collections " , reason = "might get removed " ) ]
662- fn split_terminator < P : CharEq > ( & self , pat : P ) -> SplitTerminator < P > {
663+ #[ stable ( feature = "rust1 " , since = "1.0.0 " ) ]
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,9 @@ 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 > ( & ' a self , pat : & ' a str ) -> MatchIndices < ' a > {
711+ // NB: Right now MatchIndices yields `(usize, usize)`,
712+ // but it would be more consistent and useful to return `(usize, &str)`
713+ fn match_indices < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> MatchIndices < ' a , P > {
710714 core_str:: StrExt :: match_indices ( & self [ ..] , pat)
711715 }
712716
@@ -721,9 +725,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
721725 /// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
722726 /// assert_eq!(v, vec!["1", "", "2"]);
723727 /// ```
724- #[ unstable( feature = "collections" ,
725- reason = "might get removed in the future in favor of a more generic split() " ) ]
726- fn split_str < ' a > ( & ' a self , pat : & ' a str ) -> SplitStr < ' a > {
728+ #[ unstable( feature = "collections" ) ]
729+ # [ deprecated ( since = "1.0.0" , reason = "use `split()` with a `&str` " ) ]
730+ fn split_str < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> SplitStr < ' a , P > {
727731 core_str:: StrExt :: split_str ( & self [ ..] , pat)
728732 }
729733
@@ -825,7 +829,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
825829 /// assert!("banana".starts_with("ba"));
826830 /// ```
827831 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
828- fn starts_with ( & self , pat : & str ) -> bool {
832+ fn starts_with < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> bool {
829833 core_str:: StrExt :: starts_with ( & self [ ..] , pat)
830834 }
831835
@@ -837,7 +841,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
837841 /// assert!("banana".ends_with("nana"));
838842 /// ```
839843 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
840- fn ends_with ( & self , pat : & str ) -> bool {
844+ fn ends_with < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> bool
845+ where P :: Searcher : ReverseSearcher < ' a >
846+ {
841847 core_str:: StrExt :: ends_with ( & self [ ..] , pat)
842848 }
843849
@@ -857,7 +863,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
857863 /// assert_eq!("123foo1bar123".trim_matches(|c: char| c.is_numeric()), "foo1bar");
858864 /// ```
859865 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
860- fn trim_matches < P : CharEq > ( & self , pat : P ) -> & str {
866+ fn trim_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
867+ where P :: Searcher : DoubleEndedSearcher < ' a >
868+ {
861869 core_str:: StrExt :: trim_matches ( & self [ ..] , pat)
862870 }
863871
@@ -877,7 +885,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
877885 /// assert_eq!("123foo1bar123".trim_left_matches(|c: char| c.is_numeric()), "foo1bar123");
878886 /// ```
879887 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
880- fn trim_left_matches < P : CharEq > ( & self , pat : P ) -> & str {
888+ fn trim_left_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str {
881889 core_str:: StrExt :: trim_left_matches ( & self [ ..] , pat)
882890 }
883891
@@ -897,7 +905,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
897905 /// assert_eq!("123foo1bar123".trim_right_matches(|c: char| c.is_numeric()), "123foo1bar");
898906 /// ```
899907 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
900- fn trim_right_matches < P : CharEq > ( & self , pat : P ) -> & str {
908+ fn trim_right_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
909+ where P :: Searcher : ReverseSearcher < ' a >
910+ {
901911 core_str:: StrExt :: trim_right_matches ( & self [ ..] , pat)
902912 }
903913
@@ -1074,7 +1084,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
10741084 /// assert_eq!(s.find(x), None);
10751085 /// ```
10761086 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1077- fn find < P : CharEq > ( & self , pat : P ) -> Option < usize > {
1087+ fn find < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> Option < usize > {
10781088 core_str:: StrExt :: find ( & self [ ..] , pat)
10791089 }
10801090
@@ -1102,7 +1112,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
11021112 /// assert_eq!(s.rfind(x), None);
11031113 /// ```
11041114 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1105- fn rfind < P : CharEq > ( & self , pat : P ) -> Option < usize > {
1115+ fn rfind < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> Option < usize >
1116+ where P :: Searcher : ReverseSearcher < ' a >
1117+ {
11061118 core_str:: StrExt :: rfind ( & self [ ..] , pat)
11071119 }
11081120
@@ -1125,9 +1137,9 @@ pub trait StrExt: Index<RangeFull, Output = str> {
11251137 /// assert_eq!(s.find_str("老虎 L"), Some(6));
11261138 /// assert_eq!(s.find_str("muffin man"), None);
11271139 /// ```
1128- #[ unstable( feature = "collections" ,
1129- reason = "might get removed in favor of a more generic find in the future " ) ]
1130- fn find_str ( & self , needle : & str ) -> Option < usize > {
1140+ #[ unstable( feature = "collections" ) ]
1141+ # [ deprecated ( since = "1.0.0" , reason = "use `find()` with a `&str` " ) ]
1142+ fn find_str < ' a , P : Pattern < ' a > > ( & ' a self , needle : P ) -> Option < usize > {
11311143 core_str:: StrExt :: find_str ( & self [ ..] , needle)
11321144 }
11331145
@@ -2887,22 +2899,6 @@ mod bench {
28872899 b. iter ( || assert_eq ! ( s. split( 'V' ) . count( ) , 3 ) ) ;
28882900 }
28892901
2890- #[ bench]
2891- fn split_unicode_not_ascii ( b : & mut Bencher ) {
2892- struct NotAscii ( char ) ;
2893- impl CharEq for NotAscii {
2894- fn matches ( & mut self , c : char ) -> bool {
2895- let NotAscii ( cc) = * self ;
2896- cc == c
2897- }
2898- fn only_ascii ( & self ) -> bool { false }
2899- }
2900- let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam" ;
2901-
2902- b. iter ( || assert_eq ! ( s. split( NotAscii ( 'V' ) ) . count( ) , 3 ) ) ;
2903- }
2904-
2905-
29062902 #[ bench]
29072903 fn split_ascii ( b : & mut Bencher ) {
29082904 let s = "Mary had a little lamb, Little lamb, little-lamb." ;
@@ -2911,23 +2907,6 @@ mod bench {
29112907 b. iter ( || assert_eq ! ( s. split( ' ' ) . count( ) , len) ) ;
29122908 }
29132909
2914- #[ bench]
2915- fn split_not_ascii ( b : & mut Bencher ) {
2916- struct NotAscii ( char ) ;
2917- impl CharEq for NotAscii {
2918- #[ inline]
2919- fn matches ( & mut self , c : char ) -> bool {
2920- let NotAscii ( cc) = * self ;
2921- cc == c
2922- }
2923- fn only_ascii ( & self ) -> bool { false }
2924- }
2925- let s = "Mary had a little lamb, Little lamb, little-lamb." ;
2926- let len = s. split ( ' ' ) . count ( ) ;
2927-
2928- b. iter ( || assert_eq ! ( s. split( NotAscii ( ' ' ) ) . count( ) , len) ) ;
2929- }
2930-
29312910 #[ bench]
29322911 fn split_extern_fn ( b : & mut Bencher ) {
29332912 let s = "Mary had a little lamb, Little lamb, little-lamb." ;
0 commit comments