1
Fork 0

Deprecate str::from_char

Use `String::from_char` or `.to_str` instead

[breaking-change]
This commit is contained in:
Adolfo Ochagavía 2014-07-04 22:08:16 +02:00
parent 20a6894830
commit 05baf9b10c
5 changed files with 17 additions and 21 deletions

View file

@ -125,6 +125,7 @@ pub fn from_utf8_owned(vv: Vec<u8>) -> Result<String, Vec<u8>> {
/// 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)
@ -139,8 +140,9 @@ pub fn from_byte(b: u8) -> String {
/// 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

View file

@ -619,7 +619,7 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
Public => 'y',
Inherited => 'i',
};
ebml_w.wr_str(str::from_char(ch).as_slice());
ebml_w.wr_str(ch.to_str().as_slice());
ebml_w.end_tag();
}

View file

@ -525,7 +525,6 @@ static ASCII_UPPER_MAP: &'static [u8] = &[
mod tests {
use prelude::*;
use super::*;
use str::from_char;
use char::from_u32;
use vec::Vec;
use str::StrSlice;
@ -677,8 +676,8 @@ mod tests {
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;
}
}
@ -693,8 +692,8 @@ mod tests {
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;
}
}
@ -709,8 +708,8 @@ mod tests {
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;
}
}
@ -726,8 +725,8 @@ mod tests {
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;
}
}
@ -747,11 +746,8 @@ mod tests {
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;
}
}

View file

@ -59,7 +59,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
// Look for the terminal in all of the search directories
for p in dirs_to_search.iter() {
if p.exists() {
let f = str::from_char(first_char);
let f = first_char.to_str();
let newp = p.join_many([f.as_slice(), term]);
if newp.exists() {
return Some(box newp);

View file

@ -486,9 +486,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
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))
}
}
@ -789,7 +787,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
}
'%' => parse_char(s, pos, '%'),
ch => {
Err(format!("unknown formatting type: {}", str::from_char(ch)))
Err(format!("unknown formatting type: {}", ch))
}
}
}