@@ -80,12 +80,14 @@ use vec::Vec;
80
80
81
81
pub use core:: str:: { from_utf8, CharEq , Chars , CharIndices } ;
82
82
pub use core:: str:: { Bytes , CharSplits , is_utf8} ;
83
- pub use core:: str:: { CharSplitsN , Lines , LinesAny , MatchIndices , StrSplits } ;
83
+ pub use core:: str:: { CharSplitsN , Lines , LinesAny , MatchIndices , StrSplits , SplitStr } ;
84
84
pub use core:: str:: { CharRange } ;
85
85
pub use core:: str:: { FromStr , from_str, Utf8Error } ;
86
86
pub use core:: str:: Str ;
87
87
pub use core:: str:: { from_utf8_unchecked, from_c_str} ;
88
88
pub use unicode:: str:: { Words , Graphemes , GraphemeIndices } ;
89
+ pub use core:: str:: { Split , SplitTerminator } ;
90
+ pub use core:: str:: { SplitN , RSplitN } ;
89
91
90
92
// FIXME(conventions): ensure bit/char conventions are followed by str's API
91
93
@@ -721,7 +723,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
721
723
/// // not found, so no change.
722
724
/// assert_eq!(s.replace("cookie monster", "little lamb"), s);
723
725
/// ```
724
- #[ unstable = "awaiting pattern/matcher stabilization" ]
726
+ #[ stable ]
725
727
fn replace ( & self , from : & str , to : & str ) -> String {
726
728
let mut result = String :: new ( ) ;
727
729
let mut last_end = 0 ;
@@ -828,36 +830,36 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
828
830
}
829
831
}
830
832
831
- /// Returns true if one string contains another
833
+ /// Returns true if a string contains a string pattern.
832
834
///
833
835
/// # Arguments
834
836
///
835
- /// - needle - The string to look for
837
+ /// - pat - The string pattern to look for
836
838
///
837
839
/// # Example
838
840
///
839
841
/// ```rust
840
842
/// assert!("bananas".contains("nana"));
841
843
/// ```
842
- #[ unstable = "awaiting pattern/matcher stabilization" ]
843
- fn contains ( & self , needle : & str ) -> bool {
844
- core_str:: StrExt :: contains ( self [ ] , needle )
844
+ #[ stable ]
845
+ fn contains ( & self , pat : & str ) -> bool {
846
+ core_str:: StrExt :: contains ( self [ ] , pat )
845
847
}
846
848
847
- /// Returns true if a string contains a char.
849
+ /// Returns true if a string contains a char pattern .
848
850
///
849
851
/// # Arguments
850
852
///
851
- /// - needle - The char to look for
853
+ /// - pat - The char pattern to look for
852
854
///
853
855
/// # Example
854
856
///
855
857
/// ```rust
856
858
/// assert!("hello".contains_char('e'));
857
859
/// ```
858
- #[ unstable = "awaiting pattern/matcher stabilization " ]
859
- fn contains_char ( & self , needle : char ) -> bool {
860
- core_str:: StrExt :: contains_char ( self [ ] , needle )
860
+ #[ unstable = "might get removed in favour of a more generic contains() " ]
861
+ fn contains_char < P : CharEq > ( & self , pat : P ) -> bool {
862
+ core_str:: StrExt :: contains_char ( self [ ] , pat )
861
863
}
862
864
863
865
/// An iterator over the characters of `self`. Note, this iterates
@@ -894,7 +896,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
894
896
}
895
897
896
898
/// An iterator over substrings of `self`, separated by characters
897
- /// matched by `sep `.
899
+ /// matched by the pattern `pat `.
898
900
///
899
901
/// # Example
900
902
///
@@ -911,13 +913,13 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
911
913
/// let v: Vec<&str> = "".split('X').collect();
912
914
/// assert_eq!(v, vec![""]);
913
915
/// ```
914
- #[ unstable = "awaiting pattern/matcher stabilization" ]
915
- fn split < Sep : CharEq > ( & self , sep : Sep ) -> CharSplits < Sep > {
916
- core_str:: StrExt :: split ( self [ ] , sep )
916
+ #[ stable ]
917
+ fn split < P : CharEq > ( & self , pat : P ) -> Split < P > {
918
+ core_str:: StrExt :: split ( self [ ] , pat )
917
919
}
918
920
919
921
/// An iterator over substrings of `self`, separated by characters
920
- /// matched by `sep `, restricted to splitting at most `count`
922
+ /// matched by the pattern `pat `, restricted to splitting at most `count`
921
923
/// times.
922
924
///
923
925
/// # Example
@@ -938,13 +940,13 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
938
940
/// let v: Vec<&str> = "".splitn(1, 'X').collect();
939
941
/// assert_eq!(v, vec![""]);
940
942
/// ```
941
- #[ unstable = "awaiting pattern/matcher stabilization" ]
942
- fn splitn < Sep : CharEq > ( & self , count : uint , sep : Sep ) -> CharSplitsN < Sep > {
943
- core_str:: StrExt :: splitn ( self [ ] , count, sep )
943
+ #[ stable ]
944
+ fn splitn < P : CharEq > ( & self , count : uint , pat : P ) -> SplitN < P > {
945
+ core_str:: StrExt :: splitn ( self [ ] , count, pat )
944
946
}
945
947
946
948
/// An iterator over substrings of `self`, separated by characters
947
- /// matched by `sep `.
949
+ /// matched by the pattern `pat `.
948
950
///
949
951
/// Equivalent to `split`, except that the trailing substring
950
952
/// is skipped if empty (terminator semantics).
@@ -967,13 +969,13 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
967
969
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
968
970
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
969
971
/// ```
970
- #[ unstable = "awaiting pattern/matcher stabilization " ]
971
- fn split_terminator < Sep : CharEq > ( & self , sep : Sep ) -> CharSplits < Sep > {
972
- core_str:: StrExt :: split_terminator ( self [ ] , sep )
972
+ #[ unstable = "might get removed " ]
973
+ fn split_terminator < P : CharEq > ( & self , pat : P ) -> SplitTerminator < P > {
974
+ core_str:: StrExt :: split_terminator ( self [ ] , pat )
973
975
}
974
976
975
977
/// An iterator over substrings of `self`, separated by characters
976
- /// matched by `sep `, starting from the end of the string.
978
+ /// matched by the pattern `pat `, starting from the end of the string.
977
979
/// Restricted to splitting at most `count` times.
978
980
///
979
981
/// # Example
@@ -988,13 +990,13 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
988
990
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
989
991
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
990
992
/// ```
991
- #[ unstable = "awaiting pattern/matcher stabilization" ]
992
- fn rsplitn < Sep : CharEq > ( & self , count : uint , sep : Sep ) -> CharSplitsN < Sep > {
993
- core_str:: StrExt :: rsplitn ( self [ ] , count, sep )
993
+ #[ stable ]
994
+ fn rsplitn < P : CharEq > ( & self , count : uint , pat : P ) -> RSplitN < P > {
995
+ core_str:: StrExt :: rsplitn ( self [ ] , count, pat )
994
996
}
995
997
996
998
/// An iterator over the start and end indices of the disjoint
997
- /// matches of `sep ` within `self`.
999
+ /// matches of the pattern `pat ` within `self`.
998
1000
///
999
1001
/// That is, each returned value `(start, end)` satisfies
1000
1002
/// `self.slice(start, end) == sep`. For matches of `sep` within
@@ -1013,12 +1015,12 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1013
1015
/// let v: Vec<(uint, uint)> = "ababa".match_indices("aba").collect();
1014
1016
/// assert_eq!(v, vec![(0, 3)]); // only the first `aba`
1015
1017
/// ```
1016
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1017
- fn match_indices < ' a > ( & ' a self , sep : & ' a str ) -> MatchIndices < ' a > {
1018
- core_str:: StrExt :: match_indices ( self [ ] , sep )
1018
+ #[ unstable = "might have its iterator type changed " ]
1019
+ fn match_indices < ' a > ( & ' a self , pat : & ' a str ) -> MatchIndices < ' a > {
1020
+ core_str:: StrExt :: match_indices ( self [ ] , pat )
1019
1021
}
1020
1022
1021
- /// An iterator over the substrings of `self` separated by `sep`.
1023
+ /// An iterator over the substrings of `self` separated by the pattern `sep`.
1022
1024
///
1023
1025
/// # Example
1024
1026
///
@@ -1029,9 +1031,9 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1029
1031
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
1030
1032
/// assert_eq!(v, vec!["1", "", "2"]);
1031
1033
/// ```
1032
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1033
- fn split_str < ' a > ( & ' a self , s : & ' a str ) -> StrSplits < ' a > {
1034
- core_str:: StrExt :: split_str ( self [ ] , s )
1034
+ #[ unstable = "might get removed in the future in favor of a more generic split() " ]
1035
+ fn split_str < ' a > ( & ' a self , pat : & ' a str ) -> StrSplits < ' a > {
1036
+ core_str:: StrExt :: split_str ( self [ ] , pat )
1035
1037
}
1036
1038
1037
1039
/// An iterator over the lines of a string (subsequences separated
@@ -1204,85 +1206,106 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1204
1206
core_str:: StrExt :: slice_unchecked ( self [ ] , begin, end)
1205
1207
}
1206
1208
1207
- /// Returns true if `needle ` is a prefix of the string.
1209
+ /// Returns true if the pattern `pat ` is a prefix of the string.
1208
1210
///
1209
1211
/// # Example
1210
1212
///
1211
1213
/// ```rust
1212
1214
/// assert!("banana".starts_with("ba"));
1213
1215
/// ```
1214
- #[ unstable = "awaiting pattern/matcher stabilization" ]
1215
- fn starts_with ( & self , needle : & str ) -> bool {
1216
- core_str:: StrExt :: starts_with ( self [ ] , needle )
1216
+ #[ stable ]
1217
+ fn starts_with ( & self , pat : & str ) -> bool {
1218
+ core_str:: StrExt :: starts_with ( self [ ] , pat )
1217
1219
}
1218
1220
1219
- /// Returns true if `needle ` is a suffix of the string.
1221
+ /// Returns true if the pattern `pat ` is a suffix of the string.
1220
1222
///
1221
1223
/// # Example
1222
1224
///
1223
1225
/// ```rust
1224
1226
/// assert!("banana".ends_with("nana"));
1225
1227
/// ```
1226
- #[ unstable = "awaiting pattern/matcher stabilization" ]
1227
- fn ends_with ( & self , needle : & str ) -> bool {
1228
- core_str:: StrExt :: ends_with ( self [ ] , needle )
1228
+ #[ stable ]
1229
+ fn ends_with ( & self , pat : & str ) -> bool {
1230
+ core_str:: StrExt :: ends_with ( self [ ] , pat )
1229
1231
}
1230
1232
1231
- /// Returns a string with characters that match `to_trim` removed from the left and the right.
1233
+ /// Returns a string with all pre- and suffixes that match
1234
+ /// the pattern `pat` repeatedly removed.
1232
1235
///
1233
1236
/// # Arguments
1234
1237
///
1235
- /// * to_trim - a character matcher
1238
+ /// * pat - a string pattern
1236
1239
///
1237
1240
/// # Example
1238
1241
///
1239
1242
/// ```rust
1240
- /// assert_eq!("11foo1bar11".trim_chars ('1'), "foo1bar");
1243
+ /// assert_eq!("11foo1bar11".trim_matches ('1'), "foo1bar");
1241
1244
/// let x: &[_] = &['1', '2'];
1242
- /// assert_eq!("12foo1bar12".trim_chars (x), "foo1bar");
1243
- /// assert_eq!("123foo1bar123".trim_chars (|&: c: char| c.is_numeric()), "foo1bar");
1245
+ /// assert_eq!("12foo1bar12".trim_matches (x), "foo1bar");
1246
+ /// assert_eq!("123foo1bar123".trim_matches (|&: c: char| c.is_numeric()), "foo1bar");
1244
1247
/// ```
1245
- #[ unstable = "awaiting pattern/matcher stabilization" ]
1246
- fn trim_chars < C : CharEq > ( & self , to_trim : C ) -> & str {
1247
- core_str:: StrExt :: trim_chars ( self [ ] , to_trim )
1248
+ #[ stable ]
1249
+ fn trim_matches < P : CharEq > ( & self , pat : P ) -> & str {
1250
+ core_str:: StrExt :: trim_matches ( self [ ] , pat )
1248
1251
}
1249
1252
1250
- /// Returns a string with leading `chars_to_trim` removed.
1253
+ /// Deprecated
1254
+ #[ deprecated = "Replaced by `trim_matches`" ]
1255
+ fn trim_chars < ' a , C : CharEq > ( & ' a self , to_trim : C ) -> & ' a str {
1256
+ self . trim_matches ( to_trim)
1257
+ }
1258
+
1259
+ /// Returns a string with all prefixes that match
1260
+ /// the pattern `pat` repeatedly removed.
1251
1261
///
1252
1262
/// # Arguments
1253
1263
///
1254
- /// * to_trim - a character matcher
1264
+ /// * pat - a string pattern
1255
1265
///
1256
1266
/// # Example
1257
1267
///
1258
1268
/// ```rust
1259
- /// assert_eq!("11foo1bar11".trim_left_chars ('1'), "foo1bar11");
1269
+ /// assert_eq!("11foo1bar11".trim_left_matches ('1'), "foo1bar11");
1260
1270
/// let x: &[_] = &['1', '2'];
1261
- /// assert_eq!("12foo1bar12".trim_left_chars (x), "foo1bar12");
1262
- /// assert_eq!("123foo1bar123".trim_left_chars (|&: c: char| c.is_numeric()), "foo1bar123");
1271
+ /// assert_eq!("12foo1bar12".trim_left_matches (x), "foo1bar12");
1272
+ /// assert_eq!("123foo1bar123".trim_left_matches (|&: c: char| c.is_numeric()), "foo1bar123");
1263
1273
/// ```
1264
- #[ unstable = "awaiting pattern/matcher stabilization" ]
1265
- fn trim_left_chars < C : CharEq > ( & self , to_trim : C ) -> & str {
1266
- core_str:: StrExt :: trim_left_chars ( self [ ] , to_trim)
1274
+ #[ stable]
1275
+ fn trim_left_matches < P : CharEq > ( & self , pat : P ) -> & str {
1276
+ core_str:: StrExt :: trim_left_matches ( self [ ] , pat)
1277
+ }
1278
+
1279
+ /// Deprecated
1280
+ #[ deprecated = "Replaced by `trim_left_matches`" ]
1281
+ fn trim_left_chars < ' a , C : CharEq > ( & ' a self , to_trim : C ) -> & ' a str {
1282
+ self . trim_left_matches ( to_trim)
1267
1283
}
1268
1284
1269
- /// Returns a string with trailing `chars_to_trim` removed.
1285
+ /// Returns a string with all suffixes that match
1286
+ /// the pattern `pat` repeatedly removed.
1270
1287
///
1271
1288
/// # Arguments
1272
1289
///
1273
- /// * to_trim - a character matcher
1290
+ /// * pat - a string pattern
1274
1291
///
1275
1292
/// # Example
1276
1293
///
1277
1294
/// ```rust
1278
- /// assert_eq!("11foo1bar11".trim_right_chars ('1'), "11foo1bar");
1295
+ /// assert_eq!("11foo1bar11".trim_right_matches ('1'), "11foo1bar");
1279
1296
/// let x: &[_] = &['1', '2'];
1280
- /// assert_eq!("12foo1bar12".trim_right_chars (x), "12foo1bar");
1281
- /// assert_eq!("123foo1bar123".trim_right_chars (|&: c: char| c.is_numeric()), "123foo1bar");
1297
+ /// assert_eq!("12foo1bar12".trim_right_matches (x), "12foo1bar");
1298
+ /// assert_eq!("123foo1bar123".trim_right_matches (|&: c: char| c.is_numeric()), "123foo1bar");
1282
1299
/// ```
1283
- #[ unstable = "awaiting pattern/matcher stabilization" ]
1284
- fn trim_right_chars < C : CharEq > ( & self , to_trim : C ) -> & str {
1285
- core_str:: StrExt :: trim_right_chars ( self [ ] , to_trim)
1300
+ #[ stable]
1301
+ fn trim_right_matches < P : CharEq > ( & self , pat : P ) -> & str {
1302
+ core_str:: StrExt :: trim_right_matches ( self [ ] , pat)
1303
+ }
1304
+
1305
+ /// Deprecated
1306
+ #[ deprecated = "Replaced by `trim_right_matches`" ]
1307
+ fn trim_right_chars < ' a , C : CharEq > ( & ' a self , to_trim : C ) -> & ' a str {
1308
+ self . trim_right_matches ( to_trim)
1286
1309
}
1287
1310
1288
1311
/// Check that `index`-th byte lies at the start and/or end of a
@@ -1430,7 +1453,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1430
1453
}
1431
1454
1432
1455
/// Returns the byte index of the first character of `self` that
1433
- /// matches `search `.
1456
+ /// matches the pattern `pat `.
1434
1457
///
1435
1458
/// # Return value
1436
1459
///
@@ -1452,13 +1475,13 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1452
1475
/// let x: &[_] = &['1', '2'];
1453
1476
/// assert_eq!(s.find(x), None);
1454
1477
/// ```
1455
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1456
- fn find < C : CharEq > ( & self , search : C ) -> Option < uint > {
1457
- core_str:: StrExt :: find ( self [ ] , search )
1478
+ #[ unstable = "might be superseded by match_indices " ]
1479
+ fn find < P : CharEq > ( & self , pat : P ) -> Option < uint > {
1480
+ core_str:: StrExt :: find ( self [ ] , pat )
1458
1481
}
1459
1482
1460
1483
/// Returns the byte index of the last character of `self` that
1461
- /// matches `search `.
1484
+ /// matches the pattern `pat `.
1462
1485
///
1463
1486
/// # Return value
1464
1487
///
@@ -1480,9 +1503,9 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1480
1503
/// let x: &[_] = &['1', '2'];
1481
1504
/// assert_eq!(s.rfind(x), None);
1482
1505
/// ```
1483
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1484
- fn rfind < C : CharEq > ( & self , search : C ) -> Option < uint > {
1485
- core_str:: StrExt :: rfind ( self [ ] , search )
1506
+ #[ unstable = "might be superseded by match_indices " ]
1507
+ fn rfind < P : CharEq > ( & self , pat : P ) -> Option < uint > {
1508
+ core_str:: StrExt :: rfind ( self [ ] , pat )
1486
1509
}
1487
1510
1488
1511
/// Returns the byte index of the first matching substring
@@ -1504,7 +1527,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1504
1527
/// assert_eq!(s.find_str("老虎 L"), Some(6));
1505
1528
/// assert_eq!(s.find_str("muffin man"), None);
1506
1529
/// ```
1507
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1530
+ #[ unstable = "might get removed in favor of a more generic find in the future " ]
1508
1531
fn find_str ( & self , needle : & str ) -> Option < uint > {
1509
1532
core_str:: StrExt :: find_str ( self [ ] , needle)
1510
1533
}
@@ -1546,7 +1569,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
1546
1569
/// assert!(string.subslice_offset(lines[1]) == 2); // &"b"
1547
1570
/// assert!(string.subslice_offset(lines[2]) == 4); // &"c"
1548
1571
/// ```
1549
- #[ unstable = "awaiting pattern/matcher stabilization " ]
1572
+ #[ unstable = "awaiting convention about comparability of arbitrary slices " ]
1550
1573
fn subslice_offset ( & self , inner : & str ) -> uint {
1551
1574
core_str:: StrExt :: subslice_offset ( self [ ] , inner)
1552
1575
}
0 commit comments