/// let string = str::from_byte(104);
/// assert_eq!(string.as_slice(), "h");
/// ```
+#[deprecated = "Replaced by String::from_byte"]
pub fn from_byte(b: u8) -> String {
assert!(b < 128u8);
String::from_char(1, b as char)
/// let string = str::from_char('b');
/// assert_eq!(string.as_slice(), "b");
/// ```
+#[deprecated = "use String::from_char or char.to_string()"]
pub fn from_char(ch: char) -> String {
- String::from_char(ch)
+ String::from_char(1, ch)
}
/// Convert a vector of chars to a string
mod tests {
use prelude::*;
use super::*;
- use str::from_char;
use char::from_u32;
use vec::Vec;
use str::StrSlice;
while i <= 500 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i };
- assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_upper(),
- from_char(from_u32(upper).unwrap()).to_string())
+ assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_upper(),
+ (from_u32(upper).unwrap()).to_str())
i += 1;
}
}
while i <= 500 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i };
- assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_lower(),
- from_char(from_u32(lower).unwrap()).to_string())
+ assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_lower(),
+ (from_u32(lower).unwrap()).to_str())
i += 1;
}
}
while i <= 500 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i };
- assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_upper(),
- from_char(from_u32(upper).unwrap()).to_string())
+ assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_upper(),
+ (from_u32(upper).unwrap()).to_str())
i += 1;
}
}
while i <= 500 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i };
- assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_lower(),
- from_char(from_u32(lower).unwrap()).to_string())
+ assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_lower(),
+ (from_u32(lower).unwrap()).to_str())
i += 1;
}
}
let c = i;
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
else { c };
- assert!(from_char(from_u32(i).unwrap()).as_slice()
- .eq_ignore_ascii_case(
- from_char(
- from_u32(lower)
- .unwrap()).as_slice()));
+ assert!((from_u32(i).unwrap()).to_str().as_slice().eq_ignore_ascii_case(
+ (from_u32(lower).unwrap()).to_str().as_slice()));
i += 1;
}
}
if c == range.ch {
Ok(range.next)
} else {
- Err(format!("Expected {}, found {}",
- str::from_char(c),
- str::from_char(range.ch)))
+ Err(format!("Expected {}, found {}", c, range.ch))
}
}
}
'%' => parse_char(s, pos, '%'),
ch => {
- Err(format!("unknown formatting type: {}", str::from_char(ch)))
+ Err(format!("unknown formatting type: {}", ch))
}
}
}