@@ -27,9 +27,16 @@ use core::str::Split;
27
27
28
28
use tables:: grapheme:: GraphemeCat ;
29
29
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 > {
33
40
inner : Filter < Split < ' a , fn ( char ) -> bool > , fn ( & & str ) -> bool > ,
34
41
}
35
42
@@ -38,7 +45,9 @@ pub struct Words<'a> {
38
45
pub trait UnicodeStr {
39
46
fn graphemes < ' a > ( & ' a self , is_extended : bool ) -> Graphemes < ' a > ;
40
47
fn grapheme_indices < ' a > ( & ' a self , is_extended : bool ) -> GraphemeIndices < ' a > ;
48
+ #[ allow( deprecated) ]
41
49
fn words < ' a > ( & ' a self ) -> Words < ' a > ;
50
+ fn split_whitespace < ' a > ( & ' a self ) -> SplitWhitespace < ' a > ;
42
51
fn is_whitespace ( & self ) -> bool ;
43
52
fn is_alphanumeric ( & self ) -> bool ;
44
53
fn width ( & self , is_cjk : bool ) -> usize ;
@@ -58,15 +67,21 @@ impl UnicodeStr for str {
58
67
GraphemeIndices { start_offset : self . as_ptr ( ) as usize , iter : self . graphemes ( is_extended) }
59
68
}
60
69
70
+ #[ allow( deprecated) ]
61
71
#[ inline]
62
72
fn words ( & self ) -> Words {
73
+ self . split_whitespace ( )
74
+ }
75
+
76
+ #[ inline]
77
+ fn split_whitespace ( & self ) -> SplitWhitespace {
63
78
fn is_not_empty ( s : & & str ) -> bool { !s. is_empty ( ) }
64
79
let is_not_empty: fn ( & & str ) -> bool = is_not_empty; // coerce to fn pointer
65
80
66
81
fn is_whitespace ( c : char ) -> bool { c. is_whitespace ( ) }
67
82
let is_whitespace: fn ( char ) -> bool = is_whitespace; // coerce to fn pointer
68
83
69
- Words { inner : self . split ( is_whitespace) . filter ( is_not_empty) }
84
+ SplitWhitespace { inner : self . split ( is_whitespace) . filter ( is_not_empty) }
70
85
}
71
86
72
87
#[ inline]
@@ -547,11 +562,11 @@ impl<I> Iterator for Utf16Encoder<I> where I: Iterator<Item=char> {
547
562
}
548
563
}
549
564
550
- impl < ' a > Iterator for Words < ' a > {
565
+ impl < ' a > Iterator for SplitWhitespace < ' a > {
551
566
type Item = & ' a str ;
552
567
553
568
fn next ( & mut self ) -> Option < & ' a str > { self . inner . next ( ) }
554
569
}
555
- impl < ' a > DoubleEndedIterator for Words < ' a > {
570
+ impl < ' a > DoubleEndedIterator for SplitWhitespace < ' a > {
556
571
fn next_back ( & mut self ) -> Option < & ' a str > { self . inner . next_back ( ) }
557
572
}
0 commit comments