@@ -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,50 @@ impl str {
1739
1739
UnicodeStr :: grapheme_indices ( & self [ ..] , is_extended)
1740
1740
}
1741
1741
1742
- /// An iterator over the non-empty words of `self`.
1742
+ /// An iterator over non-whitespace substrings of `self`,
1743
+ /// separated by any sequence of whitespace.
1743
1744
///
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.
1745
+ /// Sequences of whitespace are collapsed, so empty substrings
1746
+ /// are not included.
1747
1747
///
1748
1748
/// # Examples
1749
1749
///
1750
1750
/// ```
1751
1751
/// # #![feature(str_words)]
1752
+ /// # #![allow(deprecated)]
1752
1753
/// let some_words = " Mary had\ta little \n\t lamb";
1753
1754
/// let v: Vec<&str> = some_words.words().collect();
1754
1755
///
1755
1756
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
1756
1757
/// ```
1758
+ #[ deprecated( reason = "words() will be removed. Use split_whitespace() instead" ,
1759
+ since = "1.0.0" ) ]
1757
1760
#[ unstable( feature = "str_words" ,
1758
1761
reason = "the precise algorithm to use is unclear" ) ]
1762
+ #[ allow( deprecated) ]
1759
1763
pub fn words ( & self ) -> Words {
1760
1764
UnicodeStr :: words ( & self [ ..] )
1761
1765
}
1762
1766
1767
+ /// An iterator over non-whitespace substrings of `self`,
1768
+ /// separated by any sequence of whitespace.
1769
+ ///
1770
+ /// Sequences of whitespace are collapsed, so empty substrings
1771
+ /// are not included.
1772
+ ///
1773
+ /// # Examples
1774
+ ///
1775
+ /// ```
1776
+ /// let some_words = " Mary had\ta little \n\t lamb";
1777
+ /// let v: Vec<&str> = some_words.split_whitespace().collect();
1778
+ ///
1779
+ /// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
1780
+ /// ```
1781
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1782
+ pub fn split_whitespace ( & self ) -> SplitWhitespace {
1783
+ UnicodeStr :: split_whitespace ( & self [ ..] )
1784
+ }
1785
+
1763
1786
/// Returns a string's displayed width in columns.
1764
1787
///
1765
1788
/// Control characters have zero width.
0 commit comments