Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions src/libextra/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] {
}

unsafe {
str::raw::from_bytes_owned(v)
str::raw::from_utf8_owned(v)
}
}
}
Expand All @@ -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.
*
Expand All @@ -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);
* }
* ~~~
Expand Down
8 changes: 4 additions & 4 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] {
}

unsafe {
str::raw::from_bytes_owned(v)
str::raw::from_utf8_owned(v)
}
}
}
Expand All @@ -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.
*
Expand All @@ -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);
* }
* ~~~
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ impl<T : iterator::Iterator<char>> Parser<T> {

/// Decodes a json value from an @io::Reader
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());
parser.parse()
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Uuid {
///
/// # Arguments
/// * `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 {
return None
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/rustpkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustpkg/source_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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 --
Expand All @@ -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
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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));
}
Expand Down
Loading