Skip to content

Commit 6f6cdcd

Browse files
killerswannikomatsakis
authored andcommitted
---
yaml --- r: 7742 b: refs/heads/snap-stage3 c: ff95029 h: refs/heads/master v: v3
1 parent 25e6a46 commit 6f6cdcd

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: d4b287e8525758896e78b39eca6f6e1c0f32cd98
4+
refs/heads/snap-stage3: ff9502917125f3bfb8ebad252a1c8d3a4f6e0320
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/libcore/str.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export eq, lteq, hash, is_empty, is_not_empty, is_whitespace, byte_len,
1414
char_at, bytes, is_ascii, shift_byte, pop_byte,
1515
unsafe_from_byte, unsafe_from_bytes, from_char, char_range_at,
1616
from_cstr, sbuf, as_buf, push_byte, utf8_char_width, safe_slice,
17-
contains, iter_chars, chars_iter, bytes_iter,
17+
contains, iter_chars, chars_iter, bytes_iter, words_iter,
1818
loop_chars, loop_chars_sub, escape, any, all, map, windowed;
1919

2020
#[abi = "cdecl"]
@@ -914,6 +914,15 @@ fn words(ss: str) -> [str] {
914914
{|w| 0u < str::char_len(w)});
915915
}
916916

917+
/*
918+
Function: words_iter
919+
920+
Apply a function to each word
921+
*/
922+
fn words_iter(ss: str, ff: fn&(&&str)) {
923+
vec::iter(words(ss), ff)
924+
}
925+
917926
/*
918927
Function: concat
919928
@@ -1649,7 +1658,7 @@ mod tests {
16491658
i += 1;
16501659
}
16511660

1652-
iter_chars("") {|ch| fail; } // should not fail
1661+
iter_chars("") {|_ch| fail; } // should not fail
16531662
}
16541663

16551664
#[test]
@@ -1683,6 +1692,29 @@ mod tests {
16831692
bytes_iter("") {|bb| assert bb == 0u8; }
16841693
}
16851694

1695+
#[test]
1696+
fn test_words_iter() {
1697+
let data = "\nMary had a little lamb\nLittle lamb\n";
1698+
1699+
let ii = 0;
1700+
1701+
words_iter(data) {|ww|
1702+
alt ii {
1703+
0 { assert "Mary" == ww; }
1704+
1 { assert "had" == ww; }
1705+
2 { assert "a" == ww; }
1706+
3 { assert "little" == ww; }
1707+
_ { () }
1708+
}
1709+
ii += 1;
1710+
}
1711+
}
1712+
1713+
#[test]
1714+
fn test_words_iter_() {
1715+
words_iter("") {|_ww| fail; } // should not fail
1716+
}
1717+
16861718
#[test]
16871719
fn test_escape() {
16881720
assert(escape("abcdef") == "abcdef");

0 commit comments

Comments
 (0)