1
Fork 0

Rename str::from_bytes to str::from_utf8, closes #8985

This commit is contained in:
Florian Hahn 2013-09-05 14:17:24 +02:00
parent 422dcbd56d
commit de39874801
38 changed files with 147 additions and 147 deletions

View file

@ -63,7 +63,7 @@ pub fn run(lib_path: &str,
Result { Result {
status: output.status, status: output.status,
out: str::from_bytes(output.output), out: str::from_utf8(output.output),
err: str::from_bytes(output.error) err: str::from_utf8(output.error)
} }
} }

View file

@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] {
} }
unsafe { unsafe {
str::raw::from_bytes_owned(v) str::raw::from_utf8_owned(v)
} }
} }
} }
@ -162,7 +162,7 @@ impl<'self> FromBase64 for &'self str {
* Convert any base64 encoded string (literal, `@`, `&`, or `~`) * Convert any base64 encoded string (literal, `@`, `&`, or `~`)
* to the byte values it encodes. * to the byte values it encodes.
* *
* You can use the `from_bytes` function in `std::str` * You can use the `from_utf8` function in `std::str`
* to turn a `[u8]` into a string with characters corresponding to those * to turn a `[u8]` into a string with characters corresponding to those
* values. * values.
* *
@ -180,7 +180,7 @@ impl<'self> FromBase64 for &'self str {
* printfln!("%s", hello_str); * printfln!("%s", hello_str);
* let bytes = hello_str.from_base64(); * let bytes = hello_str.from_base64();
* printfln!("%?", bytes); * printfln!("%?", bytes);
* let result_str = str::from_bytes(bytes); * let result_str = str::from_utf8(bytes);
* printfln!("%s", result_str); * printfln!("%s", result_str);
* } * }
* ~~~ * ~~~

View file

@ -523,7 +523,7 @@ impl Bitv {
* with the most significant bits of each byte coming first. Each * with the most significant bits of each byte coming first. Each
* bit becomes true if equal to 1 or false if equal to 0. * bit becomes true if equal to 1 or false if equal to 0.
*/ */
pub fn from_bytes(bytes: &[u8]) -> Bitv { pub fn from_utf8(bytes: &[u8]) -> Bitv {
from_fn(bytes.len() * 8, |i| { from_fn(bytes.len() * 8, |i| {
let b = bytes[i / 8] as uint; let b = bytes[i / 8] as uint;
let offset = i % 8; let offset = i % 8;
@ -1275,8 +1275,8 @@ mod tests {
} }
#[test] #[test]
fn test_from_bytes() { fn test_from_utf8() {
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]); let bitv = from_utf8([0b10110110, 0b00000000, 0b11111111]);
let str = ~"10110110" + "00000000" + "11111111"; let str = ~"10110110" + "00000000" + "11111111";
assert_eq!(bitv.to_str(), str); assert_eq!(bitv.to_str(), str);
} }
@ -1302,7 +1302,7 @@ mod tests {
#[test] #[test]
fn test_to_bools() { fn test_to_bools() {
let bools = ~[false, false, true, false, false, true, true, false]; let bools = ~[false, false, true, false, false, true, true, false];
assert_eq!(from_bytes([0b00100110]).to_bools(), bools); assert_eq!(from_utf8([0b00100110]).to_bools(), bools);
} }
#[test] #[test]

View file

@ -41,7 +41,7 @@ impl Doc {
} }
pub fn as_str_slice<'a>(&'a self) -> &'a str { pub fn as_str_slice<'a>(&'a self) -> &'a str {
str::from_bytes_slice(self.data.slice(self.start, self.end)) str::from_utf8_slice(self.data.slice(self.start, self.end))
} }
pub fn as_str(&self) -> ~str { pub fn as_str(&self) -> ~str {

View file

@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] {
} }
unsafe { unsafe {
str::raw::from_bytes_owned(v) str::raw::from_utf8_owned(v)
} }
} }
} }
@ -62,7 +62,7 @@ impl<'self> FromHex for &'self str {
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`) * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
* to the byte values it encodes. * to the byte values it encodes.
* *
* You can use the `from_bytes` function in `std::str` * You can use the `from_utf8` function in `std::str`
* to turn a `[u8]` into a string with characters corresponding to those * to turn a `[u8]` into a string with characters corresponding to those
* values. * values.
* *
@ -80,7 +80,7 @@ impl<'self> FromHex for &'self str {
* printfln!("%s", hello_str); * printfln!("%s", hello_str);
* let bytes = hello_str.from_hex().unwrap(); * let bytes = hello_str.from_hex().unwrap();
* printfln!("%?", bytes); * printfln!("%?", bytes);
* let result_str = str::from_bytes(bytes); * let result_str = str::from_utf8(bytes);
* printfln!("%s", result_str); * printfln!("%s", result_str);
* } * }
* ~~~ * ~~~

View file

@ -858,7 +858,7 @@ impl<T : iterator::Iterator<char>> Parser<T> {
/// Decodes a json value from an @io::Reader /// Decodes a json value from an @io::Reader
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> { pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
let s = str::from_bytes(rdr.read_whole_stream()); let s = str::from_utf8(rdr.read_whole_stream());
let mut parser = Parser(~s.iter()); let mut parser = Parser(~s.iter());
parser.parse() parser.parse()
} }

View file

@ -213,7 +213,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
return Err(~"incompatible file: more string offsets than expected"); return Err(~"incompatible file: more string offsets than expected");
} }
let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect(); let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect();
file.read_byte(); // consume NUL file.read_byte(); // consume NUL

View file

@ -210,7 +210,7 @@ impl Uuid {
/// ///
/// # Arguments /// # Arguments
/// * `b` An array or slice of 16 bytes /// * `b` An array or slice of 16 bytes
pub fn from_bytes(b: &[u8]) -> Option<Uuid> { pub fn from_utf8(b: &[u8]) -> Option<Uuid> {
if b.len() != 16 { if b.len() != 16 {
return None return None
} }
@ -307,7 +307,7 @@ impl Uuid {
s[i*2+0] = digit[0]; s[i*2+0] = digit[0];
s[i*2+1] = digit[1]; s[i*2+1] = digit[1];
} }
str::from_bytes(s) str::from_utf8(s)
} }
/// Returns a string of hexadecimal digits, separated into groups with a hypen /// Returns a string of hexadecimal digits, separated into groups with a hypen
@ -413,7 +413,7 @@ impl Uuid {
ub[i] = FromStrRadix::from_str_radix(vs.slice(i*2, (i+1)*2), 16).unwrap(); ub[i] = FromStrRadix::from_str_radix(vs.slice(i*2, (i+1)*2), 16).unwrap();
} }
Ok(Uuid::from_bytes(ub).unwrap()) Ok(Uuid::from_utf8(ub).unwrap())
} }
} }
@ -705,11 +705,11 @@ mod test {
} }
#[test] #[test]
fn test_from_bytes() { fn test_from_utf8() {
let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ]; 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
let u = Uuid::from_bytes(b).unwrap(); let u = Uuid::from_utf8(b).unwrap();
let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8";
assert!(u.to_simple_str() == expected); assert!(u.to_simple_str() == expected);
@ -729,7 +729,7 @@ mod test {
let b_in: [u8, ..16] = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, let b_in: [u8, ..16] = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ]; 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
let u = Uuid::from_bytes(b_in.clone()).unwrap(); let u = Uuid::from_utf8(b_in.clone()).unwrap();
let b_out = u.to_bytes(); let b_out = u.to_bytes();

View file

@ -386,7 +386,7 @@ pub mod write {
cc_prog, prog.status)); cc_prog, prog.status));
sess.note(fmt!("%s arguments: %s", sess.note(fmt!("%s arguments: %s",
cc_prog, cc_args.connect(" "))); cc_prog, cc_args.connect(" ")));
sess.note(str::from_bytes(prog.error + prog.output)); sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors(); sess.abort_if_errors();
} }
} }
@ -943,7 +943,7 @@ pub fn link_binary(sess: Session,
cc_prog, prog.status)); cc_prog, prog.status));
sess.note(fmt!("%s arguments: %s", sess.note(fmt!("%s arguments: %s",
cc_prog, cc_args.connect(" "))); cc_prog, cc_args.connect(" ")));
sess.note(str::from_bytes(prog.error + prog.output)); sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors(); sess.abort_if_errors();
} }

View file

@ -1239,7 +1239,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) {
do reader::with_doc_data(d) |desc| { do reader::with_doc_data(d) |desc| {
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint; let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
let pathbytes = desc.slice(4u, desc.len()); let pathbytes = desc.slice(4u, desc.len());
let path = str::from_bytes(pathbytes); let path = str::from_utf8(pathbytes);
(path, pos) (path, pos)
} }

View file

@ -97,7 +97,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) -> fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) ->
ast::Ident { ast::Ident {
let rslt = scan(st, is_last, str::from_bytes); let rslt = scan(st, is_last, str::from_utf8);
return st.tcx.sess.ident_of(rslt); return st.tcx.sess.ident_of(rslt);
} }
@ -477,7 +477,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
let mut abis = AbiSet::empty(); let mut abis = AbiSet::empty();
while peek(st) != ']' { while peek(st) != ']' {
// FIXME(#5422) str API should not force this copy // FIXME(#5422) str API should not force this copy
let abi_str = scan(st, |c| c == ',', str::from_bytes); let abi_str = scan(st, |c| c == ',', str::from_utf8);
let abi = abi::lookup(abi_str).expect(abi_str); let abi = abi::lookup(abi_str).expect(abi_str);
abis.add(abi); abis.add(abi);
} }

View file

@ -161,7 +161,7 @@ Available lint options:
max_key = num::max(name.len(), max_key); max_key = num::max(name.len(), max_key);
} }
fn padded(max: uint, s: &str) -> ~str { fn padded(max: uint, s: &str) -> ~str {
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s str::from_utf8(vec::from_elem(max - s.len(), ' ' as u8)) + s
} }
println("\nAvailable lint checks:\n"); println("\nAvailable lint checks:\n");
printfln!(" %s %7.7s %s", printfln!(" %s %7.7s %s",
@ -244,7 +244,7 @@ pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
1u => { 1u => {
let ifile = matches.free[0].as_slice(); let ifile = matches.free[0].as_slice();
if "-" == ifile { if "-" == ifile {
let src = str::from_bytes(io::stdin().read_whole_stream()); let src = str::from_utf8(io::stdin().read_whole_stream());
str_input(src.to_managed()) str_input(src.to_managed())
} else { } else {
file_input(Path(ifile)) file_input(Path(ifile))

View file

@ -116,8 +116,8 @@ fn pandoc_writer(
debug!("pandoc result: %i", output.status); debug!("pandoc result: %i", output.status);
if output.status != 0 { if output.status != 0 {
error!("pandoc-out: %s", str::from_bytes(output.output)); error!("pandoc-out: %s", str::from_utf8(output.output));
error!("pandoc-err: %s", str::from_bytes(output.error)); error!("pandoc-err: %s", str::from_utf8(output.error));
fail!("pandoc failed"); fail!("pandoc failed");
} }
} }

View file

@ -153,7 +153,7 @@ impl<'self> PkgScript<'self> {
exe.to_str(), sysroot.to_str(), "configs"); exe.to_str(), sysroot.to_str(), "configs");
let output = run::process_output(exe.to_str(), [sysroot.to_str(), ~"configs"]); let output = run::process_output(exe.to_str(), [sysroot.to_str(), ~"configs"]);
// Run the configs() function to get the configs // Run the configs() function to get the configs
let cfgs = str::from_bytes_slice(output.output).word_iter() let cfgs = str::from_utf8_slice(output.output).word_iter()
.map(|w| w.to_owned()).collect(); .map(|w| w.to_owned()).collect();
(cfgs, output.status) (cfgs, output.status)
} }

View file

@ -22,8 +22,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
debug!("Running: git clone %s %s", source.to_str(), target.to_str()); debug!("Running: git clone %s %s", source.to_str(), target.to_str());
let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]); let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]);
if outp.status != 0 { if outp.status != 0 {
io::println(str::from_bytes_owned(outp.output.clone())); io::println(str::from_utf8_owned(outp.output.clone()));
io::println(str::from_bytes_owned(outp.error)); io::println(str::from_utf8_owned(outp.error));
fail!("Couldn't `git clone` %s", source.to_str()); fail!("Couldn't `git clone` %s", source.to_str());
} }
else { else {
@ -36,8 +36,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
fmt!("--git-dir=%s", target.push(".git").to_str()), fmt!("--git-dir=%s", target.push(".git").to_str()),
~"checkout", fmt!("%s", *s)]); ~"checkout", fmt!("%s", *s)]);
if outp.status != 0 { if outp.status != 0 {
io::println(str::from_bytes_owned(outp.output.clone())); io::println(str::from_utf8_owned(outp.output.clone()));
io::println(str::from_bytes_owned(outp.error)); io::println(str::from_utf8_owned(outp.error));
fail!("Couldn't `git checkout %s` in %s", fail!("Couldn't `git checkout %s` in %s",
*s, target.to_str()); *s, target.to_str());
} }
@ -64,8 +64,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool { pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool {
let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]); let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]);
if outp.status != 0 { if outp.status != 0 {
debug!(str::from_bytes_owned(outp.output.clone())); debug!(str::from_utf8_owned(outp.output.clone()));
debug!(str::from_bytes_owned(outp.error)); debug!(str::from_utf8_owned(outp.error));
false false
} }
else { else {
@ -74,8 +74,8 @@ pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool {
let outp = process_output_in_cwd("git", [~"checkout", fmt!("%s", *s)], let outp = process_output_in_cwd("git", [~"checkout", fmt!("%s", *s)],
target); target);
if outp.status != 0 { if outp.status != 0 {
debug!(str::from_bytes_owned(outp.output.clone())); debug!(str::from_utf8_owned(outp.output.clone()));
debug!(str::from_bytes_owned(outp.error)); debug!(str::from_utf8_owned(outp.error));
false false
} }
else { else {

View file

@ -123,7 +123,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
let rslt = prog.finish_with_output(); let rslt = prog.finish_with_output();
if rslt.status != 0 { if rslt.status != 0 {
fail!("%s [git returned %?, output = %s, error = %s]", err_msg, fail!("%s [git returned %?, output = %s, error = %s]", err_msg,
rslt.status, str::from_bytes(rslt.output), str::from_bytes(rslt.error)); rslt.status, str::from_utf8(rslt.output), str::from_utf8(rslt.error));
} }
} }
@ -230,8 +230,8 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
}); });
let output = prog.finish_with_output(); let output = prog.finish_with_output();
debug!("Output from command %s with args %? was %s {%s}[%?]", debug!("Output from command %s with args %? was %s {%s}[%?]",
cmd, args, str::from_bytes(output.output), cmd, args, str::from_utf8(output.output),
str::from_bytes(output.error), str::from_utf8(output.error),
output.status); output.status);
/* /*
By the way, rustpkg *won't* return a nonzero exit code if it fails -- By the way, rustpkg *won't* return a nonzero exit code if it fails --
@ -242,7 +242,7 @@ to make sure the command succeeded
if output.status != 0 { if output.status != 0 {
fail!("Command %s %? failed with exit code %?; its output was {{{ %s }}}", fail!("Command %s %? failed with exit code %?; its output was {{{ %s }}}",
cmd, args, output.status, cmd, args, output.status,
str::from_bytes(output.output) + str::from_bytes(output.error)); str::from_utf8(output.output) + str::from_utf8(output.error));
} }
output output
} }
@ -358,7 +358,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
fn command_line_test_output(args: &[~str]) -> ~[~str] { fn command_line_test_output(args: &[~str]) -> ~[~str] {
let mut result = ~[]; let mut result = ~[];
let p_output = command_line_test(args, &os::getcwd()); let p_output = command_line_test(args, &os::getcwd());
let test_output = str::from_bytes(p_output.output); let test_output = str::from_utf8(p_output.output);
for s in test_output.split_iter('\n') { for s in test_output.split_iter('\n') {
result.push(s.to_owned()); result.push(s.to_owned());
} }
@ -368,7 +368,7 @@ fn command_line_test_output(args: &[~str]) -> ~[~str] {
fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~str] { fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~str] {
let mut result = ~[]; let mut result = ~[];
let p_output = command_line_test_with_env(args, &os::getcwd(), Some(env)); let p_output = command_line_test_with_env(args, &os::getcwd(), Some(env));
let test_output = str::from_bytes(p_output.output); let test_output = str::from_utf8(p_output.output);
for s in test_output.split_iter('\n') { for s in test_output.split_iter('\n') {
result.push(s.to_owned()); result.push(s.to_owned());
} }
@ -985,7 +985,7 @@ fn test_info() {
let expected_info = ~"package foo"; // fill in let expected_info = ~"package foo"; // fill in
let workspace = create_local_package(&PkgId::new("foo")); let workspace = create_local_package(&PkgId::new("foo"));
let output = command_line_test([~"info", ~"foo"], &workspace); let output = command_line_test([~"info", ~"foo"], &workspace);
assert_eq!(str::from_bytes(output.output), expected_info); assert_eq!(str::from_utf8(output.output), expected_info);
} }
#[test] #[test]
@ -994,7 +994,7 @@ fn test_rustpkg_test() {
let expected_results = ~"1 out of 1 tests passed"; // fill in let expected_results = ~"1 out of 1 tests passed"; // fill in
let workspace = create_local_package_with_test(&PkgId::new("foo")); let workspace = create_local_package_with_test(&PkgId::new("foo"));
let output = command_line_test([~"test", ~"foo"], &workspace); let output = command_line_test([~"test", ~"foo"], &workspace);
assert_eq!(str::from_bytes(output.output), expected_results); assert_eq!(str::from_utf8(output.output), expected_results);
} }
#[test] #[test]
@ -1004,7 +1004,7 @@ fn test_uninstall() {
let _output = command_line_test([~"info", ~"foo"], &workspace); let _output = command_line_test([~"info", ~"foo"], &workspace);
command_line_test([~"uninstall", ~"foo"], &workspace); command_line_test([~"uninstall", ~"foo"], &workspace);
let output = command_line_test([~"list"], &workspace); let output = command_line_test([~"list"], &workspace);
assert!(!str::from_bytes(output.output).contains("foo")); assert!(!str::from_utf8(output.output).contains("foo"));
} }
#[test] #[test]
@ -1073,8 +1073,8 @@ fn test_extern_mod() {
let outp = prog.finish_with_output(); let outp = prog.finish_with_output();
if outp.status != 0 { if outp.status != 0 {
fail!("output was %s, error was %s", fail!("output was %s, error was %s",
str::from_bytes(outp.output), str::from_utf8(outp.output),
str::from_bytes(outp.error)); str::from_utf8(outp.error));
} }
assert!(os::path_exists(&exec_file) && is_executable(&exec_file)); assert!(os::path_exists(&exec_file) && is_executable(&exec_file));
} }

View file

@ -111,7 +111,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
} }
let mut output = None; let mut output = None;
let output_text = str::from_bytes(outp.output); let output_text = str::from_utf8(outp.output);
for l in output_text.line_iter() { for l in output_text.line_iter() {
if !l.is_whitespace() { if !l.is_whitespace() {
output = Some(l); output = Some(l);
@ -141,15 +141,15 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
tmp_dir.to_str()]); tmp_dir.to_str()]);
if outp.status == 0 { if outp.status == 0 {
debug!("Cloned it... ( %s, %s )", debug!("Cloned it... ( %s, %s )",
str::from_bytes(outp.output), str::from_utf8(outp.output),
str::from_bytes(outp.error)); str::from_utf8(outp.error));
let mut output = None; let mut output = None;
debug!("(getting version, now getting tags) executing {git --git-dir=%s tag -l}", debug!("(getting version, now getting tags) executing {git --git-dir=%s tag -l}",
tmp_dir.push(".git").to_str()); tmp_dir.push(".git").to_str());
let outp = run::process_output("git", let outp = run::process_output("git",
[fmt!("--git-dir=%s", tmp_dir.push(".git").to_str()), [fmt!("--git-dir=%s", tmp_dir.push(".git").to_str()),
~"tag", ~"-l"]); ~"tag", ~"-l"]);
let output_text = str::from_bytes(outp.output); let output_text = str::from_utf8(outp.output);
debug!("Full output: ( %s ) [%?]", output_text, outp.status); debug!("Full output: ( %s ) [%?]", output_text, outp.status);
for l in output_text.line_iter() { for l in output_text.line_iter() {
debug!("A line of output: %s", l); debug!("A line of output: %s", l);

View file

@ -468,7 +468,7 @@ pub unsafe fn write(output: &mut io::Writer,
pub unsafe fn format(fmt: &[rt::Piece], args: &[Argument]) -> ~str { pub unsafe fn format(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
let mut output = MemWriter::new(); let mut output = MemWriter::new();
write(&mut output as &mut io::Writer, fmt, args); write(&mut output as &mut io::Writer, fmt, args);
return str::from_bytes_owned(output.inner()); return str::from_utf8_owned(output.inner());
} }
impl<'self> Formatter<'self> { impl<'self> Formatter<'self> {
@ -589,7 +589,7 @@ impl<'self> Formatter<'self> {
fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) { fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) {
do ::uint::to_str_bytes(value, 10) |buf| { do ::uint::to_str_bytes(value, 10) |buf| {
let valuestr = str::from_bytes_slice(buf); let valuestr = str::from_utf8_slice(buf);
for piece in pieces.iter() { for piece in pieces.iter() {
self.run(piece, Some(valuestr)); self.run(piece, Some(valuestr));
} }

View file

@ -642,7 +642,7 @@ impl<T:Reader> ReaderUtil for T {
} }
bytes.push(ch as u8); bytes.push(ch as u8);
} }
str::from_bytes(bytes) str::from_utf8(bytes)
} }
fn read_line(&self) -> ~str { fn read_line(&self) -> ~str {
@ -651,7 +651,7 @@ impl<T:Reader> ReaderUtil for T {
fn read_chars(&self, n: uint) -> ~[char] { fn read_chars(&self, n: uint) -> ~[char] {
// returns the (consumed offset, n_req), appends characters to &chars // returns the (consumed offset, n_req), appends characters to &chars
fn chars_from_bytes<T:Reader>(bytes: &~[u8], chars: &mut ~[char]) fn chars_from_utf8<T:Reader>(bytes: &~[u8], chars: &mut ~[char])
-> (uint, uint) { -> (uint, uint) {
let mut i = 0; let mut i = 0;
let bytes_len = bytes.len(); let bytes_len = bytes.len();
@ -701,7 +701,7 @@ impl<T:Reader> ReaderUtil for T {
break; break;
} }
bytes.push_all(data); bytes.push_all(data);
let (offset, nbreq) = chars_from_bytes::<T>(&bytes, &mut chars); let (offset, nbreq) = chars_from_utf8::<T>(&bytes, &mut chars);
let ncreq = n - chars.len(); let ncreq = n - chars.len();
// again we either know we need a certain number of bytes // again we either know we need a certain number of bytes
// to complete a character, or we make sure we don't // to complete a character, or we make sure we don't
@ -1761,7 +1761,7 @@ pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
} }
pub fn with_str_writer(f: &fn(@Writer)) -> ~str { pub fn with_str_writer(f: &fn(@Writer)) -> ~str {
str::from_bytes(with_bytes_writer(f)) str::from_utf8(with_bytes_writer(f))
} }
// Utility functions // Utility functions
@ -1781,7 +1781,7 @@ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> { pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
do read_whole_file(file).chain |bytes| { do read_whole_file(file).chain |bytes| {
if str::is_utf8(bytes) { if str::is_utf8(bytes) {
Ok(str::from_bytes(bytes)) Ok(str::from_utf8(bytes))
} else { } else {
Err(file.to_str() + " is not UTF-8") Err(file.to_str() + " is not UTF-8")
} }

View file

@ -541,7 +541,7 @@ impl ToStrRadix for $T {
} }
// We know we generated valid utf-8, so we don't need to go through that // We know we generated valid utf-8, so we don't need to go through that
// check. // check.
unsafe { str::raw::from_bytes_owned(buf) } unsafe { str::raw::from_utf8_owned(buf) }
} }
} }

View file

@ -417,7 +417,7 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+Round+
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) { sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
let (bytes, special) = float_to_str_bytes_common(num, radix, let (bytes, special) = float_to_str_bytes_common(num, radix,
negative_zero, sign, digits); negative_zero, sign, digits);
(str::from_bytes(bytes), special) (str::from_utf8(bytes), special)
} }
// Some constants for from_str_bytes_common's input validation, // Some constants for from_str_bytes_common's input validation,

View file

@ -396,7 +396,7 @@ impl ToStrRadix for $T {
} }
// We know we generated valid utf-8, so we don't need to go through that // We know we generated valid utf-8, so we don't need to go through that
// check. // check.
unsafe { str::raw::from_bytes_owned(buf) } unsafe { str::raw::from_utf8_owned(buf) }
} }
} }

View file

@ -634,7 +634,7 @@ fn test_repr() {
fn exact_test<T>(t: &T, e:&str) { fn exact_test<T>(t: &T, e:&str) {
let mut m = io::mem::MemWriter::new(); let mut m = io::mem::MemWriter::new();
write_repr(&mut m as &mut io::Writer, t); write_repr(&mut m as &mut io::Writer, t);
let s = str::from_bytes_owned(m.inner()); let s = str::from_utf8_owned(m.inner());
assert_eq!(s.as_slice(), e); assert_eq!(s.as_slice(), e);
} }

View file

@ -159,7 +159,7 @@ fn file_test_smoke_test_impl() {
let mut read_buf = [0, .. 1028]; let mut read_buf = [0, .. 1028];
let read_str = match read_stream.read(read_buf).unwrap() { let read_str = match read_stream.read(read_buf).unwrap() {
-1|0 => fail!("shouldn't happen"), -1|0 => fail!("shouldn't happen"),
n => str::from_bytes(read_buf.slice_to(n)) n => str::from_utf8(read_buf.slice_to(n))
}; };
assert!(read_str == message.to_owned()); assert!(read_str == message.to_owned());
} }
@ -230,7 +230,7 @@ fn file_test_io_non_positional_read_impl() {
} }
} }
unlink(filename); unlink(filename);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
assert!(read_str == message.to_owned()); assert!(read_str == message.to_owned());
} }
} }
@ -262,7 +262,7 @@ fn file_test_io_seeking_impl() {
tell_pos_post_read = read_stream.tell(); tell_pos_post_read = read_stream.tell();
} }
unlink(filename); unlink(filename);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
assert!(read_str == message.slice(4, 8).to_owned()); assert!(read_str == message.slice(4, 8).to_owned());
assert!(tell_pos_pre_read == set_cursor); assert!(tell_pos_pre_read == set_cursor);
assert!(tell_pos_post_read == message.len() as u64); assert!(tell_pos_post_read == message.len() as u64);
@ -295,7 +295,7 @@ fn file_test_io_seek_and_write_impl() {
read_stream.read(read_mem); read_stream.read(read_mem);
} }
unlink(filename); unlink(filename);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
io::println(fmt!("read_str: '%?' final_msg: '%?'", read_str, final_msg)); io::println(fmt!("read_str: '%?' final_msg: '%?'", read_str, final_msg));
assert!(read_str == final_msg.to_owned()); assert!(read_str == final_msg.to_owned());
} }
@ -324,17 +324,17 @@ fn file_test_io_seek_shakedown_impl() {
read_stream.seek(-4, SeekEnd); read_stream.seek(-4, SeekEnd);
read_stream.read(read_mem); read_stream.read(read_mem);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
assert!(read_str == chunk_three.to_owned()); assert!(read_str == chunk_three.to_owned());
read_stream.seek(-9, SeekCur); read_stream.seek(-9, SeekCur);
read_stream.read(read_mem); read_stream.read(read_mem);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
assert!(read_str == chunk_two.to_owned()); assert!(read_str == chunk_two.to_owned());
read_stream.seek(0, SeekSet); read_stream.seek(0, SeekSet);
read_stream.read(read_mem); read_stream.read(read_mem);
let read_str = str::from_bytes(read_mem); let read_str = str::from_utf8(read_mem);
assert!(read_str == chunk_one.to_owned()); assert!(read_str == chunk_one.to_owned());
} }
unlink(filename); unlink(filename);

View file

@ -117,7 +117,7 @@ mod test {
let mut out_bytes = [0, .. 100]; let mut out_bytes = [0, .. 100];
let bytes_read = inflate_reader.read(out_bytes).unwrap(); let bytes_read = inflate_reader.read(out_bytes).unwrap();
assert_eq!(bytes_read, in_bytes.len()); assert_eq!(bytes_read, in_bytes.len());
let out_msg = str::from_bytes(out_bytes); let out_msg = str::from_utf8(out_bytes);
assert!(in_msg == out_msg); assert!(in_msg == out_msg);
} }
} }

View file

@ -329,7 +329,7 @@ mod test {
if nread > 0 { if nread > 0 {
let read_str = unsafe { let read_str = unsafe {
let read_buf = *read_buf_ptr; let read_buf = *read_buf_ptr;
str::from_bytes( str::from_utf8(
vec::from_buf( vec::from_buf(
read_buf.base, nread)) read_buf.base, nread))
}; };
@ -393,7 +393,7 @@ mod test {
// nread == 0 would be EOF.. we know it's >= zero because otherwise // nread == 0 would be EOF.. we know it's >= zero because otherwise
// the above assert would fail // the above assert would fail
if nread > 0 { if nread > 0 {
let read_str = str::from_bytes( let read_str = str::from_utf8(
read_mem.slice(0, nread as uint)); read_mem.slice(0, nread as uint));
assert!(read_str == ~"hello"); assert!(read_str == ~"hello");
// close // close

View file

@ -83,7 +83,7 @@ fn uv_socket_addr_as_socket_addr<T>(addr: UvSocketAddr, f: &fn(SocketAddr) -> T)
}; };
port as u16 port as u16
}; };
let ip_str = str::from_bytes_slice(ip_name).trim_right_chars(&'\x00'); let ip_str = str::from_utf8_slice(ip_name).trim_right_chars(&'\x00');
let ip_addr = FromStr::from_str(ip_str).unwrap(); let ip_addr = FromStr::from_str(ip_str).unwrap();
// finally run the closure // finally run the closure

View file

@ -1812,7 +1812,7 @@ fn file_test_uvio_full_simple_impl() {
let mut fd = (*io).fs_open(&Path(path), ro_fm, ro_fa).unwrap(); let mut fd = (*io).fs_open(&Path(path), ro_fm, ro_fa).unwrap();
let mut read_vec = [0, .. 1028]; let mut read_vec = [0, .. 1028];
let nread = fd.read(read_vec).unwrap(); let nread = fd.read(read_vec).unwrap();
let read_val = str::from_bytes(read_vec.slice(0, nread as uint)); let read_val = str::from_utf8(read_vec.slice(0, nread as uint));
assert!(read_val == write_val.to_owned()); assert!(read_val == write_val.to_owned());
} }
(*io).fs_unlink(&Path(path)); (*io).fs_unlink(&Path(path));

View file

@ -997,7 +997,7 @@ mod tests {
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= run::process_output("echo", [~"hello"]); = run::process_output("echo", [~"hello"]);
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1012,7 +1012,7 @@ mod tests {
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= run::process_output("/system/bin/sh", [~"-c",~"echo hello"]); = run::process_output("/system/bin/sh", [~"-c",~"echo hello"]);
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1091,7 +1091,7 @@ mod tests {
let reader = io::FILE_reader(file, false); let reader = io::FILE_reader(file, false);
let buf = reader.read_whole_stream(); let buf = reader.read_whole_stream();
os::fclose(file); os::fclose(file);
str::from_bytes(buf) str::from_utf8(buf)
} }
} }
@ -1132,7 +1132,7 @@ mod tests {
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new()); let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new());
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= prog.finish_with_output(); = prog.finish_with_output();
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1149,7 +1149,7 @@ mod tests {
run::ProcessOptions::new()); run::ProcessOptions::new());
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= prog.finish_with_output(); = prog.finish_with_output();
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1167,7 +1167,7 @@ mod tests {
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= prog.finish_with_output(); = prog.finish_with_output();
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1195,7 +1195,7 @@ mod tests {
let run::ProcessOutput {status, output, error} let run::ProcessOutput {status, output, error}
= prog.finish_with_output(); = prog.finish_with_output();
let output_str = str::from_bytes(output); let output_str = str::from_utf8(output);
assert_eq!(status, 0); assert_eq!(status, 0);
assert_eq!(output_str.trim().to_owned(), ~"hello"); assert_eq!(output_str.trim().to_owned(), ~"hello");
@ -1272,7 +1272,7 @@ mod tests {
fn test_keep_current_working_dir() { fn test_keep_current_working_dir() {
let mut prog = run_pwd(None); let mut prog = run_pwd(None);
let output = str::from_bytes(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
let parent_dir = os::getcwd().normalize(); let parent_dir = os::getcwd().normalize();
let child_dir = Path(output.trim()).normalize(); let child_dir = Path(output.trim()).normalize();
@ -1290,7 +1290,7 @@ mod tests {
let parent_dir = os::getcwd().dir_path().normalize(); let parent_dir = os::getcwd().dir_path().normalize();
let mut prog = run_pwd(Some(&parent_dir)); let mut prog = run_pwd(Some(&parent_dir));
let output = str::from_bytes(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
let child_dir = Path(output.trim()).normalize(); let child_dir = Path(output.trim()).normalize();
let parent_stat = parent_dir.stat().unwrap(); let parent_stat = parent_dir.stat().unwrap();
@ -1329,7 +1329,7 @@ mod tests {
if running_on_valgrind() { return; } if running_on_valgrind() { return; }
let mut prog = run_env(None); let mut prog = run_env(None);
let output = str::from_bytes(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
let r = os::env(); let r = os::env();
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
@ -1343,7 +1343,7 @@ mod tests {
if running_on_valgrind() { return; } if running_on_valgrind() { return; }
let mut prog = run_env(None); let mut prog = run_env(None);
let output = str::from_bytes(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
let r = os::env(); let r = os::env();
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
@ -1362,7 +1362,7 @@ mod tests {
new_env.push((~"RUN_TEST_NEW_ENV", ~"123")); new_env.push((~"RUN_TEST_NEW_ENV", ~"123"));
let mut prog = run_env(Some(new_env)); let mut prog = run_env(Some(new_env));
let output = str::from_bytes(prog.finish_with_output().output); let output = str::from_utf8(prog.finish_with_output().output);
assert!(output.contains("RUN_TEST_NEW_ENV=123")); assert!(output.contains("RUN_TEST_NEW_ENV=123"));
} }

View file

@ -55,13 +55,13 @@ Section: Creating a string
/// # Failure /// # Failure
/// ///
/// Raises the `not_utf8` condition if invalid UTF-8 /// Raises the `not_utf8` condition if invalid UTF-8
pub fn from_bytes(vv: &[u8]) -> ~str { pub fn from_utf8(vv: &[u8]) -> ~str {
use str::not_utf8::cond; use str::not_utf8::cond;
match from_bytes_opt(vv) { match from_utf8_opt(vv) {
None => { None => {
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap(); let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", cond.raise(fmt!("from_utf8: input is not UTF-8; first bad byte is %u",
first_bad_byte as uint)) first_bad_byte as uint))
} }
Some(s) => s Some(s) => s
@ -70,9 +70,9 @@ pub fn from_bytes(vv: &[u8]) -> ~str {
/// Convert a vector of bytes to a new UTF-8 string, if possible. /// Convert a vector of bytes to a new UTF-8 string, if possible.
/// Returns None if the vector contains invalid UTF-8. /// Returns None if the vector contains invalid UTF-8.
pub fn from_bytes_opt(vv: &[u8]) -> Option<~str> { pub fn from_utf8_opt(vv: &[u8]) -> Option<~str> {
if is_utf8(vv) { if is_utf8(vv) {
Some(unsafe { raw::from_bytes(vv) }) Some(unsafe { raw::from_utf8(vv) })
} else { } else {
None None
} }
@ -83,23 +83,23 @@ pub fn from_bytes_opt(vv: &[u8]) -> Option<~str> {
/// # Failure /// # Failure
/// ///
/// Raises the `not_utf8` condition if invalid UTF-8 /// Raises the `not_utf8` condition if invalid UTF-8
pub fn from_bytes_owned(vv: ~[u8]) -> ~str { pub fn from_utf8_owned(vv: ~[u8]) -> ~str {
use str::not_utf8::cond; use str::not_utf8::cond;
if !is_utf8(vv) { if !is_utf8(vv) {
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap(); let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", cond.raise(fmt!("from_utf8: input is not UTF-8; first bad byte is %u",
first_bad_byte as uint)) first_bad_byte as uint))
} else { } else {
unsafe { raw::from_bytes_owned(vv) } unsafe { raw::from_utf8_owned(vv) }
} }
} }
/// Consumes a vector of bytes to create a new utf-8 string. /// Consumes a vector of bytes to create a new utf-8 string.
/// Returns None if the vector contains invalid UTF-8. /// Returns None if the vector contains invalid UTF-8.
pub fn from_bytes_owned_opt(vv: ~[u8]) -> Option<~str> { pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> {
if is_utf8(vv) { if is_utf8(vv) {
Some(unsafe { raw::from_bytes_owned(vv) }) Some(unsafe { raw::from_utf8_owned(vv) })
} else { } else {
None None
} }
@ -113,14 +113,14 @@ pub fn from_bytes_owned_opt(vv: ~[u8]) -> Option<~str> {
/// # Failure /// # Failure
/// ///
/// Fails if invalid UTF-8 /// Fails if invalid UTF-8
pub fn from_bytes_slice<'a>(v: &'a [u8]) -> &'a str { pub fn from_utf8_slice<'a>(v: &'a [u8]) -> &'a str {
from_bytes_slice_opt(v).expect("from_bytes_slice: not utf-8") from_utf8_slice_opt(v).expect("from_utf8_slice: not utf-8")
} }
/// Converts a vector to a string slice without performing any allocations. /// Converts a vector to a string slice without performing any allocations.
/// ///
/// Returns None if the slice is not utf-8. /// Returns None if the slice is not utf-8.
pub fn from_bytes_slice_opt<'a>(v: &'a [u8]) -> Option<&'a str> { pub fn from_utf8_slice_opt<'a>(v: &'a [u8]) -> Option<&'a str> {
if is_utf8(v) { if is_utf8(v) {
Some(unsafe { cast::transmute(v) }) Some(unsafe { cast::transmute(v) })
} else { None } } else { None }
@ -1000,7 +1000,7 @@ pub mod raw {
} }
/// Converts a vector of bytes to a new owned string. /// Converts a vector of bytes to a new owned string.
pub unsafe fn from_bytes(v: &[u8]) -> ~str { pub unsafe fn from_utf8(v: &[u8]) -> ~str {
do v.as_imm_buf |buf, len| { do v.as_imm_buf |buf, len| {
from_buf_len(buf, len) from_buf_len(buf, len)
} }
@ -1009,12 +1009,12 @@ pub mod raw {
/// Converts an owned vector of bytes to a new owned string. This assumes /// Converts an owned vector of bytes to a new owned string. This assumes
/// that the utf-8-ness of the vector has already been validated /// that the utf-8-ness of the vector has already been validated
#[inline] #[inline]
pub unsafe fn from_bytes_owned(v: ~[u8]) -> ~str { pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str {
cast::transmute(v) cast::transmute(v)
} }
/// Converts a byte to a string. /// Converts a byte to a string.
pub unsafe fn from_byte(u: u8) -> ~str { from_bytes([u]) } pub unsafe fn from_byte(u: u8) -> ~str { from_utf8([u]) }
/// Form a slice from a C string. Unsafe because the caller must ensure the /// Form a slice from a C string. Unsafe because the caller must ensure the
/// C string has the static lifetime, or else the return value may be /// C string has the static lifetime, or else the return value may be
@ -2986,14 +2986,14 @@ mod tests {
} }
#[test] #[test]
fn test_unsafe_from_bytes() { fn test_unsafe_from_utf8() {
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8]; let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8];
let b = unsafe { raw::from_bytes(a) }; let b = unsafe { raw::from_utf8(a) };
assert_eq!(b, ~"AAAAAAA"); assert_eq!(b, ~"AAAAAAA");
} }
#[test] #[test]
fn test_from_bytes() { fn test_from_utf8() {
let ss = ~"ศไทย中华Việt Nam"; let ss = ~"ศไทย中华Việt Nam";
let bb = ~[0xe0_u8, 0xb8_u8, 0xa8_u8, let bb = ~[0xe0_u8, 0xb8_u8, 0xa8_u8,
0xe0_u8, 0xb9_u8, 0x84_u8, 0xe0_u8, 0xb9_u8, 0x84_u8,
@ -3007,9 +3007,9 @@ mod tests {
0x6d_u8]; 0x6d_u8];
assert_eq!(ss, from_bytes(bb)); assert_eq!(ss, from_utf8(bb));
assert_eq!(~"𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰", assert_eq!(~"𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰",
from_bytes(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰"))); from_utf8(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰")));
} }
#[test] #[test]
@ -3039,7 +3039,7 @@ mod tests {
#[test] #[test]
fn test_from_bytes_fail() { fn test_from_utf8_fail() {
use str::not_utf8::cond; use str::not_utf8::cond;
let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8, let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8,
@ -3055,11 +3055,11 @@ mod tests {
let mut error_happened = false; let mut error_happened = false;
let _x = do cond.trap(|err| { let _x = do cond.trap(|err| {
assert_eq!(err, ~"from_bytes: input is not UTF-8; first bad byte is 255"); assert_eq!(err, ~"from_utf8: input is not UTF-8; first bad byte is 255");
error_happened = true; error_happened = true;
~"" ~""
}).inside { }).inside {
from_bytes(bb) from_utf8(bb)
}; };
assert!(error_happened); assert!(error_happened);
} }
@ -3144,7 +3144,7 @@ mod tests {
let s1: ~str = ~"All mimsy were the borogoves"; let s1: ~str = ~"All mimsy were the borogoves";
let v: ~[u8] = s1.as_bytes().to_owned(); let v: ~[u8] = s1.as_bytes().to_owned();
let s2: ~str = from_bytes(v); let s2: ~str = from_utf8(v);
let mut i: uint = 0u; let mut i: uint = 0u;
let n1: uint = s1.len(); let n1: uint = s1.len();
let n2: uint = v.len(); let n2: uint = v.len();
@ -3667,73 +3667,73 @@ mod tests {
} }
#[test] #[test]
fn test_str_from_bytes_slice() { fn test_str_from_utf8_slice() {
let xs = bytes!("hello"); let xs = bytes!("hello");
assert_eq!(from_bytes_slice(xs), "hello"); assert_eq!(from_utf8_slice(xs), "hello");
let xs = bytes!("ศไทย中华Việt Nam"); let xs = bytes!("ศไทย中华Việt Nam");
assert_eq!(from_bytes_slice(xs), "ศไทย中华Việt Nam"); assert_eq!(from_utf8_slice(xs), "ศไทย中华Việt Nam");
} }
#[test] #[test]
#[should_fail] #[should_fail]
fn test_str_from_bytes_slice_invalid() { fn test_str_from_utf8_slice_invalid() {
let xs = bytes!("hello", 0xff); let xs = bytes!("hello", 0xff);
let _ = from_bytes_slice(xs); let _ = from_utf8_slice(xs);
} }
#[test] #[test]
fn test_str_from_bytes_slice_opt() { fn test_str_from_utf8_slice_opt() {
let xs = bytes!("hello"); let xs = bytes!("hello");
assert_eq!(from_bytes_slice_opt(xs), Some("hello")); assert_eq!(from_utf8_slice_opt(xs), Some("hello"));
let xs = bytes!("ศไทย中华Việt Nam"); let xs = bytes!("ศไทย中华Việt Nam");
assert_eq!(from_bytes_slice_opt(xs), Some("ศไทย中华Việt Nam")); assert_eq!(from_utf8_slice_opt(xs), Some("ศไทย中华Việt Nam"));
let xs = bytes!("hello", 0xff); let xs = bytes!("hello", 0xff);
assert_eq!(from_bytes_slice_opt(xs), None); assert_eq!(from_utf8_slice_opt(xs), None);
} }
#[test] #[test]
fn test_str_from_bytes() { fn test_str_from_utf8() {
let xs = bytes!("hello"); let xs = bytes!("hello");
assert_eq!(from_bytes(xs), ~"hello"); assert_eq!(from_utf8(xs), ~"hello");
let xs = bytes!("ศไทย中华Việt Nam"); let xs = bytes!("ศไทย中华Việt Nam");
assert_eq!(from_bytes(xs), ~"ศไทย中华Việt Nam"); assert_eq!(from_utf8(xs), ~"ศไทย中华Việt Nam");
} }
#[test] #[test]
fn test_str_from_bytes_opt() { fn test_str_from_utf8_opt() {
let xs = bytes!("hello").to_owned(); let xs = bytes!("hello").to_owned();
assert_eq!(from_bytes_opt(xs), Some(~"hello")); assert_eq!(from_utf8_opt(xs), Some(~"hello"));
let xs = bytes!("ศไทย中华Việt Nam"); let xs = bytes!("ศไทย中华Việt Nam");
assert_eq!(from_bytes_opt(xs), Some(~"ศไทย中华Việt Nam")); assert_eq!(from_utf8_opt(xs), Some(~"ศไทย中华Việt Nam"));
let xs = bytes!("hello", 0xff); let xs = bytes!("hello", 0xff);
assert_eq!(from_bytes_opt(xs), None); assert_eq!(from_utf8_opt(xs), None);
} }
#[test] #[test]
fn test_str_from_bytes_owned() { fn test_str_from_utf8_owned() {
let xs = bytes!("hello").to_owned(); let xs = bytes!("hello").to_owned();
assert_eq!(from_bytes_owned(xs), ~"hello"); assert_eq!(from_utf8_owned(xs), ~"hello");
let xs = bytes!("ศไทย中华Việt Nam").to_owned(); let xs = bytes!("ศไทย中华Việt Nam").to_owned();
assert_eq!(from_bytes_owned(xs), ~"ศไทย中华Việt Nam"); assert_eq!(from_utf8_owned(xs), ~"ศไทย中华Việt Nam");
} }
#[test] #[test]
fn test_str_from_bytes_owned_opt() { fn test_str_from_utf8_owned_opt() {
let xs = bytes!("hello").to_owned(); let xs = bytes!("hello").to_owned();
assert_eq!(from_bytes_owned_opt(xs), Some(~"hello")); assert_eq!(from_utf8_owned_opt(xs), Some(~"hello"));
let xs = bytes!("ศไทย中华Việt Nam").to_owned(); let xs = bytes!("ศไทย中华Việt Nam").to_owned();
assert_eq!(from_bytes_owned_opt(xs), Some(~"ศไทย中华Việt Nam")); assert_eq!(from_utf8_owned_opt(xs), Some(~"ศไทย中华Việt Nam"));
let xs = bytes!("hello", 0xff).to_owned(); let xs = bytes!("hello", 0xff).to_owned();
assert_eq!(from_bytes_owned_opt(xs), None); assert_eq!(from_utf8_owned_opt(xs), None);
} }
} }

View file

@ -99,7 +99,7 @@ pub fn log_str<T>(t: &T) -> ~str {
let mut result = io::mem::MemWriter::new(); let mut result = io::mem::MemWriter::new();
repr::write_repr(&mut result as &mut io::Writer, t); repr::write_repr(&mut result as &mut io::Writer, t);
str::from_bytes_owned(result.inner()) str::from_utf8_owned(result.inner())
} }
#[cfg(stage0)] #[cfg(stage0)]
pub fn log_str<T>(t: &T) -> ~str { pub fn log_str<T>(t: &T) -> ~str {

View file

@ -338,7 +338,7 @@ pub fn gather_comments_and_literals(span_diagnostic:
path: @str, path: @str,
srdr: @io::Reader) srdr: @io::Reader)
-> (~[cmnt], ~[lit]) { -> (~[cmnt], ~[lit]) {
let src = str::from_bytes(srdr.read_whole_stream()).to_managed(); let src = str::from_utf8(srdr.read_whole_stream()).to_managed();
let cm = CodeMap::new(); let cm = CodeMap::new();
let filemap = cm.new_filemap(path, src); let filemap = cm.new_filemap(path, src);
let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap); let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);

View file

@ -72,7 +72,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
for kv in pairs_sorted.iter() { for kv in pairs_sorted.iter() {
let (k,v) = (*kv).clone(); let (k,v) = (*kv).clone();
unsafe { unsafe {
let b = str::raw::from_bytes(k); let b = str::raw::from_utf8(k);
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
// to_ascii_move and to_str_move to not do a unnecessary copy. // to_ascii_move and to_str_move to not do a unnecessary copy.
buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v)); buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v));

View file

@ -60,7 +60,7 @@ impl Code {
} }
reverse(result); reverse(result);
str::from_bytes(result) str::from_utf8(result)
} }
} }

View file

@ -17,13 +17,13 @@ static C: *u8 = B as *u8;
pub fn main() { pub fn main() {
unsafe { unsafe {
let foo = &A as *u8; let foo = &A as *u8;
assert_eq!(str::raw::from_bytes(A), ~"hi"); assert_eq!(str::raw::from_utf8(A), ~"hi");
assert_eq!(str::raw::from_buf_len(foo, A.len()), ~"hi"); assert_eq!(str::raw::from_buf_len(foo, A.len()), ~"hi");
assert_eq!(str::raw::from_buf_len(C, B.len()), ~"hi"); assert_eq!(str::raw::from_buf_len(C, B.len()), ~"hi");
assert!(*C == A[0]); assert!(*C == A[0]);
assert!(*(&B[0] as *u8) == A[0]); assert!(*(&B[0] as *u8) == A[0]);
let bar = str::raw::from_bytes(A).to_c_str(); let bar = str::raw::from_utf8(A).to_c_str();
assert_eq!(bar.with_ref(|buf| str::raw::from_c_str(buf)), ~"hi"); assert_eq!(bar.with_ref(|buf| str::raw::from_c_str(buf)), ~"hi");
} }
} }

View file

@ -44,13 +44,13 @@ fn test_destroy_actually_kills(force: bool) {
#[cfg(unix,not(target_os="android"))] #[cfg(unix,not(target_os="android"))]
fn process_exists(pid: libc::pid_t) -> bool { fn process_exists(pid: libc::pid_t) -> bool {
let run::ProcessOutput {output, _} = run::process_output("ps", [~"-p", pid.to_str()]); let run::ProcessOutput {output, _} = run::process_output("ps", [~"-p", pid.to_str()]);
str::from_bytes(output).contains(pid.to_str()) str::from_utf8(output).contains(pid.to_str())
} }
#[cfg(unix,target_os="android")] #[cfg(unix,target_os="android")]
fn process_exists(pid: libc::pid_t) -> bool { fn process_exists(pid: libc::pid_t) -> bool {
let run::ProcessOutput {output, _} = run::process_output("/system/bin/ps", [pid.to_str()]); let run::ProcessOutput {output, _} = run::process_output("/system/bin/ps", [pid.to_str()]);
str::from_bytes(output).contains(~"root") str::from_utf8(output).contains(~"root")
} }
#[cfg(windows)] #[cfg(windows)]

View file

@ -80,7 +80,7 @@ mod map_reduce {
mapper_done => { num_mappers -= 1; } mapper_done => { num_mappers -= 1; }
find_reducer(k, cc) => { find_reducer(k, cc) => {
let mut c; let mut c;
match reducers.find(&str::from_bytes(k)) { match reducers.find(&str::from_utf8(k)) {
Some(&_c) => { c = _c; } Some(&_c) => { c = _c; }
None => { c = 0; } None => { c = 0; }
} }

View file

@ -246,7 +246,7 @@ fn test_write() {
writeln!(w, "{foo}", foo="bar"); writeln!(w, "{foo}", foo="bar");
} }
let s = str::from_bytes_owned(buf.inner()); let s = str::from_utf8_owned(buf.inner());
t!(s, "34helloline\nbar\n"); t!(s, "34helloline\nbar\n");
} }