Skip to content

Commit de39874

Browse files
committed
Rename str::from_bytes to str::from_utf8, closes #8985
1 parent 422dcbd commit de39874

38 files changed

+147
-147
lines changed

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn run(lib_path: &str,
6363

6464
Result {
6565
status: output.status,
66-
out: str::from_bytes(output.output),
67-
err: str::from_bytes(output.error)
66+
out: str::from_utf8(output.output),
67+
err: str::from_utf8(output.error)
6868
}
6969
}

src/libextra/base64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] {
145145
}
146146

147147
unsafe {
148-
str::raw::from_bytes_owned(v)
148+
str::raw::from_utf8_owned(v)
149149
}
150150
}
151151
}
@@ -162,7 +162,7 @@ impl<'self> FromBase64 for &'self str {
162162
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
163163
* to the byte values it encodes.
164164
*
165-
* You can use the `from_bytes` function in `std::str`
165+
* You can use the `from_utf8` function in `std::str`
166166
* to turn a `[u8]` into a string with characters corresponding to those
167167
* values.
168168
*
@@ -180,7 +180,7 @@ impl<'self> FromBase64 for &'self str {
180180
* printfln!("%s", hello_str);
181181
* let bytes = hello_str.from_base64();
182182
* printfln!("%?", bytes);
183-
* let result_str = str::from_bytes(bytes);
183+
* let result_str = str::from_utf8(bytes);
184184
* printfln!("%s", result_str);
185185
* }
186186
* ~~~

src/libextra/bitv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl Bitv {
523523
* with the most significant bits of each byte coming first. Each
524524
* bit becomes true if equal to 1 or false if equal to 0.
525525
*/
526-
pub fn from_bytes(bytes: &[u8]) -> Bitv {
526+
pub fn from_utf8(bytes: &[u8]) -> Bitv {
527527
from_fn(bytes.len() * 8, |i| {
528528
let b = bytes[i / 8] as uint;
529529
let offset = i % 8;
@@ -1275,8 +1275,8 @@ mod tests {
12751275
}
12761276
12771277
#[test]
1278-
fn test_from_bytes() {
1279-
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
1278+
fn test_from_utf8() {
1279+
let bitv = from_utf8([0b10110110, 0b00000000, 0b11111111]);
12801280
let str = ~"10110110" + "00000000" + "11111111";
12811281
assert_eq!(bitv.to_str(), str);
12821282
}
@@ -1302,7 +1302,7 @@ mod tests {
13021302
#[test]
13031303
fn test_to_bools() {
13041304
let bools = ~[false, false, true, false, false, true, true, false];
1305-
assert_eq!(from_bytes([0b00100110]).to_bools(), bools);
1305+
assert_eq!(from_utf8([0b00100110]).to_bools(), bools);
13061306
}
13071307
13081308
#[test]

src/libextra/ebml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Doc {
4141
}
4242

4343
pub fn as_str_slice<'a>(&'a self) -> &'a str {
44-
str::from_bytes_slice(self.data.slice(self.start, self.end))
44+
str::from_utf8_slice(self.data.slice(self.start, self.end))
4545
}
4646

4747
pub fn as_str(&self) -> ~str {

src/libextra/hex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] {
4545
}
4646

4747
unsafe {
48-
str::raw::from_bytes_owned(v)
48+
str::raw::from_utf8_owned(v)
4949
}
5050
}
5151
}
@@ -62,7 +62,7 @@ impl<'self> FromHex for &'self str {
6262
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
6363
* to the byte values it encodes.
6464
*
65-
* You can use the `from_bytes` function in `std::str`
65+
* You can use the `from_utf8` function in `std::str`
6666
* to turn a `[u8]` into a string with characters corresponding to those
6767
* values.
6868
*
@@ -80,7 +80,7 @@ impl<'self> FromHex for &'self str {
8080
* printfln!("%s", hello_str);
8181
* let bytes = hello_str.from_hex().unwrap();
8282
* printfln!("%?", bytes);
83-
* let result_str = str::from_bytes(bytes);
83+
* let result_str = str::from_utf8(bytes);
8484
* printfln!("%s", result_str);
8585
* }
8686
* ~~~

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ impl<T : iterator::Iterator<char>> Parser<T> {
858858

859859
/// Decodes a json value from an @io::Reader
860860
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
861-
let s = str::from_bytes(rdr.read_whole_stream());
861+
let s = str::from_utf8(rdr.read_whole_stream());
862862
let mut parser = Parser(~s.iter());
863863
parser.parse()
864864
}

src/libextra/terminfo/parser/compiled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
213213
return Err(~"incompatible file: more string offsets than expected");
214214
}
215215

216-
let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
216+
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
217217
let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect();
218218

219219
file.read_byte(); // consume NUL

src/libextra/uuid.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Uuid {
210210
///
211211
/// # Arguments
212212
/// * `b` An array or slice of 16 bytes
213-
pub fn from_bytes(b: &[u8]) -> Option<Uuid> {
213+
pub fn from_utf8(b: &[u8]) -> Option<Uuid> {
214214
if b.len() != 16 {
215215
return None
216216
}
@@ -307,7 +307,7 @@ impl Uuid {
307307
s[i*2+0] = digit[0];
308308
s[i*2+1] = digit[1];
309309
}
310-
str::from_bytes(s)
310+
str::from_utf8(s)
311311
}
312312

313313
/// Returns a string of hexadecimal digits, separated into groups with a hypen
@@ -413,7 +413,7 @@ impl Uuid {
413413
ub[i] = FromStrRadix::from_str_radix(vs.slice(i*2, (i+1)*2), 16).unwrap();
414414
}
415415

416-
Ok(Uuid::from_bytes(ub).unwrap())
416+
Ok(Uuid::from_utf8(ub).unwrap())
417417
}
418418
}
419419

@@ -705,11 +705,11 @@ mod test {
705705
}
706706

707707
#[test]
708-
fn test_from_bytes() {
708+
fn test_from_utf8() {
709709
let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
710710
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
711711

712-
let u = Uuid::from_bytes(b).unwrap();
712+
let u = Uuid::from_utf8(b).unwrap();
713713
let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8";
714714

715715
assert!(u.to_simple_str() == expected);
@@ -729,7 +729,7 @@ mod test {
729729
let b_in: [u8, ..16] = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
730730
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
731731

732-
let u = Uuid::from_bytes(b_in.clone()).unwrap();
732+
let u = Uuid::from_utf8(b_in.clone()).unwrap();
733733

734734
let b_out = u.to_bytes();
735735

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub mod write {
386386
cc_prog, prog.status));
387387
sess.note(fmt!("%s arguments: %s",
388388
cc_prog, cc_args.connect(" ")));
389-
sess.note(str::from_bytes(prog.error + prog.output));
389+
sess.note(str::from_utf8(prog.error + prog.output));
390390
sess.abort_if_errors();
391391
}
392392
}
@@ -943,7 +943,7 @@ pub fn link_binary(sess: Session,
943943
cc_prog, prog.status));
944944
sess.note(fmt!("%s arguments: %s",
945945
cc_prog, cc_args.connect(" ")));
946-
sess.note(str::from_bytes(prog.error + prog.output));
946+
sess.note(str::from_utf8(prog.error + prog.output));
947947
sess.abort_if_errors();
948948
}
949949

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) {
12391239
do reader::with_doc_data(d) |desc| {
12401240
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
12411241
let pathbytes = desc.slice(4u, desc.len());
1242-
let path = str::from_bytes(pathbytes);
1242+
let path = str::from_utf8(pathbytes);
12431243

12441244
(path, pos)
12451245
}

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
9797

9898
fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) ->
9999
ast::Ident {
100-
let rslt = scan(st, is_last, str::from_bytes);
100+
let rslt = scan(st, is_last, str::from_utf8);
101101
return st.tcx.sess.ident_of(rslt);
102102
}
103103

@@ -477,7 +477,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
477477
let mut abis = AbiSet::empty();
478478
while peek(st) != ']' {
479479
// FIXME(#5422) str API should not force this copy
480-
let abi_str = scan(st, |c| c == ',', str::from_bytes);
480+
let abi_str = scan(st, |c| c == ',', str::from_utf8);
481481
let abi = abi::lookup(abi_str).expect(abi_str);
482482
abis.add(abi);
483483
}

src/librustc/rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Available lint options:
161161
max_key = num::max(name.len(), max_key);
162162
}
163163
fn padded(max: uint, s: &str) -> ~str {
164-
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
164+
str::from_utf8(vec::from_elem(max - s.len(), ' ' as u8)) + s
165165
}
166166
println("\nAvailable lint checks:\n");
167167
printfln!(" %s %7.7s %s",
@@ -244,7 +244,7 @@ pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
244244
1u => {
245245
let ifile = matches.free[0].as_slice();
246246
if "-" == ifile {
247-
let src = str::from_bytes(io::stdin().read_whole_stream());
247+
let src = str::from_utf8(io::stdin().read_whole_stream());
248248
str_input(src.to_managed())
249249
} else {
250250
file_input(Path(ifile))

src/librustdoc/markdown_writer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ fn pandoc_writer(
116116

117117
debug!("pandoc result: %i", output.status);
118118
if output.status != 0 {
119-
error!("pandoc-out: %s", str::from_bytes(output.output));
120-
error!("pandoc-err: %s", str::from_bytes(output.error));
119+
error!("pandoc-out: %s", str::from_utf8(output.output));
120+
error!("pandoc-err: %s", str::from_utf8(output.error));
121121
fail!("pandoc failed");
122122
}
123123
}

src/librustpkg/rustpkg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'self> PkgScript<'self> {
153153
exe.to_str(), sysroot.to_str(), "configs");
154154
let output = run::process_output(exe.to_str(), [sysroot.to_str(), ~"configs"]);
155155
// Run the configs() function to get the configs
156-
let cfgs = str::from_bytes_slice(output.output).word_iter()
156+
let cfgs = str::from_utf8_slice(output.output).word_iter()
157157
.map(|w| w.to_owned()).collect();
158158
(cfgs, output.status)
159159
}

src/librustpkg/source_control.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
2222
debug!("Running: git clone %s %s", source.to_str(), target.to_str());
2323
let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]);
2424
if outp.status != 0 {
25-
io::println(str::from_bytes_owned(outp.output.clone()));
26-
io::println(str::from_bytes_owned(outp.error));
25+
io::println(str::from_utf8_owned(outp.output.clone()));
26+
io::println(str::from_utf8_owned(outp.error));
2727
fail!("Couldn't `git clone` %s", source.to_str());
2828
}
2929
else {
@@ -36,8 +36,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
3636
fmt!("--git-dir=%s", target.push(".git").to_str()),
3737
~"checkout", fmt!("%s", *s)]);
3838
if outp.status != 0 {
39-
io::println(str::from_bytes_owned(outp.output.clone()));
40-
io::println(str::from_bytes_owned(outp.error));
39+
io::println(str::from_utf8_owned(outp.output.clone()));
40+
io::println(str::from_utf8_owned(outp.error));
4141
fail!("Couldn't `git checkout %s` in %s",
4242
*s, target.to_str());
4343
}
@@ -64,8 +64,8 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
6464
pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool {
6565
let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]);
6666
if outp.status != 0 {
67-
debug!(str::from_bytes_owned(outp.output.clone()));
68-
debug!(str::from_bytes_owned(outp.error));
67+
debug!(str::from_utf8_owned(outp.output.clone()));
68+
debug!(str::from_utf8_owned(outp.error));
6969
false
7070
}
7171
else {
@@ -74,8 +74,8 @@ pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool {
7474
let outp = process_output_in_cwd("git", [~"checkout", fmt!("%s", *s)],
7575
target);
7676
if outp.status != 0 {
77-
debug!(str::from_bytes_owned(outp.output.clone()));
78-
debug!(str::from_bytes_owned(outp.error));
77+
debug!(str::from_utf8_owned(outp.output.clone()));
78+
debug!(str::from_utf8_owned(outp.error));
7979
false
8080
}
8181
else {

src/librustpkg/tests.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
123123
let rslt = prog.finish_with_output();
124124
if rslt.status != 0 {
125125
fail!("%s [git returned %?, output = %s, error = %s]", err_msg,
126-
rslt.status, str::from_bytes(rslt.output), str::from_bytes(rslt.error));
126+
rslt.status, str::from_utf8(rslt.output), str::from_utf8(rslt.error));
127127
}
128128
}
129129

@@ -230,8 +230,8 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
230230
});
231231
let output = prog.finish_with_output();
232232
debug!("Output from command %s with args %? was %s {%s}[%?]",
233-
cmd, args, str::from_bytes(output.output),
234-
str::from_bytes(output.error),
233+
cmd, args, str::from_utf8(output.output),
234+
str::from_utf8(output.error),
235235
output.status);
236236
/*
237237
By the way, rustpkg *won't* return a nonzero exit code if it fails --
@@ -242,7 +242,7 @@ to make sure the command succeeded
242242
if output.status != 0 {
243243
fail!("Command %s %? failed with exit code %?; its output was {{{ %s }}}",
244244
cmd, args, output.status,
245-
str::from_bytes(output.output) + str::from_bytes(output.error));
245+
str::from_utf8(output.output) + str::from_utf8(output.error));
246246
}
247247
output
248248
}
@@ -358,7 +358,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
358358
fn command_line_test_output(args: &[~str]) -> ~[~str] {
359359
let mut result = ~[];
360360
let p_output = command_line_test(args, &os::getcwd());
361-
let test_output = str::from_bytes(p_output.output);
361+
let test_output = str::from_utf8(p_output.output);
362362
for s in test_output.split_iter('\n') {
363363
result.push(s.to_owned());
364364
}
@@ -368,7 +368,7 @@ fn command_line_test_output(args: &[~str]) -> ~[~str] {
368368
fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~str] {
369369
let mut result = ~[];
370370
let p_output = command_line_test_with_env(args, &os::getcwd(), Some(env));
371-
let test_output = str::from_bytes(p_output.output);
371+
let test_output = str::from_utf8(p_output.output);
372372
for s in test_output.split_iter('\n') {
373373
result.push(s.to_owned());
374374
}
@@ -985,7 +985,7 @@ fn test_info() {
985985
let expected_info = ~"package foo"; // fill in
986986
let workspace = create_local_package(&PkgId::new("foo"));
987987
let output = command_line_test([~"info", ~"foo"], &workspace);
988-
assert_eq!(str::from_bytes(output.output), expected_info);
988+
assert_eq!(str::from_utf8(output.output), expected_info);
989989
}
990990
991991
#[test]
@@ -994,7 +994,7 @@ fn test_rustpkg_test() {
994994
let expected_results = ~"1 out of 1 tests passed"; // fill in
995995
let workspace = create_local_package_with_test(&PkgId::new("foo"));
996996
let output = command_line_test([~"test", ~"foo"], &workspace);
997-
assert_eq!(str::from_bytes(output.output), expected_results);
997+
assert_eq!(str::from_utf8(output.output), expected_results);
998998
}
999999
10001000
#[test]
@@ -1004,7 +1004,7 @@ fn test_uninstall() {
10041004
let _output = command_line_test([~"info", ~"foo"], &workspace);
10051005
command_line_test([~"uninstall", ~"foo"], &workspace);
10061006
let output = command_line_test([~"list"], &workspace);
1007-
assert!(!str::from_bytes(output.output).contains("foo"));
1007+
assert!(!str::from_utf8(output.output).contains("foo"));
10081008
}
10091009
10101010
#[test]
@@ -1073,8 +1073,8 @@ fn test_extern_mod() {
10731073
let outp = prog.finish_with_output();
10741074
if outp.status != 0 {
10751075
fail!("output was %s, error was %s",
1076-
str::from_bytes(outp.output),
1077-
str::from_bytes(outp.error));
1076+
str::from_utf8(outp.output),
1077+
str::from_utf8(outp.error));
10781078
}
10791079
assert!(os::path_exists(&exec_file) && is_executable(&exec_file));
10801080
}

0 commit comments

Comments
 (0)