Skip to content

Commit b0426ed

Browse files
committed
std::str: s/from_utf8_slice/from_utf8/, to make the basic case shorter.
1 parent 9d64e46 commit b0426ed

File tree

21 files changed

+70
-70
lines changed

21 files changed

+70
-70
lines changed

Diff for: src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
298298

299299
let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
300300
config.adb_test_dir.clone(), config.adb_test_dir.clone(),
301-
str::from_utf8_slice(exe_file.filename().unwrap()));
301+
str::from_utf8(exe_file.filename().unwrap()));
302302

303303
let mut process = procsrv::run_background("", config.adb_path.clone(),
304304
[~"shell",adb_arg.clone()],~[(~"",~"")], Some(~""));

Diff for: src/libextra/ebml.rs

+1-1
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_utf8_slice(self.data.slice(self.start, self.end))
44+
str::from_utf8(self.data.slice(self.start, self.end))
4545
}
4646

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

Diff for: src/libextra/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ fn should_sort_failures_before_printing_them() {
701701

702702
st.write_failures();
703703
let s = match st.out {
704-
Right(ref m) => str::from_utf8_slice(*m.inner_ref()),
704+
Right(ref m) => str::from_utf8(*m.inner_ref()),
705705
Left(_) => unreachable!()
706706
};
707707

Diff for: src/librustc/back/archive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
4141
let o = Process::new(ar, args.as_slice(), opts).finish_with_output();
4242
if !o.status.success() {
4343
sess.err(format!("{} failed with: {}", ar, o.status));
44-
sess.note(format!("stdout ---\n{}", str::from_utf8_slice(o.output)));
45-
sess.note(format!("stderr ---\n{}", str::from_utf8_slice(o.error)));
44+
sess.note(format!("stdout ---\n{}", str::from_utf8(o.output)));
45+
sess.note(format!("stderr ---\n{}", str::from_utf8(o.error)));
4646
sess.abort_if_errors();
4747
}
4848
o

Diff for: src/librustc/metadata/tydecode.rs

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

9999
fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
100100
scan(st, is_last, |bytes| {
101-
st.tcx.sess.ident_of(str::from_utf8_slice(bytes))
101+
st.tcx.sess.ident_of(str::from_utf8(bytes))
102102
})
103103
}
104104

@@ -494,7 +494,7 @@ fn parse_abi_set(st: &mut PState) -> AbiSet {
494494
let mut abis = AbiSet::empty();
495495
while peek(st) != ']' {
496496
scan(st, |c| c == ',', |bytes| {
497-
let abi_str = str::from_utf8_slice(bytes).to_owned();
497+
let abi_str = str::from_utf8(bytes).to_owned();
498498
let abi = abi::lookup(abi_str).expect(abi_str);
499499
abis.add(abi);
500500
});

Diff for: src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn enc_ty(w: @mut MemWriter, cx: @ctxt, t: ty::t) {
7272
None => {
7373
let wr = @mut MemWriter::new();
7474
enc_sty(wr, cx, &ty::get(t).sty);
75-
let s = str::from_utf8_slice(*wr.inner_ref()).to_managed();
75+
let s = str::from_utf8(*wr.inner_ref()).to_managed();
7676
cx.tcx.short_names_cache.insert(t, s);
7777
s
7878
}

Diff for: src/librustpkg/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'self> PkgScript<'self> {
184184
[sysroot.as_str().unwrap().to_owned(), ~"configs"]);
185185
debug!("run_custom: second pkg command did {:?}", output.status);
186186
// Run the configs() function to get the configs
187-
let cfgs = str::from_utf8_slice(output.output).words()
187+
let cfgs = str::from_utf8(output.output).words()
188188
.map(|w| w.to_owned()).collect();
189189
(cfgs, output.status)
190190
}

Diff for: src/librustpkg/tests.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
154154
let rslt = prog.finish_with_output();
155155
if !rslt.status.success() {
156156
fail!("{} [git returned {:?}, output = {}, error = {}]", err_msg,
157-
rslt.status, str::from_utf8_slice(rslt.output), str::from_utf8_slice(rslt.error));
157+
rslt.status, str::from_utf8(rslt.output), str::from_utf8(rslt.error));
158158
}
159159
}
160160

@@ -290,13 +290,13 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
290290
});
291291
let output = prog.finish_with_output();
292292
debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]",
293-
cmd, args, str::from_utf8_slice(output.output),
294-
str::from_utf8_slice(output.error),
293+
cmd, args, str::from_utf8(output.output),
294+
str::from_utf8(output.error),
295295
output.status);
296296
if !output.status.success() {
297-
debug!("Command {} {:?} failed with exit code {:?}; its output was --- {} ---",
297+
debug!("Command {} {:?} failed with exit code {:?}; its output was --- {} {} ---",
298298
cmd, args, output.status,
299-
str::from_utf8_slice(output.output) + str::from_utf8_slice(output.error));
299+
str::from_utf8(output.output), str::from_utf8(output.error));
300300
Fail(output)
301301
}
302302
else {
@@ -455,7 +455,7 @@ fn built_library_exists(repo: &Path, short_name: &str) -> bool {
455455
fn command_line_test_output(args: &[~str]) -> ~[~str] {
456456
let mut result = ~[];
457457
let p_output = command_line_test(args, &os::getcwd());
458-
let test_output = str::from_utf8_slice(p_output.output);
458+
let test_output = str::from_utf8(p_output.output);
459459
for s in test_output.split('\n') {
460460
result.push(s.to_owned());
461461
}
@@ -469,7 +469,7 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~
469469
Fail(_) => fail!("Command-line test failed"),
470470
Success(r) => r
471471
};
472-
let test_output = str::from_utf8_slice(p_output.output);
472+
let test_output = str::from_utf8(p_output.output);
473473
for s in test_output.split('\n') {
474474
result.push(s.to_owned());
475475
}
@@ -1212,7 +1212,7 @@ fn test_uninstall() {
12121212
let workspace = create_local_package(&PkgId::new("foo"));
12131213
command_line_test([~"uninstall", ~"foo"], workspace.path());
12141214
let output = command_line_test([~"list"], workspace.path());
1215-
assert!(!str::from_utf8_slice(output.output).contains("foo"));
1215+
assert!(!str::from_utf8(output.output).contains("foo"));
12161216
}
12171217
12181218
#[test]
@@ -1282,8 +1282,8 @@ fn test_extern_mod() {
12821282
let outp = prog.finish_with_output();
12831283
if !outp.status.success() {
12841284
fail!("output was {}, error was {}",
1285-
str::from_utf8_slice(outp.output),
1286-
str::from_utf8_slice(outp.error));
1285+
str::from_utf8(outp.output),
1286+
str::from_utf8(outp.error));
12871287
}
12881288
assert!(exec_file.exists() && is_executable(&exec_file));
12891289
}
@@ -1337,8 +1337,8 @@ fn test_extern_mod_simpler() {
13371337
let outp = prog.finish_with_output();
13381338
if !outp.status.success() {
13391339
fail!("output was {}, error was {}",
1340-
str::from_utf8_slice(outp.output),
1341-
str::from_utf8_slice(outp.error));
1340+
str::from_utf8(outp.output),
1341+
str::from_utf8(outp.error));
13421342
}
13431343
assert!(exec_file.exists() && is_executable(&exec_file));
13441344
}
@@ -2101,7 +2101,7 @@ fn test_rustpkg_test_creates_exec() {
21012101
fn test_rustpkg_test_output() {
21022102
let workspace = create_local_package_with_test(&PkgId::new("foo"));
21032103
let output = command_line_test([~"test", ~"foo"], workspace.path());
2104-
let output_str = str::from_utf8_slice(output.output);
2104+
let output_str = str::from_utf8(output.output);
21052105
// The first two assertions are separate because test output may
21062106
// contain color codes, which could appear between "test f" and "ok".
21072107
assert!(output_str.contains("test f"));
@@ -2132,7 +2132,7 @@ fn test_rustpkg_test_cfg() {
21322132
"#[test] #[cfg(not(foobar))] fn f() { assert!('a' != 'a'); }");
21332133
let output = command_line_test([~"test", ~"--cfg", ~"foobar", ~"foo"],
21342134
foo_workspace);
2135-
let output_str = str::from_utf8_slice(output.output);
2135+
let output_str = str::from_utf8(output.output);
21362136
assert!(output_str.contains("0 passed; 0 failed; 0 ignored; 0 measured"));
21372137
}
21382138
@@ -2430,8 +2430,8 @@ fn correct_error_dependency() {
24302430
Fail(ProcessOutput{ error: error, output: output, .. }) => {
24312431
assert!(str::is_utf8(error));
24322432
assert!(str::is_utf8(output));
2433-
let error_str = str::from_utf8_slice(error);
2434-
let out_str = str::from_utf8_slice(output);
2433+
let error_str = str::from_utf8(error);
2434+
let out_str = str::from_utf8(output);
24352435
debug!("ss = {}", error_str);
24362436
debug!("out_str = {}", out_str);
24372437
if out_str.contains("Package badpkg depends on some_package_that_doesnt_exist") &&

Diff for: src/librustpkg/version.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
114114
}
115115

116116
let mut output = None;
117-
let output_text = str::from_utf8_slice(outp.output);
117+
let output_text = str::from_utf8(outp.output);
118118
for l in output_text.lines() {
119119
if !l.is_whitespace() {
120120
output = Some(l);
@@ -145,8 +145,8 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
145145
tmp_dir.as_str().unwrap().to_owned()]);
146146
if outp.status.success() {
147147
debug!("Cloned it... ( {}, {} )",
148-
str::from_utf8_slice(outp.output),
149-
str::from_utf8_slice(outp.error));
148+
str::from_utf8(outp.output),
149+
str::from_utf8(outp.error));
150150
let mut output = None;
151151
let git_dir = tmp_dir.join(".git");
152152
debug!("(getting version, now getting tags) executing \\{git --git-dir={} tag -l\\}",
@@ -155,7 +155,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
155155
let outp = run::process_output("git",
156156
["--git-dir=" + git_dir.as_str().unwrap(),
157157
~"tag", ~"-l"]);
158-
let output_text = str::from_utf8_slice(outp.output);
158+
let output_text = str::from_utf8(outp.output);
159159
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
160160
for l in output_text.lines() {
161161
debug!("A line of output: {}", l);

Diff for: src/librustuv/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ mod test {
487487

488488
let nread = result.unwrap();
489489
assert!(nread > 0);
490-
let read_str = str::from_utf8_slice(read_mem.slice_to(nread as uint));
490+
let read_str = str::from_utf8(read_mem.slice_to(nread as uint));
491491
assert_eq!(read_str, "hello");
492492
}
493493
// unlink

Diff for: src/librustuv/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn sockaddr_to_socket_addr(addr: *sockaddr) -> SocketAddr {
8181
};
8282
port as u16
8383
};
84-
let ip_str = str::from_utf8_slice(ip_name).trim_right_chars(&'\x00');
84+
let ip_str = str::from_utf8(ip_name).trim_right_chars(&'\x00');
8585
let ip_addr = FromStr::from_str(ip_str).unwrap();
8686

8787
SocketAddr { ip: ip_addr, port: ip_port }

Diff for: src/libstd/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CString {
167167
if self.buf.is_null() { return None; }
168168
let buf = self.as_bytes();
169169
let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
170-
str::from_utf8_slice_opt(buf)
170+
str::from_utf8_opt(buf)
171171
}
172172

173173
/// Return a CString iterator.

Diff for: src/libstd/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ impl<'self> Formatter<'self> {
802802

803803
fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) {
804804
::uint::to_str_bytes(value, 10, |buf| {
805-
let valuestr = str::from_utf8_slice(buf);
805+
let valuestr = str::from_utf8(buf);
806806
for piece in pieces.iter() {
807807
self.run(piece, Some(valuestr));
808808
}

Diff for: src/libstd/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).unwrap();
119119
assert_eq!(bytes_read, in_bytes.len());
120-
let out_msg = str::from_utf8_slice(out_bytes);
120+
let out_msg = str::from_utf8(out_bytes);
121121
assert_eq!(in_msg, out_msg);
122122
}
123123
}

Diff for: src/libstd/io/fs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ mod test {
821821
}
822822
}
823823
unlink(filename);
824-
let read_str = str::from_utf8_slice(read_mem);
824+
let read_str = str::from_utf8(read_mem);
825825
assert_eq!(read_str, message);
826826
})
827827

@@ -845,7 +845,7 @@ mod test {
845845
tell_pos_post_read = read_stream.tell();
846846
}
847847
unlink(filename);
848-
let read_str = str::from_utf8_slice(read_mem);
848+
let read_str = str::from_utf8(read_mem);
849849
assert_eq!(read_str, message.slice(4, 8));
850850
assert_eq!(tell_pos_pre_read, set_cursor);
851851
assert_eq!(tell_pos_post_read, message.len() as u64);
@@ -870,7 +870,7 @@ mod test {
870870
read_stream.read(read_mem);
871871
}
872872
unlink(filename);
873-
let read_str = str::from_utf8_slice(read_mem);
873+
let read_str = str::from_utf8(read_mem);
874874
assert!(read_str == final_msg.to_owned());
875875
})
876876

@@ -892,15 +892,15 @@ mod test {
892892

893893
read_stream.seek(-4, SeekEnd);
894894
read_stream.read(read_mem);
895-
assert_eq!(str::from_utf8_slice(read_mem), chunk_three);
895+
assert_eq!(str::from_utf8(read_mem), chunk_three);
896896

897897
read_stream.seek(-9, SeekCur);
898898
read_stream.read(read_mem);
899-
assert_eq!(str::from_utf8_slice(read_mem), chunk_two);
899+
assert_eq!(str::from_utf8(read_mem), chunk_two);
900900

901901
read_stream.seek(0, SeekSet);
902902
read_stream.read(read_mem);
903-
assert_eq!(str::from_utf8_slice(read_mem), chunk_one);
903+
assert_eq!(str::from_utf8(read_mem), chunk_one);
904904
}
905905
unlink(filename);
906906
})
@@ -974,7 +974,7 @@ mod test {
974974
{
975975
let n = f.filestem_str();
976976
File::open(f).read(mem);
977-
let read_str = str::from_utf8_slice(mem);
977+
let read_str = str::from_utf8(mem);
978978
let expected = match n {
979979
None|Some("") => fail!("really shouldn't happen.."),
980980
Some(n) => prefix+n

Diff for: src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ pub trait Buffer: Reader {
10491049
Some(n) if n == width => {}
10501050
Some(..) | None => return None // read error
10511051
}
1052-
match str::from_utf8_slice_opt(buf.slice_to(width)) {
1052+
match str::from_utf8_opt(buf.slice_to(width)) {
10531053
Some(s) => Some(s.char_at(0)),
10541054
None => None
10551055
}

Diff for: src/libstd/path/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
176176
/// If the path is not representable in utf-8, this returns None.
177177
#[inline]
178178
fn as_str<'a>(&'a self) -> Option<&'a str> {
179-
str::from_utf8_slice_opt(self.as_vec())
179+
str::from_utf8_opt(self.as_vec())
180180
}
181181

182182
/// Returns the path as a byte vector
@@ -207,7 +207,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
207207
/// See `dirname` for details.
208208
#[inline]
209209
fn dirname_str<'a>(&'a self) -> Option<&'a str> {
210-
str::from_utf8_slice_opt(self.dirname())
210+
str::from_utf8_opt(self.dirname())
211211
}
212212
/// Returns the file component of `self`, as a byte vector.
213213
/// If `self` represents the root of the file hierarchy, returns None.
@@ -217,7 +217,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
217217
/// See `filename` for details.
218218
#[inline]
219219
fn filename_str<'a>(&'a self) -> Option<&'a str> {
220-
self.filename().and_then(str::from_utf8_slice_opt)
220+
self.filename().and_then(str::from_utf8_opt)
221221
}
222222
/// Returns the stem of the filename of `self`, as a byte vector.
223223
/// The stem is the portion of the filename just before the last '.'.
@@ -239,7 +239,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
239239
/// See `filestem` for details.
240240
#[inline]
241241
fn filestem_str<'a>(&'a self) -> Option<&'a str> {
242-
self.filestem().and_then(str::from_utf8_slice_opt)
242+
self.filestem().and_then(str::from_utf8_opt)
243243
}
244244
/// Returns the extension of the filename of `self`, as an optional byte vector.
245245
/// The extension is the portion of the filename just after the last '.'.
@@ -262,7 +262,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
262262
/// See `extension` for details.
263263
#[inline]
264264
fn extension_str<'a>(&'a self) -> Option<&'a str> {
265-
self.extension().and_then(str::from_utf8_slice_opt)
265+
self.extension().and_then(str::from_utf8_opt)
266266
}
267267

268268
/// Replaces the filename portion of the path with the given byte vector or string.
@@ -493,12 +493,12 @@ pub trait BytesContainer {
493493
/// Raises `str::null_byte` if not utf-8
494494
#[inline]
495495
fn container_as_str<'a>(&'a self) -> &'a str {
496-
str::from_utf8_slice(self.container_as_bytes())
496+
str::from_utf8(self.container_as_bytes())
497497
}
498498
/// Returns the receiver interpreted as a utf-8 string, if possible
499499
#[inline]
500500
fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> {
501-
str::from_utf8_slice_opt(self.container_as_bytes())
501+
str::from_utf8_opt(self.container_as_bytes())
502502
}
503503
/// Returns whether .container_as_str() is guaranteed to not fail
504504
// FIXME (#8888): Remove unused arg once ::<for T> works

0 commit comments

Comments
 (0)