Removed ascii functions from other modules
Replaced str::to_lowercase and str::to_uppercase
This commit is contained in:
@@ -787,22 +787,6 @@ pub fn each_split_within<'a>(ss: &'a str,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a string to lowercase. ASCII only
|
||||
pub fn to_lower(s: &str) -> ~str {
|
||||
do map(s) |c| {
|
||||
assert!(char::is_ascii(c));
|
||||
(unsafe{libc::tolower(c as libc::c_char)}) as char
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a string to uppercase. ASCII only
|
||||
pub fn to_upper(s: &str) -> ~str {
|
||||
do map(s) |c| {
|
||||
assert!(char::is_ascii(c));
|
||||
(unsafe{libc::toupper(c as libc::c_char)}) as char
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all occurrences of one string with another
|
||||
*
|
||||
@@ -1610,13 +1594,6 @@ pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
||||
Section: String properties
|
||||
*/
|
||||
|
||||
/// Determines if a string contains only ASCII characters
|
||||
pub fn is_ascii(s: &str) -> bool {
|
||||
let mut i: uint = len(s);
|
||||
while i > 0u { i -= 1u; if !u8::is_ascii(s[i]) { return false; } }
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns true if the string has length 0
|
||||
pub fn is_empty(s: &str) -> bool { len(s) == 0u }
|
||||
|
||||
@@ -2403,8 +2380,6 @@ pub trait StrSlice<'self> {
|
||||
fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool);
|
||||
fn starts_with<'a>(&self, needle: &'a str) -> bool;
|
||||
fn substr(&self, begin: uint, n: uint) -> &'self str;
|
||||
fn to_lower(&self) -> ~str;
|
||||
fn to_upper(&self) -> ~str;
|
||||
fn escape_default(&self) -> ~str;
|
||||
fn escape_unicode(&self) -> ~str;
|
||||
fn trim(&self) -> &'self str;
|
||||
@@ -2565,12 +2540,6 @@ impl<'self> StrSlice<'self> for &'self str {
|
||||
fn substr(&self, begin: uint, n: uint) -> &'self str {
|
||||
substr(*self, begin, n)
|
||||
}
|
||||
/// Convert a string to lowercase
|
||||
#[inline]
|
||||
fn to_lower(&self) -> ~str { to_lower(*self) }
|
||||
/// Convert a string to uppercase
|
||||
#[inline]
|
||||
fn to_upper(&self) -> ~str { to_upper(*self) }
|
||||
/// Escape each char in `s` with char::escape_default.
|
||||
#[inline]
|
||||
fn escape_default(&self) -> ~str { escape_default(*self) }
|
||||
@@ -3084,27 +3053,6 @@ mod tests {
|
||||
assert!(repeat(~"hi", 0) == ~"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_upper() {
|
||||
// libc::toupper, and hence str::to_upper
|
||||
// are culturally insensitive: they only work for ASCII
|
||||
// (see Issue #1347)
|
||||
let unicode = ~""; //"\u65e5\u672c"; // uncomment once non-ASCII works
|
||||
let input = ~"abcDEF" + unicode + ~"xyz:.;";
|
||||
let expected = ~"ABCDEF" + unicode + ~"XYZ:.;";
|
||||
let actual = to_upper(input);
|
||||
assert!(expected == actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_lower() {
|
||||
// libc::tolower, and hence str::to_lower
|
||||
// are culturally insensitive: they only work for ASCII
|
||||
// (see Issue #1347)
|
||||
assert!(~"" == to_lower(""));
|
||||
assert!(~"ymca" == to_lower("YMCA"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unsafe_slice() {
|
||||
assert!("ab" == unsafe {raw::slice_bytes("abc", 0, 2)});
|
||||
@@ -3337,13 +3285,6 @@ mod tests {
|
||||
assert!((!is_whitespace(~" _ ")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_ascii() {
|
||||
assert!((is_ascii(~"")));
|
||||
assert!((is_ascii(~"a")));
|
||||
assert!((!is_ascii(~"\u2009")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shift_byte() {
|
||||
let mut s = ~"ABC";
|
||||
|
||||
Reference in New Issue
Block a user