diff options
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/slice.rs | 24 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 28 |
2 files changed, 35 insertions, 17 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4599aff000d..d35173cbebf 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -328,9 +328,12 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred`, limited to splitting at most `n` times. The matched element is + /// `pred`, limited to returning at most `n` items. The matched element is /// not contained in the subslices. /// + /// The last element returned, if any, will contain the remainder of the + /// slice. + /// /// # Examples /// /// Print the slice split once by numbers divisible by 3 (i.e. `[10, 40]`, @@ -338,7 +341,7 @@ impl<T> [T] { /// /// ``` /// let v = [10, 40, 30, 20, 60, 50]; - /// for group in v.splitn(1, |num| *num % 3 == 0) { + /// for group in v.splitn(2, |num| *num % 3 == 0) { /// println!("{:?}", group); /// } /// ``` @@ -349,10 +352,13 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred` limited to splitting at most `n` times. This starts at the end of + /// `pred` limited to returning at most `n` items. This starts at the end of /// the slice and works backwards. The matched element is not contained in /// the subslices. /// + /// The last element returned, if any, will contain the remainder of the + /// slice. + /// /// # Examples /// /// Print the slice split once, starting from the end, by numbers divisible @@ -360,7 +366,7 @@ impl<T> [T] { /// /// ``` /// let v = [10, 40, 30, 20, 60, 50]; - /// for group in v.rsplitn(1, |num| *num % 3 == 0) { + /// for group in v.rsplitn(2, |num| *num % 3 == 0) { /// println!("{:?}", group); /// } /// ``` @@ -626,8 +632,11 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred`, limited to splitting at most `n` times. The matched element is + /// `pred`, limited to returning at most `n` items. The matched element is /// not contained in the subslices. + /// + /// The last element returned, if any, will contain the remainder of the + /// slice. #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<T, F> @@ -636,9 +645,12 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred` limited to splitting at most `n` times. This starts at the end of + /// `pred` limited to returning at most `n` items. This starts at the end of /// the slice and works backwards. The matched element is not contained in /// the subslices. + /// + /// The last element returned, if any, will contain the remainder of the + /// slice. #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<T, F> diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index f8f2909291f..c22b6fb9286 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -610,24 +610,27 @@ impl str { core_str::StrExt::split(&self[..], pat) } - /// An iterator over substrings of `self`, separated by characters matched by a pattern, - /// restricted to splitting at most `count` times. + /// An iterator over substrings of `self`, separated by characters matched + /// by a pattern, returning most `count` items. /// /// The pattern can be a simple `&str`, or a closure that determines /// the split. /// + /// The last element returned, if any, will contain the remainder of the + /// string. + /// /// # Examples /// /// Simple `&str` patterns: /// /// ``` /// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect(); - /// assert_eq!(v, ["Mary", "had", "a little lambda"]); + /// assert_eq!(v, ["Mary", "had a little lambda"]); /// /// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect(); - /// assert_eq!(v, ["lion", "", "tigerXleopard"]); + /// assert_eq!(v, ["lion", "XtigerXleopard"]); /// - /// let v: Vec<&str> = "abcXdef".splitn(0, 'X').collect(); + /// let v: Vec<&str> = "abcXdef".splitn(1, 'X').collect(); /// assert_eq!(v, ["abcXdef"]); /// /// let v: Vec<&str> = "".splitn(1, 'X').collect(); @@ -637,7 +640,7 @@ impl str { /// More complex patterns with a lambda: /// /// ``` - /// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_numeric()).collect(); + /// let v: Vec<&str> = "abc1def2ghi".splitn(2, |c: char| c.is_numeric()).collect(); /// assert_eq!(v, ["abc", "def2ghi"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -705,25 +708,28 @@ impl str { } /// An iterator over substrings of `self`, separated by a pattern, - /// starting from the end of the string, restricted to splitting - /// at most `count` times. + /// starting from the end of the string, restricted to returning + /// at most `count` items. + /// + /// The last element returned, if any, will contain the remainder of the + /// string. /// /// # Examples /// /// Simple patterns: /// /// ``` - /// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect(); + /// let v: Vec<&str> = "Mary had a little lamb".rsplitn(3, ' ').collect(); /// assert_eq!(v, ["lamb", "little", "Mary had a"]); /// - /// let v: Vec<&str> = "lion::tiger::leopard".rsplitn(1, "::").collect(); + /// let v: Vec<&str> = "lion::tiger::leopard".rsplitn(2, "::").collect(); /// assert_eq!(v, ["leopard", "lion::tiger"]); /// ``` /// /// More complex patterns with a lambda: /// /// ``` - /// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_numeric()).collect(); + /// let v: Vec<&str> = "abc1def2ghi".rsplitn(2, |c: char| c.is_numeric()).collect(); /// assert_eq!(v, ["ghi", "abc1def"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] |
