diff options
| author | Kevin Cantu <me@kevincantu.org> | 2012-01-23 03:20:01 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-01-23 22:28:25 -0800 |
| commit | 536dd2f5a72e3c05b41a89af02142d2fc9826bd9 (patch) | |
| tree | 649760ddfae335b94e7bb44bd3237dbbc81d4170 /src | |
| parent | 1c54744e3f63bb32ea7845a242178eec450fdf3b (diff) | |
| download | rust-536dd2f5a72e3c05b41a89af02142d2fc9826bd9.tar.gz rust-536dd2f5a72e3c05b41a89af02142d2fc9826bd9.zip | |
Added str::lines_iter
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/str.rs | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 253d6e5dfb1..83ab8ac5b09 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -14,7 +14,7 @@ export eq, lteq, hash, is_empty, is_not_empty, is_whitespace, byte_len, char_at, bytes, is_ascii, shift_byte, pop_byte, unsafe_from_byte, unsafe_from_bytes, from_char, char_range_at, from_cstr, sbuf, as_buf, push_byte, utf8_char_width, safe_slice, - contains, iter_chars, chars_iter, bytes_iter, words_iter, + contains, iter_chars, chars_iter, bytes_iter, words_iter, lines_iter, loop_chars, loop_chars_sub, escape, any, all, map, windowed; #[abi = "cdecl"] @@ -924,6 +924,15 @@ fn words_iter(ss: str, ff: fn&(&&str)) { } /* +Function: lines_iter + +Apply a function to each lines (by '\n') +*/ +fn lines_iter(ss: str, ff: fn&(&&str)) { + vec::iter(lines(ss), ff) +} + +/* Function: concat Concatenate a vector of strings @@ -1708,11 +1717,26 @@ mod tests { } ii += 1; } + + words_iter("") {|_x| fail; } // should not fail } #[test] - fn test_words_iter_() { - words_iter("") {|_ww| fail; } // should not fail + fn test_lines_iter () { + let lf = "\nMary had a little lamb\nLittle lamb\n"; + + let ii = 0; + + lines_iter(lf) {|x| + alt ii { + 0 { assert "" == x; } + 1 { assert "Mary had a little lamb" == x; } + 2 { assert "Little lamb" == x; } + 3 { assert "" == x; } + _ { () } + } + ii += 1; + } } #[test] |
