@@ -76,7 +76,7 @@ pub use core::str::{Matches, RMatches};
7676pub use core:: str:: { MatchIndices , RMatchIndices } ;
7777pub use core:: str:: { from_utf8, Chars , CharIndices , Bytes } ;
7878pub 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 } ;
8080pub use core:: str:: pattern;
8181
8282/*
@@ -1737,27 +1737,44 @@ impl str {
17371737 UnicodeStr :: grapheme_indices ( & self [ ..] , is_extended)
17381738 }
17391739
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.
17451742 ///
17461743 /// # Examples
17471744 ///
17481745 /// ```
17491746 /// # #![feature(str_words)]
1747+ /// # #![allow(deprecated)]
17501748 /// let some_words = " Mary had\ta little \n\t lamb";
17511749 /// let v: Vec<&str> = some_words.words().collect();
17521750 ///
17531751 /// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
17541752 /// ```
1753+ #[ deprecated( reason = "words() will be removed. Use split_whitespace() instead" ,
1754+ since = "1.1.0" ) ]
17551755 #[ unstable( feature = "str_words" ,
17561756 reason = "the precise algorithm to use is unclear" ) ]
1757+ #[ allow( deprecated) ]
17571758 pub fn words ( & self ) -> Words {
17581759 UnicodeStr :: words ( & self [ ..] )
17591760 }
17601761
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+
17611778 /// Returns a string's displayed width in columns.
17621779 ///
17631780 /// Control characters have zero width.
0 commit comments