File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed
branches/snap-stage3/src/libcore Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: 477c3a8eb16a0b81e5211c929851ce221e9268d7
4
+ refs/heads/snap-stage3: 0493a7c87d7769a3b3b819a7b38cd242f95dfad2
5
5
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change @@ -1113,6 +1113,33 @@ fn escape(s: str) -> str {
1113
1113
r
1114
1114
}
1115
1115
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
+
1116
1143
#[ cfg( test) ]
1117
1144
mod tests {
1118
1145
@@ -1572,4 +1599,19 @@ mod tests {
1572
1599
assert ( escape ( "abc\n def" ) == "abc\\ ndef" ) ;
1573
1600
assert ( escape ( "abc\" def" ) == "abc\\ \" def" ) ;
1574
1601
}
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
+ }
You can’t perform that action at this time.
0 commit comments