1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -789,16 +789,18 @@ pub fn each_split_within<'a>(ss: &'a str,
789
789
790
790
/// Convert a string to lowercase. ASCII only
791
791
pub fn to_lower ( s : & str ) -> ~str {
792
- map ( s,
793
- |c| unsafe { ( libc:: tolower ( c as libc:: c_char ) ) as char }
794
- )
792
+ do map ( s) |c| {
793
+ assert ! ( char :: is_ascii( c) ) ;
794
+ ( unsafe { libc:: tolower ( c as libc:: c_char ) } ) as char
795
+ }
795
796
}
796
797
797
798
/// Convert a string to uppercase. ASCII only
798
799
pub fn to_upper ( s : & str ) -> ~str {
799
- map ( s,
800
- |c| unsafe { ( libc:: toupper ( c as libc:: c_char ) ) as char }
801
- )
800
+ do map ( s) |c| {
801
+ assert ! ( char :: is_ascii( c) ) ;
802
+ ( unsafe { libc:: toupper ( c as libc:: c_char ) } ) as char
803
+ }
802
804
}
803
805
804
806
/**
@@ -3096,12 +3098,11 @@ mod tests {
3096
3098
3097
3099
#[test]
3098
3100
fn test_to_lower() {
3099
- unsafe {
3100
- assert!(~" " == map(~" ",
3101
- |c| libc::tolower(c as c_char) as char));
3102
- assert!(~" ymca" == map(~" YMCA ",
3103
- |c| libc::tolower(c as c_char) as char));
3104
- }
3101
+ // libc::tolower, and hence str::to_lower
3102
+ // are culturally insensitive: they only work for ASCII
3103
+ // (see Issue #1347)
3104
+ assert!(~" " == to_lower(" "));
3105
+ assert!(~" ymca" == to_lower(" YMCA "));
3105
3106
}
3106
3107
3107
3108
#[test]
@@ -3666,12 +3667,8 @@ mod tests {
3666
3667
3667
3668
#[ test]
3668
3669
fn test_map( ) {
3669
- unsafe {
3670
- assert!( ~"" == map( ~"", |c|
3671
- libc:: toupper( c as c_char) as char ) ) ;
3672
- assert!( ~"YMCA " == map(~" ymca",
3673
- |c| libc::toupper(c as c_char) as char));
3674
- }
3670
+ assert!( ~"" == map( ~"", |c| unsafe { libc:: toupper( c as c_char) } as char ) ) ;
3671
+ assert!( ~"YMCA " == map(~" ymca", |c| unsafe {libc::toupper(c as c_char)} as char));
3675
3672
}
3676
3673
3677
3674
#[test]
@@ -3685,11 +3682,11 @@ mod tests {
3685
3682
3686
3683
#[test]
3687
3684
fn test_any() {
3688
- assert!(false == any(~" ", char::is_uppercase));
3685
+ assert!(false == any(~" ", char::is_uppercase));
3689
3686
assert!(false == any(~" ymca", char::is_uppercase));
3690
3687
assert!(true == any(~" YMCA ", char::is_uppercase));
3691
- assert!(true == any(~" yMCA", char::is_uppercase));
3692
- assert!(true == any(~" Ymcy ", char::is_uppercase));
3688
+ assert!(true == any(~" yMCA", char::is_uppercase));
3689
+ assert!(true == any(~" Ymcy ", char::is_uppercase));
3693
3690
}
3694
3691
3695
3692
#[test]
0 commit comments