@@ -674,30 +674,18 @@ fn windowed(nn: uint, ss: str) -> [str] {
674
674
Function: to_lower
675
675
676
676
Convert a string to lowercase
677
-
678
- FIXME: rewrite with map
679
677
*/
680
678
fn to_lower ( s : str ) -> str {
681
- let outstr = "" ;
682
- chars_iter ( s) { |c|
683
- push_char ( outstr, char:: to_lower ( c) ) ;
684
- }
685
- ret outstr;
679
+ map ( s, char:: to_lower)
686
680
}
687
681
688
682
/*
689
683
Function: to_upper
690
684
691
685
Convert a string to uppercase
692
-
693
- FIXME: rewrite with map
694
686
*/
695
687
fn to_upper ( s : str ) -> str {
696
- let outstr = "" ;
697
- chars_iter ( s) { |c|
698
- push_char ( outstr, char:: to_upper ( c) ) ;
699
- }
700
- ret outstr;
688
+ map ( s, char:: to_upper)
701
689
}
702
690
703
691
// FIXME: This is super-inefficient
@@ -1583,8 +1571,9 @@ mod tests {
1583
1571
1584
1572
#[ test]
1585
1573
fn test_to_upper ( ) {
1586
- // to_upper doesn't understand unicode yet,
1587
- // but we need to at least preserve it
1574
+ // char::to_upper, and hence str::to_upper
1575
+ // are culturally insensitive: I'm not sure they
1576
+ // really work for anything but English ASCII, but YMMV
1588
1577
1589
1578
let unicode = "\u65e5 \u672c " ;
1590
1579
let input = "abcDEF" + unicode + "xyz:.;" ;
@@ -1593,6 +1582,12 @@ mod tests {
1593
1582
assert ( eq ( expected, actual) ) ;
1594
1583
}
1595
1584
1585
+ #[ test]
1586
+ fn test_to_lower ( ) {
1587
+ assert "" == map ( "" , char:: to_lower) ;
1588
+ assert "ymca" == map ( "YMCA" , char:: to_lower) ;
1589
+ }
1590
+
1596
1591
#[ test]
1597
1592
fn test_slice ( ) {
1598
1593
assert ( eq ( "ab" , slice ( "abc" , 0 u, 2 u) ) ) ;
0 commit comments