From dcc2305664ab9101513f5d6b40941ed4ffea47f5 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 21 May 2014 20:05:55 +0200 Subject: [PATCH] Add examples for edge cases of str.split/str.splitn In particular, show examples for splitting the empty string and using `splitn` with a count of 0. Fix #14222. --- src/libcore/str.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 0d820836377..19be2fd3169 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1112,6 +1112,9 @@ pub trait StrSlice<'a> { /// /// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect(); /// assert_eq!(v, vec!["lion", "", "tiger", "leopard"]); + /// + /// let v: Vec<&str> = "".split('X').collect(); + /// assert_eq!(v, vec![""]); /// ``` fn split(&self, sep: Sep) -> CharSplits<'a, Sep>; @@ -1130,6 +1133,12 @@ pub trait StrSlice<'a> { /// /// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect(); /// assert_eq!(v, vec!["lion", "", "tigerXleopard"]); + /// + /// let v: Vec<&str> = "abcXdef".splitn('X', 0).collect(); + /// assert_eq!(v, vec!["abcXdef"]); + /// + /// let v: Vec<&str> = "".splitn('X', 1).collect(); + /// assert_eq!(v, vec![""]); /// ``` fn splitn(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>; -- GitLab