Removed ascii functions from other modules
Replaced str::to_lowercase and str::to_uppercase
This commit is contained in:
@@ -50,7 +50,10 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
|
|||||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||||
let start_kind = idx;
|
let start_kind = idx;
|
||||||
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
||||||
let kind = str::to_lower(str::slice(line, start_kind, idx).to_owned());
|
|
||||||
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
let kind = str::slice(line, start_kind, idx).to_ascii().to_lower().to_str_ascii();
|
||||||
|
|
||||||
// Extract msg:
|
// Extract msg:
|
||||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||||
|
|||||||
@@ -100,12 +100,6 @@ pub fn is_alphanumeric(c: char) -> bool {
|
|||||||
unicode::general_category::No(c);
|
unicode::general_category::No(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates whether the character is an ASCII character
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn is_ascii(c: char) -> bool {
|
|
||||||
c - ('\x7F' & c) == '\x00'
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Indicates whether the character is numeric (Nd, Nl, or No)
|
/// Indicates whether the character is numeric (Nd, Nl, or No)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_digit(c: char) -> bool {
|
pub fn is_digit(c: char) -> bool {
|
||||||
@@ -116,7 +110,7 @@ pub fn is_digit(c: char) -> bool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a character parses as a numeric digit in the given radix.
|
* Checks if a character parses as a numeric digit in the given radix.
|
||||||
* Compared to `is_digit()`, this function only recognizes the ascii
|
* Compared to `is_digit()`, this function only recognizes the
|
||||||
* characters `0-9`, `a-z` and `A-Z`.
|
* characters `0-9`, `a-z` and `A-Z`.
|
||||||
*
|
*
|
||||||
* Returns `true` if `c` is a valid digit under `radix`, and `false`
|
* Returns `true` if `c` is a valid digit under `radix`, and `false`
|
||||||
@@ -163,7 +157,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a number to the ascii character representing it.
|
* Converts a number to the character representing it.
|
||||||
*
|
*
|
||||||
* Returns `Some(char)` if `num` represents one digit under `radix`,
|
* Returns `Some(char)` if `num` represents one digit under `radix`,
|
||||||
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
|
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
|
||||||
@@ -316,12 +310,6 @@ fn test_to_digit() {
|
|||||||
assert!(to_digit('$', 36u).is_none());
|
assert!(to_digit('$', 36u).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_ascii() {
|
|
||||||
assert!(str::all(~"banana", is_ascii));
|
|
||||||
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_digit() {
|
fn test_is_digit() {
|
||||||
assert!(is_digit('2'));
|
assert!(is_digit('2'));
|
||||||
|
|||||||
@@ -10,16 +10,9 @@
|
|||||||
|
|
||||||
//! Operations and constants for `u8`
|
//! Operations and constants for `u8`
|
||||||
|
|
||||||
pub use self::inst::is_ascii;
|
|
||||||
|
|
||||||
mod inst {
|
mod inst {
|
||||||
pub type T = u8;
|
pub type T = u8;
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub type T_SIGNED = i8;
|
pub type T_SIGNED = i8;
|
||||||
pub static bits: uint = 8;
|
pub static bits: uint = 8;
|
||||||
|
|
||||||
// Type-specific functions here. These must be reexported by the
|
|
||||||
// parent module so that they appear in core::u8 and not core::u8::u8;
|
|
||||||
|
|
||||||
pub fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -753,7 +753,9 @@ impl GenericPath for WindowsPath {
|
|||||||
fn is_restricted(&self) -> bool {
|
fn is_restricted(&self) -> bool {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
Some(stem) => {
|
Some(stem) => {
|
||||||
match stem.to_lower() {
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
match stem.to_ascii().to_lower().to_str_ascii() {
|
||||||
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
|
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
|
||||||
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
|
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
|
||||||
_ => false
|
_ => false
|
||||||
@@ -809,7 +811,10 @@ impl GenericPath for WindowsPath {
|
|||||||
host: copy self.host,
|
host: copy self.host,
|
||||||
device: match self.device {
|
device: match self.device {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref device) => Some(device.to_upper())
|
|
||||||
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
Some(ref device) => Some(device.to_ascii().to_upper().to_str_ascii())
|
||||||
},
|
},
|
||||||
is_absolute: self.is_absolute,
|
is_absolute: self.is_absolute,
|
||||||
components: normalize(self.components)
|
components: normalize(self.components)
|
||||||
|
|||||||
@@ -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
|
* 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
|
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
|
/// Returns true if the string has length 0
|
||||||
pub fn is_empty(s: &str) -> bool { len(s) == 0u }
|
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 each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool);
|
||||||
fn starts_with<'a>(&self, needle: &'a str) -> bool;
|
fn starts_with<'a>(&self, needle: &'a str) -> bool;
|
||||||
fn substr(&self, begin: uint, n: uint) -> &'self str;
|
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_default(&self) -> ~str;
|
||||||
fn escape_unicode(&self) -> ~str;
|
fn escape_unicode(&self) -> ~str;
|
||||||
fn trim(&self) -> &'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 {
|
fn substr(&self, begin: uint, n: uint) -> &'self str {
|
||||||
substr(*self, begin, n)
|
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.
|
/// Escape each char in `s` with char::escape_default.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn escape_default(&self) -> ~str { escape_default(*self) }
|
fn escape_default(&self) -> ~str { escape_default(*self) }
|
||||||
@@ -3084,27 +3053,6 @@ mod tests {
|
|||||||
assert!(repeat(~"hi", 0) == ~"");
|
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]
|
#[test]
|
||||||
fn test_unsafe_slice() {
|
fn test_unsafe_slice() {
|
||||||
assert!("ab" == unsafe {raw::slice_bytes("abc", 0, 2)});
|
assert!("ab" == unsafe {raw::slice_bytes("abc", 0, 2)});
|
||||||
@@ -3337,13 +3285,6 @@ mod tests {
|
|||||||
assert!((!is_whitespace(~" _ ")));
|
assert!((!is_whitespace(~" _ ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_ascii() {
|
|
||||||
assert!((is_ascii(~"")));
|
|
||||||
assert!((is_ascii(~"a")));
|
|
||||||
assert!((!is_ascii(~"\u2009")));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shift_byte() {
|
fn test_shift_byte() {
|
||||||
let mut s = ~"ABC";
|
let mut s = ~"ABC";
|
||||||
|
|||||||
@@ -221,6 +221,9 @@ mod tests {
|
|||||||
assert_eq!('['.to_ascii().to_lower().to_char(), '[');
|
assert_eq!('['.to_ascii().to_lower().to_char(), '[');
|
||||||
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
|
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
|
||||||
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
|
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
|
||||||
|
|
||||||
|
assert!(str::all(~"banana", |c| c.is_ascii()));
|
||||||
|
assert!(! str::all(~"ประเทศไทย中华Việt Nam", |c| c.is_ascii()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -234,6 +237,15 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!("abCDef&?#".to_ascii().to_lower().to_str_ascii(), ~"abcdef&?#");
|
assert_eq!("abCDef&?#".to_ascii().to_lower().to_str_ascii(), ~"abcdef&?#");
|
||||||
assert_eq!("abCDef&?#".to_ascii().to_upper().to_str_ascii(), ~"ABCDEF&?#");
|
assert_eq!("abCDef&?#".to_ascii().to_upper().to_str_ascii(), ~"ABCDEF&?#");
|
||||||
|
|
||||||
|
assert_eq!("".to_ascii().to_lower().to_str_ascii(), ~"");
|
||||||
|
assert_eq!("YMCA".to_ascii().to_lower().to_str_ascii(), ~"ymca");
|
||||||
|
assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().to_str_ascii(), ~"ABCDEFXYZ:.;");
|
||||||
|
|
||||||
|
assert!("".is_ascii());
|
||||||
|
assert!("a".is_ascii());
|
||||||
|
assert!(!"\u2009".is_ascii());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -520,7 +520,10 @@ pub mod rt {
|
|||||||
match cv.ty {
|
match cv.ty {
|
||||||
TyDefault => uint_to_str_prec(u, 10, prec),
|
TyDefault => uint_to_str_prec(u, 10, prec),
|
||||||
TyHexLower => uint_to_str_prec(u, 16, prec),
|
TyHexLower => uint_to_str_prec(u, 16, prec),
|
||||||
TyHexUpper => str::to_upper(uint_to_str_prec(u, 16, prec)),
|
|
||||||
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
TyHexUpper => uint_to_str_prec(u, 16, prec).to_ascii().to_upper().to_str_ascii(),
|
||||||
TyBits => uint_to_str_prec(u, 2, prec),
|
TyBits => uint_to_str_prec(u, 2, prec),
|
||||||
TyOctal => uint_to_str_prec(u, 8, prec)
|
TyOctal => uint_to_str_prec(u, 8, prec)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -546,7 +546,10 @@ pub fn build_session_options(binary: @~str,
|
|||||||
let lint_dict = lint::get_lint_dict();
|
let lint_dict = lint::get_lint_dict();
|
||||||
for lint_levels.each |level| {
|
for lint_levels.each |level| {
|
||||||
let level_name = lint::level_to_str(*level);
|
let level_name = lint::level_to_str(*level);
|
||||||
let level_short = level_name.substr(0,1).to_upper();
|
|
||||||
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
let level_short = level_name.substr(0,1).to_ascii().to_upper().to_str_ascii();
|
||||||
let flags = vec::append(getopts::opt_strs(matches, level_short),
|
let flags = vec::append(getopts::opt_strs(matches, level_short),
|
||||||
getopts::opt_strs(matches, level_name));
|
getopts::opt_strs(matches, level_name));
|
||||||
for flags.each |lint_name| {
|
for flags.each |lint_name| {
|
||||||
|
|||||||
@@ -157,7 +157,9 @@ pub fn pandoc_header_id(header: &str) -> ~str {
|
|||||||
let s = str::replace(s, ~" ", ~"-");
|
let s = str::replace(s, ~" ", ~"-");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
fn convert_to_lowercase(s: &str) -> ~str { str::to_lower(s) }
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
fn convert_to_lowercase(s: &str) -> ~str { s.to_ascii().to_lower().to_str_ascii() }
|
||||||
fn remove_up_to_first_letter(s: &str) -> ~str { s.to_str() }
|
fn remove_up_to_first_letter(s: &str) -> ~str { s.to_str() }
|
||||||
fn maybe_use_section_id(s: &str) -> ~str { s.to_str() }
|
fn maybe_use_section_id(s: &str) -> ~str { s.to_str() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ fn parse_reader(rdr: @io::Reader) -> Version {
|
|||||||
|
|
||||||
|
|
||||||
pub fn parse(s: &str) -> Option<Version> {
|
pub fn parse(s: &str) -> Option<Version> {
|
||||||
if ! str::is_ascii(s) {
|
if !s.is_ascii() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let s = s.trim();
|
let s = s.trim();
|
||||||
|
|||||||
@@ -885,8 +885,12 @@ mod tests {
|
|||||||
// tjc: funny that we have to use parens
|
// tjc: funny that we have to use parens
|
||||||
fn ile(x: &(&'static str), y: &(&'static str)) -> bool
|
fn ile(x: &(&'static str), y: &(&'static str)) -> bool
|
||||||
{
|
{
|
||||||
let x = x.to_lower();
|
// FIXME: 4318 Instead of to_str_ascii, could use
|
||||||
let y = y.to_lower();
|
// to_str_consume to not do a unneccessary copy.
|
||||||
|
// (Actually, could just remove the to_str_* call, but needs an deriving(Ord) on
|
||||||
|
// Ascii)
|
||||||
|
let x = x.to_ascii().to_lower().to_str_ascii();
|
||||||
|
let y = y.to_ascii().to_lower().to_str_ascii();
|
||||||
x <= y
|
x <= y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user