@@ -14,7 +14,7 @@ export eq, lteq, hash, is_empty, is_not_empty, is_whitespace, byte_len,
14
14
char_at, bytes, is_ascii, shift_byte, pop_byte,
15
15
unsafe_from_byte, unsafe_from_bytes, from_char, char_range_at,
16
16
from_cstr, sbuf, as_buf, push_byte, utf8_char_width, safe_slice,
17
- contains, iter_chars, chars_iter, bytes_iter, words_iter,
17
+ contains, iter_chars, chars_iter, bytes_iter, words_iter, lines_iter ,
18
18
loop_chars, loop_chars_sub, escape, any, all, map, windowed;
19
19
20
20
#[ abi = "cdecl" ]
@@ -923,6 +923,15 @@ fn words_iter(ss: str, ff: fn&(&&str)) {
923
923
vec:: iter ( words ( ss) , ff)
924
924
}
925
925
926
+ /*
927
+ Function: lines_iter
928
+
929
+ Apply a function to each lines (by '\n')
930
+ */
931
+ fn lines_iter ( ss : str , ff : fn & ( & & str ) ) {
932
+ vec:: iter ( lines ( ss) , ff)
933
+ }
934
+
926
935
/*
927
936
Function: concat
928
937
@@ -1708,11 +1717,26 @@ mod tests {
1708
1717
}
1709
1718
ii += 1 ;
1710
1719
}
1720
+
1721
+ words_iter ( "" ) { |_x| fail; } // should not fail
1711
1722
}
1712
1723
1713
1724
#[ test]
1714
- fn test_words_iter_ ( ) {
1715
- words_iter ( "" ) { |_ww| fail; } // should not fail
1725
+ fn test_lines_iter ( ) {
1726
+ let lf = "\n Mary had a little lamb\n Little lamb\n " ;
1727
+
1728
+ let ii = 0 ;
1729
+
1730
+ lines_iter ( lf) { |x|
1731
+ alt ii {
1732
+ 0 { assert "" == x; }
1733
+ 1 { assert "Mary had a little lamb" == x; }
1734
+ 2 { assert "Little lamb" == x; }
1735
+ 3 { assert "" == x; }
1736
+ _ { ( ) }
1737
+ }
1738
+ ii += 1 ;
1739
+ }
1716
1740
}
1717
1741
1718
1742
#[ test]
0 commit comments