Skip to content

Commit 5795bb1

Browse files
committed
std: rename str::from_bytes{,_with_null,_slice} to from_utf8*
1 parent 48312a5 commit 5795bb1

File tree

24 files changed

+71
-71
lines changed

24 files changed

+71
-71
lines changed

src/compiletest/procsrv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn run(lib_path: &str,
6565

6666
Result {
6767
status: output.status,
68-
out: str::from_bytes(output.output),
69-
err: str::from_bytes(output.error)
68+
out: str::from_utf8(output.output),
69+
err: str::from_utf8(output.error)
7070
}
7171
}

src/libextra/base64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'self> FromBase64 for &'self str {
217217
* println(fmt!("%s",hello_str));
218218
* let bytes = hello_str.from_base64();
219219
* println(fmt!("%?",bytes));
220-
* let result_str = str::from_bytes(bytes);
220+
* let result_str = str::from_utf8(bytes);
221221
* println(fmt!("%s",result_str));
222222
* }
223223
* ~~~

src/libextra/ebml.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub mod reader {
9595
}
9696

9797
pub fn as_str_slice<'a>(&'a self) -> &'a str {
98-
str::from_bytes_slice(self.data.slice(self.start, self.end))
98+
str::from_utf8_slice(self.data.slice(self.start, self.end))
9999
}
100100

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

src/libextra/net_tcp.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ mod test {
18001800
buf_write(sock_buf, expected_req);
18011801

18021802
let buf_reader = sock_buf as @Reader;
1803-
let actual_response = str::from_bytes(buf_reader.read_whole_stream());
1803+
let actual_response = str::from_utf8(buf_reader.read_whole_stream());
18041804
debug!("Actual response: %s", actual_response);
18051805
assert!(expected_resp == actual_response);
18061806
}
@@ -1817,7 +1817,7 @@ mod test {
18171817
let new_bytes = (*r).read_bytes(len);
18181818
debug!("in buf_read.. new_bytes len: %?",
18191819
new_bytes.len());
1820-
str::from_bytes(new_bytes)
1820+
str::from_utf8(new_bytes)
18211821
}
18221822

18231823
fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str,
@@ -1867,11 +1867,11 @@ mod test {
18671867
let received_req_bytes = read(&sock, 0u);
18681868
match received_req_bytes {
18691869
result::Ok(data) => {
1870-
debug!("SERVER: got REQ str::from_bytes..");
1870+
debug!("SERVER: got REQ str::from_utf8..");
18711871
debug!("SERVER: REQ data len: %?",
18721872
data.len());
18731873
server_ch.send(
1874-
str::from_bytes(data));
1874+
str::from_utf8(data));
18751875
debug!("SERVER: before write");
18761876
let s = resp_cell2.take();
18771877
tcp_write_single(&sock, s.as_bytes().to_owned());
@@ -1954,7 +1954,7 @@ mod test {
19541954
Ok(~"")
19551955
}
19561956
else {
1957-
let ret_val = str::from_bytes(read_result.get());
1957+
let ret_val = str::from_utf8(read_result.get());
19581958
debug!("CLIENT: after client_ch recv ret: '%s'",
19591959
ret_val);
19601960
Ok(ret_val)

src/libextra/terminfo/parser/compiled.rs

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

215-
let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
215+
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
216216
let term_names = names_str.split_iter('|').transform(|s| s.to_owned()).collect();
217217

218218
file.read_byte(); // consume NUL

src/libextra/uv_ll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ mod test {
12871287
let buf_base = get_base_from_buf(buf);
12881288
let bytes = vec::from_buf(buf_base, nread as uint);
12891289
let read_chan = (*client_data).read_chan.clone();
1290-
let msg_from_server = str::from_bytes(bytes);
1290+
let msg_from_server = str::from_utf8(bytes);
12911291
read_chan.send(msg_from_server);
12921292
close(stream as *libc::c_void, after_close_cb)
12931293
}
@@ -1473,7 +1473,7 @@ mod test {
14731473
buf_len as uint,
14741474
nread);
14751475
let bytes = vec::from_buf(buf_base, nread as uint);
1476-
let request_str = str::from_bytes(bytes);
1476+
let request_str = str::from_utf8(bytes);
14771477
14781478
let client_data = get_data_for_uv_handle(
14791479
client_stream_ptr as *libc::c_void) as *tcp_server_data;

src/librustc/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub mod write {
397397
cc_prog, prog.status));
398398
sess.note(fmt!("%s arguments: %s",
399399
cc_prog, cc_args.connect(" ")));
400-
sess.note(str::from_bytes(prog.error + prog.output));
400+
sess.note(str::from_utf8(prog.error + prog.output));
401401
sess.abort_if_errors();
402402
}
403403
}
@@ -819,7 +819,7 @@ pub fn link_binary(sess: Session,
819819
cc_prog, prog.status));
820820
sess.note(fmt!("%s arguments: %s",
821821
cc_prog, cc_args.connect(" ")));
822-
sess.note(str::from_bytes(prog.error + prog.output));
822+
sess.note(str::from_utf8(prog.error + prog.output));
823823
sess.abort_if_errors();
824824
}
825825

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) {
941941
do reader::with_doc_data(d) |desc| {
942942
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
943943
let pathbytes = desc.slice(4u, desc.len());
944-
let path = str::from_bytes(pathbytes);
944+
let path = str::from_utf8(pathbytes);
945945

946946
(path, pos)
947947
}

src/librustc/metadata/tydecode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::ident {
9999

100100
fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) ->
101101
ast::ident {
102-
let rslt = scan(st, is_last, str::from_bytes);
102+
let rslt = scan(st, is_last, str::from_utf8);
103103
return st.tcx.sess.ident_of(rslt);
104104
}
105105

@@ -453,7 +453,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
453453
let mut abis = AbiSet::empty();
454454
while peek(st) != ']' {
455455
// FIXME(#5422) str API should not force this copy
456-
let abi_str = scan(st, |c| c == ',', str::from_bytes);
456+
let abi_str = scan(st, |c| c == ',', str::from_utf8);
457457
let abi = abi::lookup(abi_str).expect(abi_str);
458458
abis.add(abi);
459459
}

src/librustc/rustc.rc

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Available lint options:
168168
let mut max_key = 0;
169169
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
170170
fn padded(max: uint, s: &str) -> ~str {
171-
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
171+
str::from_utf8(vec::from_elem(max - s.len(), ' ' as u8)) + s
172172
}
173173
io::println(fmt!("\nAvailable lint checks:\n"));
174174
io::println(fmt!(" %s %7.7s %s",
@@ -251,7 +251,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
251251
1u => {
252252
let ifile = matches.free[0].as_slice();
253253
if "-" == ifile {
254-
let src = str::from_bytes(io::stdin().read_whole_stream());
254+
let src = str::from_utf8(io::stdin().read_whole_stream());
255255
str_input(src.to_managed())
256256
} else {
257257
file_input(Path(ifile))

src/librustc/util/ppaux.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,11 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
433433
ty_param(param_ty {idx: id, def_id: did}) => {
434434
if cx.sess.verbose() {
435435
fmt!("'%s:%?",
436-
str::from_bytes([('a' as u8) + (id as u8)]),
436+
str::from_utf8([('a' as u8) + (id as u8)]),
437437
did)
438438
} else {
439439
fmt!("'%s",
440-
str::from_bytes([('a' as u8) + (id as u8)]))
440+
str::from_utf8([('a' as u8) + (id as u8)]))
441441
}
442442
}
443443
ty_self(*) => ~"Self",

src/librustpkg/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ fn test_info() {
660660
let expected_info = ~"package foo"; // fill in
661661
let workspace = create_local_package(&PkgId::new("foo"));
662662
let output = command_line_test([~"info", ~"foo"], &workspace);
663-
assert_eq!(str::from_bytes(output.output), expected_info);
663+
assert_eq!(str::from_utf8(output.output), expected_info);
664664
}
665665
666666
#[test]
@@ -669,7 +669,7 @@ fn test_rustpkg_test() {
669669
let expected_results = ~"1 out of 1 tests passed"; // fill in
670670
let workspace = create_local_package_with_test(&PkgId::new("foo"));
671671
let output = command_line_test([~"test", ~"foo"], &workspace);
672-
assert_eq!(str::from_bytes(output.output), expected_results);
672+
assert_eq!(str::from_utf8(output.output), expected_results);
673673
}
674674
675675
#[test]
@@ -679,5 +679,5 @@ fn test_uninstall() {
679679
let _output = command_line_test([~"info", ~"foo"], &workspace);
680680
command_line_test([~"uninstall", ~"foo"], &workspace);
681681
let output = command_line_test([~"list"], &workspace);
682-
assert!(!str::from_bytes(output.output).contains("foo"));
682+
assert!(!str::from_utf8(output.output).contains("foo"));
683683
}

src/libstd/io.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<T:Reader> ReaderUtil for T {
636636
}
637637
bytes.push(ch as u8);
638638
}
639-
str::from_bytes(bytes)
639+
str::from_utf8(bytes)
640640
}
641641

642642
fn read_line(&self) -> ~str {
@@ -645,7 +645,7 @@ impl<T:Reader> ReaderUtil for T {
645645

646646
fn read_chars(&self, n: uint) -> ~[char] {
647647
// returns the (consumed offset, n_req), appends characters to &chars
648-
fn chars_from_bytes<T:Reader>(bytes: &~[u8], chars: &mut ~[char])
648+
fn chars_from_utf8<T:Reader>(bytes: &~[u8], chars: &mut ~[char])
649649
-> (uint, uint) {
650650
let mut i = 0;
651651
let bytes_len = bytes.len();
@@ -691,7 +691,7 @@ impl<T:Reader> ReaderUtil for T {
691691
break;
692692
}
693693
bytes.push_all(data);
694-
let (offset, nbreq) = chars_from_bytes::<T>(&bytes, &mut chars);
694+
let (offset, nbreq) = chars_from_utf8::<T>(&bytes, &mut chars);
695695
let ncreq = n - chars.len();
696696
// again we either know we need a certain number of bytes
697697
// to complete a character, or we make sure we don't
@@ -1721,7 +1721,7 @@ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
17211721
pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
17221722
result::chain(read_whole_file(file), |bytes| {
17231723
if str::is_utf8(bytes) {
1724-
result::Ok(str::from_bytes(bytes))
1724+
result::Ok(str::from_utf8(bytes))
17251725
} else {
17261726
result::Err(file.to_str() + " is not UTF-8")
17271727
}

src/libstd/logging.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn log_type<T>(level: u32, object: &T) {
6060
}
6161
_ => {
6262
// XXX: Bad allocation
63-
let msg = str::from_bytes(bytes);
63+
let msg = str::from_utf8(bytes);
6464
newsched_log_str(msg);
6565
}
6666
}

src/libstd/num/strconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
388388
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
389389
let (bytes, special) = to_str_bytes_common(num, radix,
390390
negative_zero, sign, digits);
391-
(str::from_bytes(bytes), special)
391+
(str::from_utf8(bytes), special)
392392
}
393393

394394
// Some constants for from_str_bytes_common's input validation,

src/libstd/rt/io/flate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mod test {
117117
let mut out_bytes = [0, .. 100];
118118
let bytes_read = inflate_reader.read(out_bytes).get();
119119
assert_eq!(bytes_read, in_bytes.len());
120-
let out_msg = str::from_bytes(out_bytes);
120+
let out_msg = str::from_utf8(out_bytes);
121121
assert!(in_msg == out_msg);
122122
}
123123
}

src/libstd/run.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ mod tests {
954954

955955
let run::ProcessOutput {status, output, error}
956956
= run::process_output("echo", [~"hello"]);
957-
let output_str = str::from_bytes(output);
957+
let output_str = str::from_utf8(output);
958958
959959
assert_eq!(status, 0);
960960
assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -1016,7 +1016,7 @@ mod tests {
10161016
let reader = io::FILE_reader(file, false);
10171017
let buf = reader.read_whole_stream();
10181018
os::fclose(file);
1019-
str::from_bytes(buf)
1019+
str::from_utf8(buf)
10201020
}
10211021
}
10221022
@@ -1039,7 +1039,7 @@ mod tests {
10391039
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new());
10401040
let run::ProcessOutput {status, output, error}
10411041
= prog.finish_with_output();
1042-
let output_str = str::from_bytes(output);
1042+
let output_str = str::from_utf8(output);
10431043
10441044
assert_eq!(status, 0);
10451045
assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -1053,7 +1053,7 @@ mod tests {
10531053
let run::ProcessOutput {status, output, error}
10541054
= prog.finish_with_output();
10551055
1056-
let output_str = str::from_bytes(output);
1056+
let output_str = str::from_utf8(output);
10571057
10581058
assert_eq!(status, 0);
10591059
assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -1102,7 +1102,7 @@ mod tests {
11021102
fn test_keep_current_working_dir() {
11031103
let mut prog = run_pwd(None);
11041104
1105-
let output = str::from_bytes(prog.finish_with_output().output);
1105+
let output = str::from_utf8(prog.finish_with_output().output);
11061106
let parent_dir = os::getcwd().normalize();
11071107
let child_dir = Path(output.trim()).normalize();
11081108
@@ -1120,7 +1120,7 @@ mod tests {
11201120
let parent_dir = os::getcwd().dir_path().normalize();
11211121
let mut prog = run_pwd(Some(&parent_dir));
11221122
1123-
let output = str::from_bytes(prog.finish_with_output().output);
1123+
let output = str::from_utf8(prog.finish_with_output().output);
11241124
let child_dir = Path(output.trim()).normalize();
11251125
11261126
let parent_stat = parent_dir.stat().unwrap();
@@ -1150,7 +1150,7 @@ mod tests {
11501150
fn test_inherit_env() {
11511151
11521152
let mut prog = run_env(None);
1153-
let output = str::from_bytes(prog.finish_with_output().output);
1153+
let output = str::from_utf8(prog.finish_with_output().output);
11541154
11551155
for os::env().each |&(k, v)| {
11561156
// don't check windows magical empty-named variables
@@ -1165,7 +1165,7 @@ mod tests {
11651165
new_env.push((~"RUN_TEST_NEW_ENV", ~"123"));
11661166
11671167
let mut prog = run_env(Some(new_env.slice(0, new_env.len())));
1168-
let output = str::from_bytes(prog.finish_with_output().output);
1168+
let output = str::from_utf8(prog.finish_with_output().output);
11691169
11701170
assert!(output.contains("RUN_TEST_NEW_ENV=123"));
11711171
}

0 commit comments

Comments
 (0)