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