Skip to content

Commit 9ac9148

Browse files
committed
auto merge of #14335 : tbu-/rust/pr_doc_strsplit, r=pnkfelix
In particular, show examples for splitting the empty string and using `splitn` with a count of 0. Fix #14222.
2 parents e7e5e9c + dcc2305 commit 9ac9148

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libcore/str.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,9 @@ pub trait StrSlice<'a> {
11121112
///
11131113
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect();
11141114
/// assert_eq!(v, vec!["lion", "", "tiger", "leopard"]);
1115+
///
1116+
/// let v: Vec<&str> = "".split('X').collect();
1117+
/// assert_eq!(v, vec![""]);
11151118
/// ```
11161119
fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplits<'a, Sep>;
11171120

@@ -1130,6 +1133,12 @@ pub trait StrSlice<'a> {
11301133
///
11311134
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect();
11321135
/// assert_eq!(v, vec!["lion", "", "tigerXleopard"]);
1136+
///
1137+
/// let v: Vec<&str> = "abcXdef".splitn('X', 0).collect();
1138+
/// assert_eq!(v, vec!["abcXdef"]);
1139+
///
1140+
/// let v: Vec<&str> = "".splitn('X', 1).collect();
1141+
/// assert_eq!(v, vec![""]);
11331142
/// ```
11341143
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
11351144

0 commit comments

Comments
 (0)