@@ -78,7 +78,7 @@ pub use core::str::{Matches, RMatches};
7878pub use core:: str:: { MatchIndices , RMatchIndices } ;
7979pub use core:: str:: { from_utf8, Chars , CharIndices , Bytes } ;
8080pub 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 } ;
8282pub use core:: str:: pattern;
8383
8484/*
@@ -1739,27 +1739,50 @@ impl str {
17391739 UnicodeStr :: grapheme_indices ( & self [ ..] , is_extended)
17401740 }
17411741
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.
17431744 ///
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.
17471747 ///
17481748 /// # Examples
17491749 ///
17501750 /// ```
17511751 /// # #![feature(str_words)]
1752+ /// # #![allow(deprecated)]
17521753 /// let some_words = " Mary had\ta little \n\t lamb";
17531754 /// let v: Vec<&str> = some_words.words().collect();
17541755 ///
17551756 /// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
17561757 /// ```
1758+ #[ deprecated( reason = "words() will be removed. Use split_whitespace() instead" ,
1759+ since = "1.0.0" ) ]
17571760 #[ unstable( feature = "str_words" ,
17581761 reason = "the precise algorithm to use is unclear" ) ]
1762+ #[ allow( deprecated) ]
17591763 pub fn words ( & self ) -> Words {
17601764 UnicodeStr :: words ( & self [ ..] )
17611765 }
17621766
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+
17631786 /// Returns a string's displayed width in columns.
17641787 ///
17651788 /// Control characters have zero width.
0 commit comments