Skip to content

Commit ccd0fff

Browse files
committed
stdlib: Implement str::split_ivec()
1 parent e038e8e commit ccd0fff

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib/str.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,21 @@ fn split(str s, u8 sep) -> vec[str] {
442442
ret v;
443443
}
444444

445+
fn split_ivec(str s, u8 sep) -> str[] {
446+
let str[] v = ~[];
447+
let str accum = "";
448+
let bool ends_with_sep = false;
449+
for (u8 c in s) {
450+
if (c == sep) {
451+
v += ~[accum];
452+
accum = "";
453+
ends_with_sep = true;
454+
} else { accum += unsafe_from_byte(c); ends_with_sep = false; }
455+
}
456+
if (str::byte_len(accum) != 0u || ends_with_sep) { v += ~[accum]; }
457+
ret v;
458+
}
459+
445460
fn concat(vec[str] v) -> str {
446461
let str s = "";
447462
for (str ss in v) { s += ss; }

0 commit comments

Comments
 (0)