Skip to content
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

Str from bytes API cleanup, attempt 2 #7172

Closed
wants to merge 6 commits 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
8 changes: 4 additions & 4 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ pub fn run(lib_path: &str,
for input.iter().advance |input| {
proc.input().write_str(*input);
}
let output = proc.finish_with_output();
let run::ProcessOutput { status, output, error, _ } = proc.finish_with_output();

Result {
status: output.status,
out: str::from_bytes(output.output),
err: str::from_bytes(output.error)
status: status,
out: str::from_utf8(output),
err: str::from_utf8(error)
}
}
2 changes: 1 addition & 1 deletion src/libextra/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<'self> FromBase64 for &'self str {
* println(fmt!("%s",hello_str));
* let bytes = hello_str.from_base64();
* println(fmt!("%?",bytes));
* let result_str = str::from_bytes(bytes);
* let result_str = str::from_utf8(bytes);
* println(fmt!("%s",result_str));
* }
* ~~~
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub mod reader {
}

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
10 changes: 5 additions & 5 deletions src/libextra/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ mod test {
buf_write(sock_buf, expected_req);

let buf_reader = sock_buf as @Reader;
let actual_response = str::from_bytes(buf_reader.read_whole_stream());
let actual_response = str::from_utf8(buf_reader.read_whole_stream());
debug!("Actual response: %s", actual_response);
assert!(expected_resp == actual_response);
}
Expand All @@ -1817,7 +1817,7 @@ mod test {
let new_bytes = (*r).read_bytes(len);
debug!("in buf_read.. new_bytes len: %?",
new_bytes.len());
str::from_bytes(new_bytes)
str::from_utf8(new_bytes)
}

fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str,
Expand Down Expand Up @@ -1867,11 +1867,11 @@ mod test {
let received_req_bytes = read(&sock, 0u);
match received_req_bytes {
result::Ok(data) => {
debug!("SERVER: got REQ str::from_bytes..");
debug!("SERVER: got REQ str::from_utf8..");
debug!("SERVER: REQ data len: %?",
data.len());
server_ch.send(
str::from_bytes(data));
str::from_utf8(data));
debug!("SERVER: before write");
let s = resp_cell2.take();
tcp_write_single(&sock, s.as_bytes().to_owned());
Expand Down Expand Up @@ -1954,7 +1954,7 @@ mod test {
Ok(~"")
}
else {
let ret_val = str::from_bytes(read_result.get());
let ret_val = str::from_utf8(read_result.get());
debug!("CLIENT: after client_ch recv ret: '%s'",
ret_val);
Ok(ret_val)
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/rl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ pub unsafe fn complete(cb: CompletionCb) {

extern fn callback(line: *c_char, completions: *()) {
unsafe {
let cb = *local_data::local_data_get(complete_key)
.get();
let cb = *local_data::local_data_get(complete_key).get();

do cb(str::raw::from_c_str(line)) |suggestion| {
do str::as_c_str(suggestion) |buf| {
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ 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 term_names: ~[~str] = names_str.split_iter('|').transform(|s| s.to_owned()).collect();
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
let term_names = names_str.split_iter('|').transform(|s| s.to_owned()).collect();

file.read_byte(); // consume NUL

Expand Down
6 changes: 3 additions & 3 deletions src/libextra/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ pub unsafe fn ip6_addr(ip: &str, port: int) -> sockaddr_in6 {
pub unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
// ipv4 addr max size: 15 + 1 trailing null byte
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
do vec::as_imm_buf(dst) |dst_buf, size| {
rust_uv_ip4_name(to_unsafe_ptr(src),
dst_buf, size as libc::size_t);
Expand Down Expand Up @@ -1287,7 +1287,7 @@ mod test {
let buf_base = get_base_from_buf(buf);
let bytes = vec::from_buf(buf_base, nread as uint);
let read_chan = (*client_data).read_chan.clone();
let msg_from_server = str::from_bytes(bytes);
let msg_from_server = str::from_utf8(bytes);
read_chan.send(msg_from_server);
close(stream as *libc::c_void, after_close_cb)
}
Expand Down Expand Up @@ -1473,7 +1473,7 @@ mod test {
buf_len as uint,
nread);
let bytes = vec::from_buf(buf_base, nread as uint);
let request_str = str::from_bytes(bytes);
let request_str = str::from_utf8(bytes);

let client_data = get_data_for_uv_handle(
client_stream_ptr as *libc::c_void) as *tcp_server_data;
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 @@ -397,7 +397,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 @@ -819,7 +819,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 @@ -941,7 +941,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_slice(pathbytes).to_owned();

(path, pos)
}
Expand Down
21 changes: 12 additions & 9 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ fn scan<R>(st: &mut PState, is_last: &fn(char) -> bool,
}
let end_pos = st.pos;
st.pos += 1;
return op(st.data.slice(start_pos, end_pos));
op(st.data.slice(start_pos, end_pos))
}

pub fn parse_ident(st: &mut PState, last: char) -> ast::ident {
fn is_last(b: char, c: char) -> bool { return c == b; }
return parse_ident_(st, |a| is_last(last, a) );
}

fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) ->
ast::ident {
let rslt = scan(st, is_last, str::from_bytes);
return st.tcx.sess.ident_of(rslt);
fn parse_ident_(st: &mut PState, is_last: @fn(char) -> bool) -> ast::ident {
do scan(st, is_last) |v| {
st.tcx.sess.ident_of(str::from_utf8_slice(v))
}
}

pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: int,
Expand Down Expand Up @@ -409,7 +409,9 @@ fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {

fn parse_def(st: &mut PState, source: DefIdSource,
conv: conv_did) -> ast::def_id {
return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
do scan(st, |c| { c == '|' }) |v| {
conv(source, parse_def_id(v))
}
}

fn parse_uint(st: &mut PState) -> uint {
Expand Down Expand Up @@ -450,9 +452,10 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
assert_eq!(next(st), '[');
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 = abi::lookup(abi_str).expect(abi_str);
let abi = do scan(st, |c| c == ',') |v| {
let abi_str = str::from_utf8_slice(v);
abi::lookup(abi_str).expect(abi_str)
};
abis.add(abi);
}
assert_eq!(next(st), ']');
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/rustc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Available lint options:
let mut max_key = 0;
for lint_dict.each_key |k| { max_key = uint::max(k.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
}
io::println(fmt!("\nAvailable lint checks:\n"));
io::println(fmt!(" %s %7.7s %s",
Expand Down Expand Up @@ -251,7 +251,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
7 changes: 2 additions & 5 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,9 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_err => ~"[type error]",
ty_param(param_ty {idx: id, def_id: did}) => {
if cx.sess.verbose() {
fmt!("'%s:%?",
str::from_bytes([('a' as u8) + (id as u8)]),
did)
fmt!("'%s:%?", str::from_byte(('a' as u8) + (id as u8)), did)
} else {
fmt!("'%s",
str::from_bytes([('a' as u8) + (id as u8)]))
fmt!("'%s", str::from_byte(('a' as u8) + (id as u8)))
}
}
ty_self(*) => ~"Self",
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_slice(output.output));
error!("pandoc-err: %s", str::from_utf8_slice(output.error));
fail!("pandoc failed");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/package_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ impl PkgSrc {
&& self.tests.is_empty() && self.benchs.is_empty() {

note("Couldn't infer any crates to build.\n\
Try naming a crate `main.rs`, `lib.rs`, \
`test.rs`, or `bench.rs`.");
Try naming a crate `main.rs`, `lib.rs`, \
`test.rs`, or `bench.rs`.");
cond.raise(copy self.id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'self> PkgScript<'self> {
exe.to_str(), root.to_str(), "configs");
let output = run::process_output(exe.to_str(), [root.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()
.transform(|w| w.to_owned()).collect();
(cfgs, output.status)
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
});
let output = prog.finish_with_output();
io::println(fmt!("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_slice(output.output),
str::from_utf8_slice(output.error),
output.status));
/*
By the way, rustpkg *won't* return a nonzero exit code if it fails --
Expand Down Expand Up @@ -246,7 +246,7 @@ fn assert_executable_exists(repo: &Path, short_name: &str) {
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_slice(p_output.output);
for test_output.split_iter('\n').advance |s| {
result += [s.to_owned()];
}
Expand Down Expand Up @@ -660,7 +660,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 @@ -669,7 +669,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 @@ -679,5 +679,5 @@ 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"));
}
8 changes: 4 additions & 4 deletions src/librustpkg/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ pub fn try_getting_version(remote_path: &RemotePath) -> Option<Version> {
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_slice(outp.output),
str::from_utf8_slice(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_slice(outp.output);
debug!("Full output: ( %s ) [%?]", output_text, outp.status);
for output_text.line_iter().advance |l| {
debug!("A line of output: %s", l);
Expand Down Expand Up @@ -208,4 +208,4 @@ fn test_split_version() {
let s = "a#1.2";
assert!(split_version(s) == Some((s.slice(0, 1), ExactRevision(~"1.2"))));
assert!(split_version("a#a#3.4") == None);
}
}
8 changes: 4 additions & 4 deletions src/libstd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl<T:Reader> ReaderUtil for T {
}
bytes.push(ch as u8);
}
str::from_bytes(bytes)
str::from_utf8(bytes)
}

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

fn read_chars(&self, n: uint) -> ~[char] {
// 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) {
let mut i = 0;
let bytes_len = bytes.len();
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<T:Reader> ReaderUtil for T {
break;
}
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();
// again we either know we need a certain number of bytes
// to complete a character, or we make sure we don't
Expand Down Expand Up @@ -1721,7 +1721,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> {
result::chain(read_whole_file(file), |bytes| {
if str::is_utf8(bytes) {
result::Ok(str::from_bytes(bytes))
result::Ok(str::from_utf8(bytes))
} else {
result::Err(file.to_str() + " is not UTF-8")
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn log_type<T>(level: u32, object: &T) {
}
_ => {
// XXX: Bad allocation
let msg = str::from_bytes(bytes);
let msg = str::from_utf8(bytes);
newsched_log_str(msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/num/strconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
let (bytes, special) = 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,
Expand Down
Loading