@@ -76,7 +76,7 @@ pub use core::str::{Matches, RMatches};
76
76
pub use core:: str:: { MatchIndices , RMatchIndices } ;
77
77
pub use core:: str:: { from_utf8, Chars , CharIndices , Bytes } ;
78
78
pub use core:: str:: { from_utf8_unchecked, ParseBoolError } ;
79
- pub use rustc_unicode:: str:: { Words , Graphemes , GraphemeIndices } ;
79
+ pub use rustc_unicode:: str:: { SplitWhitespace , Words , Graphemes , GraphemeIndices } ;
80
80
pub use core:: str:: pattern;
81
81
82
82
/*
@@ -1737,27 +1737,44 @@ impl str {
1737
1737
UnicodeStr :: grapheme_indices ( & self [ ..] , is_extended)
1738
1738
}
1739
1739
1740
- /// An iterator over the non-empty words of `self`.
1741
- ///
1742
- /// A 'word' is a subsequence separated by any sequence of whitespace.
1743
- /// Sequences of whitespace
1744
- /// are collapsed, so empty "words" are not included.
1740
+ /// An iterator over the non-empty substrings of `self` which contain no whitespace,
1741
+ /// and which are separated by any amount of whitespace.
1745
1742
///
1746
1743
/// # Examples
1747
1744
///
1748
1745
/// ```
1749
1746
/// # #![feature(str_words)]
1747
+ /// # #![allow(deprecated)]
1750
1748
/// let some_words = " Mary had\ta little \n\t lamb";
1751
1749
/// let v: Vec<&str> = some_words.words().collect();
1752
1750
///
1753
1751
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
1754
1752
/// ```
1753
+ #[ deprecated( reason = "words() will be removed. Use split_whitespace() instead" ,
1754
+ since = "1.1.0" ) ]
1755
1755
#[ unstable( feature = "str_words" ,
1756
1756
reason = "the precise algorithm to use is unclear" ) ]
1757
+ #[ allow( deprecated) ]
1757
1758
pub fn words ( & self ) -> Words {
1758
1759
UnicodeStr :: words ( & self [ ..] )
1759
1760
}
1760
1761
1762
+ /// An iterator over the non-empty substrings of `self` which contain no whitespace,
1763
+ /// and which are separated by any amount of whitespace.
1764
+ ///
1765
+ /// # Examples
1766
+ ///
1767
+ /// ```
1768
+ /// let some_words = " Mary had\ta little \n\t lamb";
1769
+ /// let v: Vec<&str> = some_words.split_whitespace().collect();
1770
+ ///
1771
+ /// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
1772
+ /// ```
1773
+ #[ stable( feature = "split_whitespace" , since = "1.1.0" ) ]
1774
+ pub fn split_whitespace ( & self ) -> SplitWhitespace {
1775
+ UnicodeStr :: split_whitespace ( & self [ ..] )
1776
+ }
1777
+
1761
1778
/// Returns a string's displayed width in columns.
1762
1779
///
1763
1780
/// Control characters have zero width.
0 commit comments