@@ -27,9 +27,16 @@ use core::str::Split;
2727
2828use tables:: grapheme:: GraphemeCat ;
2929
30- /// An iterator over the words of a string, separated by a sequence of whitespace
31- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
32- pub struct Words < ' a > {
30+ #[ deprecated( reason = "struct Words is being replaced by struct SplitWhitespace" ,
31+ since = "1.1.0" ) ]
32+ #[ unstable( feature = "unicode" ,
33+ reason = "per RFC 1054, deprecating in favor of SplitWhitespace" ) ]
34+ pub type Words < ' a > = SplitWhitespace < ' a > ;
35+
36+ /// An iterator over the non-whitespace substrings of a string,
37+ /// separated by any amount of whitespace.
38+ #[ stable( feature = "split_whitespace" , since = "1.1.0" ) ]
39+ pub struct SplitWhitespace < ' a > {
3340 inner : Filter < Split < ' a , fn ( char ) -> bool > , fn ( & & str ) -> bool > ,
3441}
3542
@@ -38,7 +45,9 @@ pub struct Words<'a> {
3845pub trait UnicodeStr {
3946 fn graphemes < ' a > ( & ' a self , is_extended : bool ) -> Graphemes < ' a > ;
4047 fn grapheme_indices < ' a > ( & ' a self , is_extended : bool ) -> GraphemeIndices < ' a > ;
48+ #[ allow( deprecated) ]
4149 fn words < ' a > ( & ' a self ) -> Words < ' a > ;
50+ fn split_whitespace < ' a > ( & ' a self ) -> SplitWhitespace < ' a > ;
4251 fn is_whitespace ( & self ) -> bool ;
4352 fn is_alphanumeric ( & self ) -> bool ;
4453 fn width ( & self , is_cjk : bool ) -> usize ;
@@ -58,15 +67,21 @@ impl UnicodeStr for str {
5867 GraphemeIndices { start_offset : self . as_ptr ( ) as usize , iter : self . graphemes ( is_extended) }
5968 }
6069
70+ #[ allow( deprecated) ]
6171 #[ inline]
6272 fn words ( & self ) -> Words {
73+ self . split_whitespace ( )
74+ }
75+
76+ #[ inline]
77+ fn split_whitespace ( & self ) -> SplitWhitespace {
6378 fn is_not_empty ( s : & & str ) -> bool { !s. is_empty ( ) }
6479 let is_not_empty: fn ( & & str ) -> bool = is_not_empty; // coerce to fn pointer
6580
6681 fn is_whitespace ( c : char ) -> bool { c. is_whitespace ( ) }
6782 let is_whitespace: fn ( char ) -> bool = is_whitespace; // coerce to fn pointer
6883
69- Words { inner : self . split ( is_whitespace) . filter ( is_not_empty) }
84+ SplitWhitespace { inner : self . split ( is_whitespace) . filter ( is_not_empty) }
7085 }
7186
7287 #[ inline]
@@ -547,11 +562,11 @@ impl<I> Iterator for Utf16Encoder<I> where I: Iterator<Item=char> {
547562 }
548563}
549564
550- impl < ' a > Iterator for Words < ' a > {
565+ impl < ' a > Iterator for SplitWhitespace < ' a > {
551566 type Item = & ' a str ;
552567
553568 fn next ( & mut self ) -> Option < & ' a str > { self . inner . next ( ) }
554569}
555- impl < ' a > DoubleEndedIterator for Words < ' a > {
570+ impl < ' a > DoubleEndedIterator for SplitWhitespace < ' a > {
556571 fn next_back ( & mut self ) -> Option < & ' a str > { self . inner . next_back ( ) }
557572}
0 commit comments