From de39874801761197bf10bf8d04bde1aa2bd82e15 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 5 Sep 2013 14:17:24 +0200 Subject: [PATCH] Rename str::from_bytes to str::from_utf8, closes #8985 --- src/compiletest/procsrv.rs | 4 +- src/libextra/base64.rs | 6 +- src/libextra/bitv.rs | 8 +- src/libextra/ebml.rs | 2 +- src/libextra/hex.rs | 6 +- src/libextra/json.rs | 2 +- src/libextra/terminfo/parser/compiled.rs | 2 +- src/libextra/uuid.rs | 12 +-- src/librustc/back/link.rs | 4 +- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/tydecode.rs | 4 +- src/librustc/rustc.rs | 4 +- src/librustdoc/markdown_writer.rs | 4 +- src/librustpkg/rustpkg.rs | 2 +- src/librustpkg/source_control.rs | 16 ++-- src/librustpkg/tests.rs | 22 ++--- src/librustpkg/version.rs | 8 +- src/libstd/fmt/mod.rs | 4 +- src/libstd/io.rs | 10 +- src/libstd/num/int_macros.rs | 2 +- src/libstd/num/strconv.rs | 2 +- src/libstd/num/uint_macros.rs | 2 +- src/libstd/repr.rs | 2 +- src/libstd/rt/io/file.rs | 14 +-- src/libstd/rt/io/flate.rs | 2 +- src/libstd/rt/uv/file.rs | 4 +- src/libstd/rt/uv/net.rs | 2 +- src/libstd/rt/uv/uvio.rs | 2 +- src/libstd/run.rs | 24 ++--- src/libstd/str.rs | 96 +++++++++---------- src/libstd/sys.rs | 2 +- src/libsyntax/parse/comments.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- src/test/run-pass/const-str-ptr.rs | 4 +- src/test/run-pass/core-run-destroy.rs | 4 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/ifmt.rs | 2 +- 38 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index 45e4f756d7a..ef8049aa717 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -63,7 +63,7 @@ pub fn run(lib_path: &str, Result { status: output.status, - out: str::from_bytes(output.output), - err: str::from_bytes(output.error) + out: str::from_utf8(output.output), + err: str::from_utf8(output.error) } } diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index b4431004bd7..525ff658dba 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] { } 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 `~`) * 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 * values. * @@ -180,7 +180,7 @@ impl<'self> FromBase64 for &'self str { * printfln!("%s", hello_str); * let bytes = hello_str.from_base64(); * printfln!("%?", bytes); - * let result_str = str::from_bytes(bytes); + * let result_str = str::from_utf8(bytes); * printfln!("%s", result_str); * } * ~~~ diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 03588d984d9..70fd3a01ca4 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -523,7 +523,7 @@ impl Bitv { * with the most significant bits of each byte coming first. Each * 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| { let b = bytes[i / 8] as uint; let offset = i % 8; @@ -1275,8 +1275,8 @@ mod tests { } #[test] - fn test_from_bytes() { - let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]); + fn test_from_utf8() { + let bitv = from_utf8([0b10110110, 0b00000000, 0b11111111]); let str = ~"10110110" + "00000000" + "11111111"; assert_eq!(bitv.to_str(), str); } @@ -1302,7 +1302,7 @@ mod tests { #[test] fn test_to_bools() { 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] diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index d8d54e20e97..4e5094dab63 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -41,7 +41,7 @@ impl Doc { } 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 { diff --git a/src/libextra/hex.rs b/src/libextra/hex.rs index d5345cb956b..b93b5fb43d4 100644 --- a/src/libextra/hex.rs +++ b/src/libextra/hex.rs @@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] { } 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 `~`) * 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 * values. * @@ -80,7 +80,7 @@ impl<'self> FromHex for &'self str { * printfln!("%s", hello_str); * let bytes = hello_str.from_hex().unwrap(); * printfln!("%?", bytes); - * let result_str = str::from_bytes(bytes); + * let result_str = str::from_utf8(bytes); * printfln!("%s", result_str); * } * ~~~ diff --git a/src/libextra/json.rs b/src/libextra/json.rs index bc8c08d4643..ee3e1966fe2 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -858,7 +858,7 @@ impl> Parser { /// Decodes a json value from an @io::Reader pub fn from_reader(rdr: @io::Reader) -> Result { - let s = str::from_bytes(rdr.read_whole_stream()); + let s = str::from_utf8(rdr.read_whole_stream()); let mut parser = Parser(~s.iter()); parser.parse() } diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index 0d2badff492..49a6210e3a9 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -213,7 +213,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { 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(); file.read_byte(); // consume NUL diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs index 3159d8a8f3c..9a79e61e233 100644 --- a/src/libextra/uuid.rs +++ b/src/libextra/uuid.rs @@ -210,7 +210,7 @@ impl Uuid { /// /// # Arguments /// * `b` An array or slice of 16 bytes - pub fn from_bytes(b: &[u8]) -> Option { + pub fn from_utf8(b: &[u8]) -> Option { if b.len() != 16 { return None } @@ -307,7 +307,7 @@ impl Uuid { s[i*2+0] = digit[0]; 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 @@ -413,7 +413,7 @@ impl Uuid { 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] - fn test_from_bytes() { + fn test_from_utf8() { let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 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"; 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, 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(); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 91e2331ec8c..f334b104191 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -386,7 +386,7 @@ pub mod write { cc_prog, prog.status)); sess.note(fmt!("%s arguments: %s", 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(); } } @@ -943,7 +943,7 @@ pub fn link_binary(sess: Session, cc_prog, prog.status)); sess.note(fmt!("%s arguments: %s", 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(); } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 7d173e333fc..18446acfef6 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1239,7 +1239,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) { do reader::with_doc_data(d) |desc| { let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint; let pathbytes = desc.slice(4u, desc.len()); - let path = str::from_bytes(pathbytes); + let path = str::from_utf8(pathbytes); (path, pos) } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 036c66cca84..6e4b6180fd2 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -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) -> 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); } @@ -477,7 +477,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet { let mut abis = AbiSet::empty(); while peek(st) != ']' { // 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); abis.add(abi); } diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 72cd3fa7b4f..6c5c8631a14 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -161,7 +161,7 @@ Available lint options: max_key = num::max(name.len(), max_key); } 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"); printfln!(" %s %7.7s %s", @@ -244,7 +244,7 @@ pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) { 1u => { let ifile = matches.free[0].as_slice(); 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()) } else { file_input(Path(ifile)) diff --git a/src/librustdoc/markdown_writer.rs b/src/librustdoc/markdown_writer.rs index c13e85ea716..a1ea5a68c82 100644 --- a/src/librustdoc/markdown_writer.rs +++ b/src/librustdoc/markdown_writer.rs @@ -116,8 +116,8 @@ fn pandoc_writer( debug!("pandoc result: %i", output.status); if output.status != 0 { - error!("pandoc-out: %s", str::from_bytes(output.output)); - error!("pandoc-err: %s", str::from_bytes(output.error)); + error!("pandoc-out: %s", str::from_utf8(output.output)); + error!("pandoc-err: %s", str::from_utf8(output.error)); fail!("pandoc failed"); } } diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 6a6e7569a65..25a415df302 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -153,7 +153,7 @@ impl<'self> PkgScript<'self> { 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 - 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(); (cfgs, output.status) } diff --git a/src/librustpkg/source_control.rs b/src/librustpkg/source_control.rs index caa004a53b2..92b749f2787 100644 --- a/src/librustpkg/source_control.rs +++ b/src/librustpkg/source_control.rs @@ -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()); let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]); if outp.status != 0 { - io::println(str::from_bytes_owned(outp.output.clone())); - io::println(str::from_bytes_owned(outp.error)); + io::println(str::from_utf8_owned(outp.output.clone())); + io::println(str::from_utf8_owned(outp.error)); fail!("Couldn't `git clone` %s", source.to_str()); } else { @@ -36,8 +36,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) { fmt!("--git-dir=%s", target.push(".git").to_str()), ~"checkout", fmt!("%s", *s)]); if outp.status != 0 { - io::println(str::from_bytes_owned(outp.output.clone())); - io::println(str::from_bytes_owned(outp.error)); + io::println(str::from_utf8_owned(outp.output.clone())); + io::println(str::from_utf8_owned(outp.error)); fail!("Couldn't `git checkout %s` in %s", *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 { let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]); if outp.status != 0 { - debug!(str::from_bytes_owned(outp.output.clone())); - debug!(str::from_bytes_owned(outp.error)); + debug!(str::from_utf8_owned(outp.output.clone())); + debug!(str::from_utf8_owned(outp.error)); false } 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)], target); if outp.status != 0 { - debug!(str::from_bytes_owned(outp.output.clone())); - debug!(str::from_bytes_owned(outp.error)); + debug!(str::from_utf8_owned(outp.output.clone())); + debug!(str::from_utf8_owned(outp.error)); false } else { diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 5226036802e..a86f299276a 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -123,7 +123,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st let rslt = prog.finish_with_output(); if rslt.status != 0 { 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(); debug!("Output from command %s with args %? was %s {%s}[%?]", - cmd, args, str::from_bytes(output.output), - str::from_bytes(output.error), + cmd, args, str::from_utf8(output.output), + str::from_utf8(output.error), output.status); /* 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 { fail!("Command %s %? failed with exit code %?; its output was {{{ %s }}}", 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 } @@ -358,7 +358,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool { fn command_line_test_output(args: &[~str]) -> ~[~str] { let mut result = ~[]; 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') { 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] { let mut result = ~[]; 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') { result.push(s.to_owned()); } @@ -985,7 +985,7 @@ fn test_info() { let expected_info = ~"package foo"; // fill in let workspace = create_local_package(&PkgId::new("foo")); 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] @@ -994,7 +994,7 @@ fn test_rustpkg_test() { let expected_results = ~"1 out of 1 tests passed"; // fill in let workspace = create_local_package_with_test(&PkgId::new("foo")); 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] @@ -1004,7 +1004,7 @@ fn test_uninstall() { let _output = command_line_test([~"info", ~"foo"], &workspace); command_line_test([~"uninstall", ~"foo"], &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] @@ -1073,8 +1073,8 @@ fn test_extern_mod() { let outp = prog.finish_with_output(); if outp.status != 0 { fail!("output was %s, error was %s", - str::from_bytes(outp.output), - str::from_bytes(outp.error)); + str::from_utf8(outp.output), + str::from_utf8(outp.error)); } assert!(os::path_exists(&exec_file) && is_executable(&exec_file)); } diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index 827bb415d40..d408177572f 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -111,7 +111,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option { } 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() { if !l.is_whitespace() { output = Some(l); @@ -141,15 +141,15 @@ pub fn try_getting_version(remote_path: &Path) -> Option { tmp_dir.to_str()]); if outp.status == 0 { debug!("Cloned it... ( %s, %s )", - str::from_bytes(outp.output), - str::from_bytes(outp.error)); + str::from_utf8(outp.output), + str::from_utf8(outp.error)); let mut output = None; debug!("(getting version, now getting tags) executing {git --git-dir=%s tag -l}", tmp_dir.push(".git").to_str()); let outp = run::process_output("git", [fmt!("--git-dir=%s", tmp_dir.push(".git").to_str()), ~"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); for l in output_text.line_iter() { debug!("A line of output: %s", l); diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 8d50f5efa48..ef036340412 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -468,7 +468,7 @@ pub unsafe fn write(output: &mut io::Writer, pub unsafe fn format(fmt: &[rt::Piece], args: &[Argument]) -> ~str { let mut output = MemWriter::new(); 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> { @@ -589,7 +589,7 @@ impl<'self> Formatter<'self> { fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) { 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() { self.run(piece, Some(valuestr)); } diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 59329c5bdd2..ee948446614 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -642,7 +642,7 @@ impl ReaderUtil for T { } bytes.push(ch as u8); } - str::from_bytes(bytes) + str::from_utf8(bytes) } fn read_line(&self) -> ~str { @@ -651,7 +651,7 @@ impl ReaderUtil for T { fn read_chars(&self, n: uint) -> ~[char] { // returns the (consumed offset, n_req), appends characters to &chars - fn chars_from_bytes(bytes: &~[u8], chars: &mut ~[char]) + fn chars_from_utf8(bytes: &~[u8], chars: &mut ~[char]) -> (uint, uint) { let mut i = 0; let bytes_len = bytes.len(); @@ -701,7 +701,7 @@ impl ReaderUtil for T { break; } bytes.push_all(data); - let (offset, nbreq) = chars_from_bytes::(&bytes, &mut chars); + let (offset, nbreq) = chars_from_utf8::(&bytes, &mut chars); let ncreq = n - chars.len(); // again we either know we need a certain number of bytes // 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 { - str::from_bytes(with_bytes_writer(f)) + str::from_utf8(with_bytes_writer(f)) } // 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> { do read_whole_file(file).chain |bytes| { if str::is_utf8(bytes) { - Ok(str::from_bytes(bytes)) + Ok(str::from_utf8(bytes)) } else { Err(file.to_str() + " is not UTF-8") } diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 0131feda830..377d0a78134 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -541,7 +541,7 @@ impl ToStrRadix for $T { } // We know we generated valid utf-8, so we don't need to go through that // check. - unsafe { str::raw::from_bytes_owned(buf) } + unsafe { str::raw::from_utf8_owned(buf) } } } diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 6fba8a6dd13..edfabd339af 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -417,7 +417,7 @@ pub fn float_to_str_common (~str, bool) { let (bytes, special) = float_to_str_bytes_common(num, radix, negative_zero, sign, digits); - (str::from_bytes(bytes), special) + (str::from_utf8(bytes), special) } // Some constants for from_str_bytes_common's input validation, diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 1426142d465..af991045b45 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -396,7 +396,7 @@ impl ToStrRadix for $T { } // We know we generated valid utf-8, so we don't need to go through that // check. - unsafe { str::raw::from_bytes_owned(buf) } + unsafe { str::raw::from_utf8_owned(buf) } } } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 7141a17d133..c03d7bdf6a7 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -634,7 +634,7 @@ fn test_repr() { fn exact_test(t: &T, e:&str) { let mut m = io::mem::MemWriter::new(); 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); } diff --git a/src/libstd/rt/io/file.rs b/src/libstd/rt/io/file.rs index 3fb00720406..ad21dfea3cd 100644 --- a/src/libstd/rt/io/file.rs +++ b/src/libstd/rt/io/file.rs @@ -159,7 +159,7 @@ fn file_test_smoke_test_impl() { let mut read_buf = [0, .. 1028]; let read_str = match read_stream.read(read_buf).unwrap() { -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()); } @@ -230,7 +230,7 @@ fn file_test_io_non_positional_read_impl() { } } unlink(filename); - let read_str = str::from_bytes(read_mem); + let read_str = str::from_utf8(read_mem); assert!(read_str == message.to_owned()); } } @@ -262,7 +262,7 @@ fn file_test_io_seeking_impl() { tell_pos_post_read = read_stream.tell(); } 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!(tell_pos_pre_read == set_cursor); 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); } 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)); 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.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()); read_stream.seek(-9, SeekCur); 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()); read_stream.seek(0, SeekSet); 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()); } unlink(filename); diff --git a/src/libstd/rt/io/flate.rs b/src/libstd/rt/io/flate.rs index 16bca850fd2..7c72ce6ba89 100644 --- a/src/libstd/rt/io/flate.rs +++ b/src/libstd/rt/io/flate.rs @@ -117,7 +117,7 @@ mod test { let mut out_bytes = [0, .. 100]; let bytes_read = inflate_reader.read(out_bytes).unwrap(); 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); } } diff --git a/src/libstd/rt/uv/file.rs b/src/libstd/rt/uv/file.rs index eaf70242440..15fe9abaa2c 100644 --- a/src/libstd/rt/uv/file.rs +++ b/src/libstd/rt/uv/file.rs @@ -329,7 +329,7 @@ mod test { if nread > 0 { let read_str = unsafe { let read_buf = *read_buf_ptr; - str::from_bytes( + str::from_utf8( vec::from_buf( read_buf.base, nread)) }; @@ -393,7 +393,7 @@ mod test { // nread == 0 would be EOF.. we know it's >= zero because otherwise // the above assert would fail if nread > 0 { - let read_str = str::from_bytes( + let read_str = str::from_utf8( read_mem.slice(0, nread as uint)); assert!(read_str == ~"hello"); // close diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 3ff6e90e32d..6e890850654 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -83,7 +83,7 @@ fn uv_socket_addr_as_socket_addr(addr: UvSocketAddr, f: &fn(SocketAddr) -> T) }; 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(); // finally run the closure diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index e37dfba0cc1..6f9e3c43b0e 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -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 read_vec = [0, .. 1028]; 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()); } (*io).fs_unlink(&Path(path)); diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 7fc2deff97d..0fe9236253d 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -997,7 +997,7 @@ mod tests { let run::ProcessOutput {status, output, error} = 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!(output_str.trim().to_owned(), ~"hello"); @@ -1012,7 +1012,7 @@ mod tests { let run::ProcessOutput {status, output, error} = 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!(output_str.trim().to_owned(), ~"hello"); @@ -1091,7 +1091,7 @@ mod tests { let reader = io::FILE_reader(file, false); let buf = reader.read_whole_stream(); 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 run::ProcessOutput {status, output, error} = prog.finish_with_output(); - let output_str = str::from_bytes(output); + let output_str = str::from_utf8(output); assert_eq!(status, 0); assert_eq!(output_str.trim().to_owned(), ~"hello"); @@ -1149,7 +1149,7 @@ mod tests { run::ProcessOptions::new()); let run::ProcessOutput {status, output, error} = prog.finish_with_output(); - let output_str = str::from_bytes(output); + let output_str = str::from_utf8(output); assert_eq!(status, 0); assert_eq!(output_str.trim().to_owned(), ~"hello"); @@ -1167,7 +1167,7 @@ mod tests { let run::ProcessOutput {status, output, error} = prog.finish_with_output(); - let output_str = str::from_bytes(output); + let output_str = str::from_utf8(output); assert_eq!(status, 0); assert_eq!(output_str.trim().to_owned(), ~"hello"); @@ -1195,7 +1195,7 @@ mod tests { let run::ProcessOutput {status, output, error} = prog.finish_with_output(); - let output_str = str::from_bytes(output); + let output_str = str::from_utf8(output); assert_eq!(status, 0); assert_eq!(output_str.trim().to_owned(), ~"hello"); @@ -1272,7 +1272,7 @@ mod tests { fn test_keep_current_working_dir() { 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 child_dir = Path(output.trim()).normalize(); @@ -1290,7 +1290,7 @@ mod tests { let parent_dir = os::getcwd().dir_path().normalize(); 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 parent_stat = parent_dir.stat().unwrap(); @@ -1329,7 +1329,7 @@ mod tests { if running_on_valgrind() { return; } 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(); for &(ref k, ref v) in r.iter() { @@ -1343,7 +1343,7 @@ mod tests { if running_on_valgrind() { return; } 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(); for &(ref k, ref v) in r.iter() { @@ -1362,7 +1362,7 @@ mod tests { new_env.push((~"RUN_TEST_NEW_ENV", ~"123")); 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")); } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 704a9f05856..073d5524fab 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -55,13 +55,13 @@ Section: Creating a string /// # Failure /// /// 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; - match from_bytes_opt(vv) { + match from_utf8_opt(vv) { None => { 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)) } 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. /// 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) { - Some(unsafe { raw::from_bytes(vv) }) + Some(unsafe { raw::from_utf8(vv) }) } else { None } @@ -83,23 +83,23 @@ pub fn from_bytes_opt(vv: &[u8]) -> Option<~str> { /// # Failure /// /// 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; if !is_utf8(vv) { 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)) } 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. /// 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) { - Some(unsafe { raw::from_bytes_owned(vv) }) + Some(unsafe { raw::from_utf8_owned(vv) }) } else { None } @@ -113,14 +113,14 @@ pub fn from_bytes_owned_opt(vv: ~[u8]) -> Option<~str> { /// # Failure /// /// Fails if invalid UTF-8 -pub fn from_bytes_slice<'a>(v: &'a [u8]) -> &'a str { - from_bytes_slice_opt(v).expect("from_bytes_slice: not utf-8") +pub fn from_utf8_slice<'a>(v: &'a [u8]) -> &'a str { + from_utf8_slice_opt(v).expect("from_utf8_slice: not utf-8") } /// Converts a vector to a string slice without performing any allocations. /// /// 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) { Some(unsafe { cast::transmute(v) }) } else { None } @@ -1000,7 +1000,7 @@ pub mod raw { } /// 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| { 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 /// that the utf-8-ness of the vector has already been validated #[inline] - pub unsafe fn from_bytes_owned(v: ~[u8]) -> ~str { + pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str { cast::transmute(v) } /// 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 /// C string has the static lifetime, or else the return value may be @@ -2986,14 +2986,14 @@ mod tests { } #[test] - fn test_unsafe_from_bytes() { + fn test_unsafe_from_utf8() { 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"); } #[test] - fn test_from_bytes() { + fn test_from_utf8() { let ss = ~"ศไทย中华Việt Nam"; let bb = ~[0xe0_u8, 0xb8_u8, 0xa8_u8, 0xe0_u8, 0xb9_u8, 0x84_u8, @@ -3007,9 +3007,9 @@ mod tests { 0x6d_u8]; - assert_eq!(ss, from_bytes(bb)); + assert_eq!(ss, from_utf8(bb)); assert_eq!(~"𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰", - from_bytes(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰"))); + from_utf8(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰"))); } #[test] @@ -3039,7 +3039,7 @@ mod tests { #[test] - fn test_from_bytes_fail() { + fn test_from_utf8_fail() { use str::not_utf8::cond; let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8, @@ -3055,11 +3055,11 @@ mod tests { let mut error_happened = false; 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; ~"" }).inside { - from_bytes(bb) + from_utf8(bb) }; assert!(error_happened); } @@ -3144,7 +3144,7 @@ mod tests { let s1: ~str = ~"All mimsy were the borogoves"; 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 n1: uint = s1.len(); let n2: uint = v.len(); @@ -3667,73 +3667,73 @@ mod tests { } #[test] - fn test_str_from_bytes_slice() { + fn test_str_from_utf8_slice() { let xs = bytes!("hello"); - assert_eq!(from_bytes_slice(xs), "hello"); + assert_eq!(from_utf8_slice(xs), "hello"); 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] #[should_fail] - fn test_str_from_bytes_slice_invalid() { + fn test_str_from_utf8_slice_invalid() { let xs = bytes!("hello", 0xff); - let _ = from_bytes_slice(xs); + let _ = from_utf8_slice(xs); } #[test] - fn test_str_from_bytes_slice_opt() { + fn test_str_from_utf8_slice_opt() { 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"); - 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); - assert_eq!(from_bytes_slice_opt(xs), None); + assert_eq!(from_utf8_slice_opt(xs), None); } #[test] - fn test_str_from_bytes() { + fn test_str_from_utf8() { let xs = bytes!("hello"); - assert_eq!(from_bytes(xs), ~"hello"); + assert_eq!(from_utf8(xs), ~"hello"); let xs = bytes!("ศไทย中华Việt Nam"); - assert_eq!(from_bytes(xs), ~"ศไทย中华Việt Nam"); + assert_eq!(from_utf8(xs), ~"ศไทย中华Việt Nam"); } #[test] - fn test_str_from_bytes_opt() { + fn test_str_from_utf8_opt() { 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"); - 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); - assert_eq!(from_bytes_opt(xs), None); + assert_eq!(from_utf8_opt(xs), None); } #[test] - fn test_str_from_bytes_owned() { + fn test_str_from_utf8_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(); - assert_eq!(from_bytes_owned(xs), ~"ศไทย中华Việt Nam"); + assert_eq!(from_utf8_owned(xs), ~"ศไทย中华Việt Nam"); } #[test] - fn test_str_from_bytes_owned_opt() { + fn test_str_from_utf8_owned_opt() { 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(); - 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(); - assert_eq!(from_bytes_owned_opt(xs), None); + assert_eq!(from_utf8_owned_opt(xs), None); } } diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index cfc285488a9..c3a5afc1ec8 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -99,7 +99,7 @@ pub fn log_str(t: &T) -> ~str { let mut result = io::mem::MemWriter::new(); repr::write_repr(&mut result as &mut io::Writer, t); - str::from_bytes_owned(result.inner()) + str::from_utf8_owned(result.inner()) } #[cfg(stage0)] pub fn log_str(t: &T) -> ~str { diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 9a9164f5102..7ca6224c31d 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -338,7 +338,7 @@ pub fn gather_comments_and_literals(span_diagnostic: path: @str, srdr: @io::Reader) -> (~[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 filemap = cm.new_filemap(path, src); let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap); diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 0a036696544..f0bf7fc7a6b 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -72,7 +72,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { for kv in pairs_sorted.iter() { let (k,v) = (*kv).clone(); 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 // 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)); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 2b5b4ded947..ae3422540aa 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -60,7 +60,7 @@ impl Code { } reverse(result); - str::from_bytes(result) + str::from_utf8(result) } } diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 0e7d6d9f16a..d12a0abc9a6 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -17,13 +17,13 @@ static C: *u8 = B as *u8; pub fn main() { unsafe { 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(C, B.len()), ~"hi"); assert!(*C == 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"); } } diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs index 2551d1a5cfc..1c3e83f3cab 100644 --- a/src/test/run-pass/core-run-destroy.rs +++ b/src/test/run-pass/core-run-destroy.rs @@ -44,13 +44,13 @@ fn test_destroy_actually_kills(force: bool) { #[cfg(unix,not(target_os="android"))] fn process_exists(pid: libc::pid_t) -> bool { 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")] fn process_exists(pid: libc::pid_t) -> bool { 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)] diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index a7b376f4aea..7cd26dd84c4 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -80,7 +80,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_bytes(k)) { + match reducers.find(&str::from_utf8(k)) { Some(&_c) => { c = _c; } None => { c = 0; } } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 8ed93a13d60..3f0c7e07041 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -246,7 +246,7 @@ fn test_write() { 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"); }