@@ -640,19 +640,16 @@ impl str {
640
640
///
641
641
/// let v: Vec<&str> = "lion::tiger::leopard".split("::").collect();
642
642
/// assert_eq!(v, ["lion", "tiger", "leopard"]);
643
- ///
644
- /// let v: Vec<&str> = "abc1def2ghi".split(char::is_numeric).collect();
645
- /// assert_eq!(v, ["abc", "def", "ghi"]);
646
- ///
647
- /// let v: Vec<&str> = "lionXtigerXleopard".split(char::is_uppercase).collect();
648
- /// assert_eq!(v, ["lion", "tiger", "leopard"]);
649
643
/// ```
650
644
///
651
- /// A more complex pattern, using a closure :
645
+ /// More complex patterns with closures :
652
646
///
653
647
/// ```
654
- /// let v: Vec<&str> = "abc1defXghi ".split(|c| c == '1' || c == 'X' ).collect();
648
+ /// let v: Vec<&str> = "abc1def2ghi ".split(|c: char| c.is_numeric() ).collect();
655
649
/// assert_eq!(v, ["abc", "def", "ghi"]);
650
+ ///
651
+ /// let v: Vec<&str> = "lionXtigerXleopard".split(char::is_uppercase).collect();
652
+ /// assert_eq!(v, ["lion", "tiger", "leopard"]);
656
653
/// ```
657
654
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
658
655
pub fn split < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> Split < ' a , P > {
@@ -694,11 +691,14 @@ impl str {
694
691
/// assert_eq!(v, ["leopard", "tiger", "lion"]);
695
692
/// ```
696
693
///
697
- /// A more complex pattern, using a closure :
694
+ /// More complex patterns with closures :
698
695
///
699
- /// ```
700
- /// let v: Vec<&str> = "abc1defXghi ".rsplit(|c| c == '1' || c == 'X' ).collect();
696
+ /// ```rust
697
+ /// let v: Vec<&str> = "abc1def2ghi ".rsplit(|c: char| c.is_numeric() ).collect();
701
698
/// assert_eq!(v, ["ghi", "def", "abc"]);
699
+ ///
700
+ /// let v: Vec<&str> = "lionXtigerXleopard".rsplit(char::is_uppercase).collect();
701
+ /// assert_eq!(v, ["leopard", "tiger", "lion"]);
702
702
/// ```
703
703
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
704
704
pub fn rsplit < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> RSplit < ' a , P >
@@ -733,13 +733,22 @@ impl str {
733
733
///
734
734
/// # Examples
735
735
///
736
+ /// Simple patterns:
737
+ ///
736
738
/// ```
737
739
/// let v: Vec<&str> = "A.B.".split_terminator('.').collect();
738
740
/// assert_eq!(v, ["A", "B"]);
739
741
///
740
742
/// let v: Vec<&str> = "A..B..".split_terminator(".").collect();
741
743
/// assert_eq!(v, ["A", "", "B", ""]);
742
744
/// ```
745
+ ///
746
+ /// More complex patterns with closures:
747
+ ///
748
+ /// ```
749
+ /// let v: Vec<&str> = "abc1def2ghi3".split_terminator(|c: char| c.is_numeric()).collect();
750
+ /// assert_eq!(v, ["abc", "def", "ghi"]);
751
+ /// ```
743
752
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
744
753
pub fn split_terminator < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> SplitTerminator < ' a , P > {
745
754
core_str:: StrExt :: split_terminator ( & self [ ..] , pat)
@@ -769,13 +778,22 @@ impl str {
769
778
///
770
779
/// # Examples
771
780
///
781
+ /// Simple patterns:
782
+ ///
772
783
/// ```
773
784
/// let v: Vec<&str> = "A.B.".rsplit_terminator('.').collect();
774
785
/// assert_eq!(v, ["B", "A"]);
775
786
///
776
787
/// let v: Vec<&str> = "A..B..".rsplit_terminator(".").collect();
777
788
/// assert_eq!(v, ["", "B", "", "A"]);
778
789
/// ```
790
+ ///
791
+ /// More complex patterns with closures:
792
+ ///
793
+ /// ```
794
+ /// let v: Vec<&str> = "abc1def2ghi3".rsplit_terminator(|c: char| c.is_numeric()).collect();
795
+ /// assert_eq!(v, ["ghi", "def", "abc"]);
796
+ /// ```
779
797
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
780
798
pub fn rsplit_terminator < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> RSplitTerminator < ' a , P >
781
799
where P :: Searcher : ReverseSearcher < ' a >
@@ -819,11 +837,11 @@ impl str {
819
837
/// assert_eq!(v, [""]);
820
838
/// ```
821
839
///
822
- /// A more complex pattern, using a closure :
840
+ /// More complex patterns with closures :
823
841
///
824
842
/// ```
825
- /// let v: Vec<&str> = "abc1defXghi ".splitn(2, |c| c == '1' || c == 'X' ).collect();
826
- /// assert_eq!(v, ["abc", "defXghi "]);
843
+ /// let v: Vec<&str> = "abc1def2ghi ".splitn(2, |c: char| c.is_numeric() ).collect();
844
+ /// assert_eq!(v, ["abc", "def2ghi "]);
827
845
/// ```
828
846
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
829
847
pub fn splitn < ' a , P : Pattern < ' a > > ( & ' a self , count : usize , pat : P ) -> SplitN < ' a , P > {
@@ -864,10 +882,10 @@ impl str {
864
882
/// assert_eq!(v, ["leopard", "lion::tiger"]);
865
883
/// ```
866
884
///
867
- /// A more complex pattern, using a closure :
885
+ /// More complex patterns with closures :
868
886
///
869
887
/// ```
870
- /// let v: Vec<&str> = "abc1defXghi ".rsplitn(2, |c| c == '1' || c == 'X' ).collect();
888
+ /// let v: Vec<&str> = "abc1def2ghi ".rsplitn(2, |c: char| c.is_numeric() ).collect();
871
889
/// assert_eq!(v, ["ghi", "abc1def"]);
872
890
/// ```
873
891
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -902,7 +920,7 @@ impl str {
902
920
/// let v: Vec<&str> = "abcXXXabcYYYabc".matches("abc").collect();
903
921
/// assert_eq!(v, ["abc", "abc", "abc"]);
904
922
///
905
- /// let v: Vec<&str> = "1abc2abc3".matches(char:: is_numeric).collect();
923
+ /// let v: Vec<&str> = "1abc2abc3".matches(|c: char| c. is_numeric() ).collect();
906
924
/// assert_eq!(v, ["1", "2", "3"]);
907
925
/// ```
908
926
#[ unstable( feature = "collections" ,
@@ -935,7 +953,7 @@ impl str {
935
953
/// let v: Vec<&str> = "abcXXXabcYYYabc".rmatches("abc").collect();
936
954
/// assert_eq!(v, ["abc", "abc", "abc"]);
937
955
///
938
- /// let v: Vec<&str> = "1abc2abc3".rmatches(char:: is_numeric).collect();
956
+ /// let v: Vec<&str> = "1abc2abc3".rmatches(|c: char| c. is_numeric() ).collect();
939
957
/// assert_eq!(v, ["3", "2", "1"]);
940
958
/// ```
941
959
#[ unstable( feature = "collections" ,
@@ -1181,16 +1199,15 @@ impl str {
1181
1199
///
1182
1200
/// ```
1183
1201
/// assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar");
1184
- /// assert_eq!("123foo1bar123".trim_matches(char::is_numeric), "foo1bar");
1185
1202
///
1186
1203
/// let x: &[_] = &['1', '2'];
1187
1204
/// assert_eq!("12foo1bar12".trim_matches(x), "foo1bar");
1188
1205
/// ```
1189
1206
///
1190
- /// A more complex pattern, using a closure :
1207
+ /// More complex patterns with closures :
1191
1208
///
1192
1209
/// ```
1193
- /// assert_eq!("1foo1barXX ".trim_matches(|c| c == '1' || c == 'X' ), "foo1bar");
1210
+ /// assert_eq!("123foo1bar123 ".trim_matches(|c: char| c.is_numeric() ), "foo1bar");
1194
1211
/// ```
1195
1212
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1196
1213
pub fn trim_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
@@ -1207,13 +1224,20 @@ impl str {
1207
1224
///
1208
1225
/// # Examples
1209
1226
///
1227
+ /// Simple patterns:
1228
+ ///
1210
1229
/// ```
1211
1230
/// assert_eq!("11foo1bar11".trim_left_matches('1'), "foo1bar11");
1212
- /// assert_eq!("123foo1bar123".trim_left_matches(char::is_numeric), "foo1bar123");
1213
1231
///
1214
1232
/// let x: &[_] = &['1', '2'];
1215
1233
/// assert_eq!("12foo1bar12".trim_left_matches(x), "foo1bar12");
1216
1234
/// ```
1235
+ ///
1236
+ /// More complex patterns with closures:
1237
+ ///
1238
+ /// ```
1239
+ /// assert_eq!("123foo1bar123".trim_left_matches(|c: char| c.is_numeric()), "foo1bar123");
1240
+ /// ```
1217
1241
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1218
1242
pub fn trim_left_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str {
1219
1243
core_str:: StrExt :: trim_left_matches ( & self [ ..] , pat)
@@ -1231,16 +1255,14 @@ impl str {
1231
1255
///
1232
1256
/// ```
1233
1257
/// assert_eq!("11foo1bar11".trim_right_matches('1'), "11foo1bar");
1234
- /// assert_eq!("123foo1bar123".trim_right_matches(char::is_numeric), "123foo1bar");
1235
- ///
1236
1258
/// let x: &[_] = &['1', '2'];
1237
1259
/// assert_eq!("12foo1bar12".trim_right_matches(x), "12foo1bar");
1238
1260
/// ```
1239
1261
///
1240
- /// A more complex pattern, using a closure :
1262
+ /// More complex patterns with closures :
1241
1263
///
1242
1264
/// ```
1243
- /// assert_eq!("1fooX".trim_left_matches (|c| c == '1' || c == 'X') , "fooX ");
1265
+ /// assert_eq!("123foo1bar123".trim_right_matches (|c: char| c.is_numeric()) , "123foo1bar ");
1244
1266
/// ```
1245
1267
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1246
1268
pub fn trim_right_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
@@ -1477,7 +1499,7 @@ impl str {
1477
1499
/// ```
1478
1500
/// let s = "Löwe 老虎 Léopard";
1479
1501
///
1480
- /// assert_eq!(s.find(char:: is_whitespace), Some(5));
1502
+ /// assert_eq!(s.find(|c: char| c. is_whitespace() ), Some(5));
1481
1503
/// assert_eq!(s.find(char::is_lowercase), Some(1));
1482
1504
/// ```
1483
1505
///
@@ -1519,7 +1541,7 @@ impl str {
1519
1541
/// ```
1520
1542
/// let s = "Löwe 老虎 Léopard";
1521
1543
///
1522
- /// assert_eq!(s.rfind(char:: is_whitespace), Some(12));
1544
+ /// assert_eq!(s.rfind(|c: char| c. is_whitespace() ), Some(12));
1523
1545
/// assert_eq!(s.rfind(char::is_lowercase), Some(20));
1524
1546
/// ```
1525
1547
///
0 commit comments