Skip to content

Commit e236886

Browse files
killerswannikomatsakis
authored andcommitted
---
yaml --- r: 7740 b: refs/heads/snap-stage3 c: 0493a7c h: refs/heads/master v: v3
1 parent 0ca6a36 commit e236886

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
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: 477c3a8eb16a0b81e5211c929851ce221e9268d7
4+
refs/heads/snap-stage3: 0493a7c87d7769a3b3b819a7b38cd242f95dfad2
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,33 @@ fn escape(s: str) -> str {
11131113
r
11141114
}
11151115

1116+
/*
1117+
Function: all
1118+
1119+
Return true if a predicate matches all characters
1120+
1121+
If the string contains no characters
1122+
*/
1123+
fn all(ss: str, ff: fn&(char) -> bool) -> bool {
1124+
str::loop_chars(ss, ff)
1125+
}
1126+
1127+
/*
1128+
Function: map
1129+
1130+
Apply a function to each character
1131+
*/
1132+
fn map(ss: str, ff: fn&(char) -> char) -> str {
1133+
let result = "";
1134+
1135+
str::iter_chars(ss, {|cc|
1136+
str::push_char(result, ff(cc));
1137+
});
1138+
1139+
ret result;
1140+
}
1141+
1142+
11161143
#[cfg(test)]
11171144
mod tests {
11181145

@@ -1572,4 +1599,19 @@ mod tests {
15721599
assert(escape("abc\ndef") == "abc\\ndef");
15731600
assert(escape("abc\"def") == "abc\\\"def");
15741601
}
1575-
}
1602+
1603+
#[test]
1604+
fn test_map () {
1605+
assert "" == map("", char::to_upper);
1606+
assert "YMCA" == map("ymca", char::to_upper);
1607+
}
1608+
1609+
#[test]
1610+
fn test_all () {
1611+
assert true == all("", char::is_uppercase);
1612+
assert false == all("ymca", char::is_uppercase);
1613+
assert true == all("YMCA", char::is_uppercase);
1614+
assert false == all("yMCA", char::is_uppercase);
1615+
assert false == all("YMCy", char::is_uppercase);
1616+
}
1617+
}

0 commit comments

Comments
 (0)