auto merge of #8960 : Kimundi/rust/master, r=alexcrichton
Changed ToStr impl for Ascii Added ToStr impl for char
This commit is contained in:
commit
142dab4e4f
@ -14,6 +14,8 @@
|
||||
use int;
|
||||
use str::StrSlice;
|
||||
use unicode::{derived_property, general_category, decompose};
|
||||
use to_str::ToStr;
|
||||
use str;
|
||||
|
||||
#[cfg(test)] use str::OwnedStr;
|
||||
|
||||
@ -316,6 +318,13 @@ pub fn len_utf8_bytes(c: char) -> uint {
|
||||
)
|
||||
}
|
||||
|
||||
impl ToStr for char {
|
||||
#[inline]
|
||||
fn to_str(&self) -> ~str {
|
||||
str::from_char(*self)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(missing_doc)]
|
||||
pub trait Char {
|
||||
fn is_alphabetic(&self) -> bool;
|
||||
@ -502,3 +511,9 @@ fn string(c: char) -> ~str {
|
||||
assert_eq!(string('\u011b'), ~"\\u011b");
|
||||
assert_eq!(string('\U0001d4b6'), ~"\\U0001d4b6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
let s = 't'.to_str();
|
||||
assert_eq!(s, ~"t");
|
||||
}
|
||||
|
@ -60,7 +60,10 @@ pub fn eq_ignore_case(self, other: Ascii) -> bool {
|
||||
|
||||
impl ToStr for Ascii {
|
||||
#[inline]
|
||||
fn to_str(&self) -> ~str { str::from_bytes(['\'' as u8, self.chr, '\'' as u8]) }
|
||||
fn to_str(&self) -> ~str {
|
||||
// self.chr is allways a valid utf8 byte, no need for the check
|
||||
unsafe { str::raw::from_byte(self.chr) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for converting into an ascii type.
|
||||
@ -506,4 +509,12 @@ fn test_eq_ignore_ascii_case() {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
let s = Ascii{ chr: 't' as u8 }.to_str();
|
||||
assert_eq!(s, ~"t");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user