auto merge of #8997 : fhahn/rust/issue_8985, r=catamorphism,brson
Patch for #8985
This commit is contained in:
commit
6f9ce0948a
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
str::raw::from_bytes_owned(v)
|
||||
str::raw::from_utf8_owned(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
*
|
||||
@ -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);
|
||||
* }
|
||||
* ~~~
|
||||
|
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
@ -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]
|
||||
|
@ -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 {
|
||||
|
@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
str::raw::from_bytes_owned(v)
|
||||
str::raw::from_utf8_owned(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
*
|
||||
@ -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);
|
||||
* }
|
||||
* ~~~
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
@ -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
|
||||
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
@ -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))
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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());
|
||||
}
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 --
|
||||
@ -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
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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));
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
|
||||
}
|
||||
|
||||
let mut output = None;
|
||||
let output_text = str::from_bytes(outp.output);
|
||||
let output_text = str::from_utf8(outp.output);
|
||||
for l in output_text.line_iter() {
|
||||
if !l.is_whitespace() {
|
||||
output = Some(l);
|
||||
@ -141,15 +141,15 @@ pub fn try_getting_version(remote_path: &Path) -> 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(outp.output),
|
||||
str::from_utf8(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(outp.output);
|
||||
debug!("Full output: ( %s ) [%?]", output_text, outp.status);
|
||||
for l in output_text.line_iter() {
|
||||
debug!("A line of output: %s", l);
|
||||
|
@ -468,7 +468,7 @@ pub unsafe fn write(output: &mut io::Writer,
|
||||
pub unsafe fn format(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
|
||||
let mut output = MemWriter::new();
|
||||
write(&mut output as &mut io::Writer, fmt, args);
|
||||
return str::from_bytes_owned(output.inner());
|
||||
return str::from_utf8_owned(output.inner());
|
||||
}
|
||||
|
||||
impl<'self> Formatter<'self> {
|
||||
@ -589,7 +589,7 @@ impl<'self> Formatter<'self> {
|
||||
|
||||
fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) {
|
||||
do ::uint::to_str_bytes(value, 10) |buf| {
|
||||
let valuestr = str::from_bytes_slice(buf);
|
||||
let valuestr = str::from_utf8_slice(buf);
|
||||
for piece in pieces.iter() {
|
||||
self.run(piece, Some(valuestr));
|
||||
}
|
||||
|
@ -642,7 +642,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 {
|
||||
@ -651,7 +651,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();
|
||||
@ -701,7 +701,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
|
||||
@ -1761,7 +1761,7 @@ pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
|
||||
}
|
||||
|
||||
pub fn with_str_writer(f: &fn(@Writer)) -> ~str {
|
||||
str::from_bytes(with_bytes_writer(f))
|
||||
str::from_utf8(with_bytes_writer(f))
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
@ -1781,7 +1781,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> {
|
||||
do read_whole_file(file).chain |bytes| {
|
||||
if str::is_utf8(bytes) {
|
||||
Ok(str::from_bytes(bytes))
|
||||
Ok(str::from_utf8(bytes))
|
||||
} else {
|
||||
Err(file.to_str() + " is not UTF-8")
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ impl ToStrRadix for $T {
|
||||
}
|
||||
// We know we generated valid utf-8, so we don't need to go through that
|
||||
// check.
|
||||
unsafe { str::raw::from_bytes_owned(buf) }
|
||||
unsafe { str::raw::from_utf8_owned(buf) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+Round+
|
||||
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
|
||||
let (bytes, special) = float_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,
|
||||
|
@ -396,7 +396,7 @@ impl ToStrRadix for $T {
|
||||
}
|
||||
// We know we generated valid utf-8, so we don't need to go through that
|
||||
// check.
|
||||
unsafe { str::raw::from_bytes_owned(buf) }
|
||||
unsafe { str::raw::from_utf8_owned(buf) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -634,7 +634,7 @@ fn test_repr() {
|
||||
fn exact_test<T>(t: &T, e:&str) {
|
||||
let mut m = io::mem::MemWriter::new();
|
||||
write_repr(&mut m as &mut io::Writer, t);
|
||||
let s = str::from_bytes_owned(m.inner());
|
||||
let s = str::from_utf8_owned(m.inner());
|
||||
assert_eq!(s.as_slice(), e);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ fn file_test_smoke_test_impl() {
|
||||
let mut read_buf = [0, .. 1028];
|
||||
let read_str = match read_stream.read(read_buf).unwrap() {
|
||||
-1|0 => fail!("shouldn't happen"),
|
||||
n => str::from_bytes(read_buf.slice_to(n))
|
||||
n => str::from_utf8(read_buf.slice_to(n))
|
||||
};
|
||||
assert!(read_str == message.to_owned());
|
||||
}
|
||||
@ -230,7 +230,7 @@ fn file_test_io_non_positional_read_impl() {
|
||||
}
|
||||
}
|
||||
unlink(filename);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
assert!(read_str == message.to_owned());
|
||||
}
|
||||
}
|
||||
@ -262,7 +262,7 @@ fn file_test_io_seeking_impl() {
|
||||
tell_pos_post_read = read_stream.tell();
|
||||
}
|
||||
unlink(filename);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
assert!(read_str == message.slice(4, 8).to_owned());
|
||||
assert!(tell_pos_pre_read == set_cursor);
|
||||
assert!(tell_pos_post_read == message.len() as u64);
|
||||
@ -295,7 +295,7 @@ fn file_test_io_seek_and_write_impl() {
|
||||
read_stream.read(read_mem);
|
||||
}
|
||||
unlink(filename);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
io::println(fmt!("read_str: '%?' final_msg: '%?'", read_str, final_msg));
|
||||
assert!(read_str == final_msg.to_owned());
|
||||
}
|
||||
@ -324,17 +324,17 @@ fn file_test_io_seek_shakedown_impl() {
|
||||
|
||||
read_stream.seek(-4, SeekEnd);
|
||||
read_stream.read(read_mem);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
assert!(read_str == chunk_three.to_owned());
|
||||
|
||||
read_stream.seek(-9, SeekCur);
|
||||
read_stream.read(read_mem);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
assert!(read_str == chunk_two.to_owned());
|
||||
|
||||
read_stream.seek(0, SeekSet);
|
||||
read_stream.read(read_mem);
|
||||
let read_str = str::from_bytes(read_mem);
|
||||
let read_str = str::from_utf8(read_mem);
|
||||
assert!(read_str == chunk_one.to_owned());
|
||||
}
|
||||
unlink(filename);
|
||||
|
@ -117,7 +117,7 @@ mod test {
|
||||
let mut out_bytes = [0, .. 100];
|
||||
let bytes_read = inflate_reader.read(out_bytes).unwrap();
|
||||
assert_eq!(bytes_read, in_bytes.len());
|
||||
let out_msg = str::from_bytes(out_bytes);
|
||||
let out_msg = str::from_utf8(out_bytes);
|
||||
assert!(in_msg == out_msg);
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ mod test {
|
||||
if nread > 0 {
|
||||
let read_str = unsafe {
|
||||
let read_buf = *read_buf_ptr;
|
||||
str::from_bytes(
|
||||
str::from_utf8(
|
||||
vec::from_buf(
|
||||
read_buf.base, nread))
|
||||
};
|
||||
@ -393,7 +393,7 @@ mod test {
|
||||
// nread == 0 would be EOF.. we know it's >= zero because otherwise
|
||||
// the above assert would fail
|
||||
if nread > 0 {
|
||||
let read_str = str::from_bytes(
|
||||
let read_str = str::from_utf8(
|
||||
read_mem.slice(0, nread as uint));
|
||||
assert!(read_str == ~"hello");
|
||||
// close
|
||||
|
@ -83,7 +83,7 @@ fn uv_socket_addr_as_socket_addr<T>(addr: UvSocketAddr, f: &fn(SocketAddr) -> T)
|
||||
};
|
||||
port as u16
|
||||
};
|
||||
let ip_str = str::from_bytes_slice(ip_name).trim_right_chars(&'\x00');
|
||||
let ip_str = str::from_utf8_slice(ip_name).trim_right_chars(&'\x00');
|
||||
let ip_addr = FromStr::from_str(ip_str).unwrap();
|
||||
|
||||
// finally run the closure
|
||||
|
@ -1812,7 +1812,7 @@ fn file_test_uvio_full_simple_impl() {
|
||||
let mut fd = (*io).fs_open(&Path(path), ro_fm, ro_fa).unwrap();
|
||||
let mut read_vec = [0, .. 1028];
|
||||
let nread = fd.read(read_vec).unwrap();
|
||||
let read_val = str::from_bytes(read_vec.slice(0, nread as uint));
|
||||
let read_val = str::from_utf8(read_vec.slice(0, nread as uint));
|
||||
assert!(read_val == write_val.to_owned());
|
||||
}
|
||||
(*io).fs_unlink(&Path(path));
|
||||
|
@ -997,7 +997,7 @@ mod tests {
|
||||
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= run::process_output("echo", [~"hello"]);
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1012,7 +1012,7 @@ mod tests {
|
||||
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= run::process_output("/system/bin/sh", [~"-c",~"echo hello"]);
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1091,7 +1091,7 @@ mod tests {
|
||||
let reader = io::FILE_reader(file, false);
|
||||
let buf = reader.read_whole_stream();
|
||||
os::fclose(file);
|
||||
str::from_bytes(buf)
|
||||
str::from_utf8(buf)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1132,7 +1132,7 @@ mod tests {
|
||||
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new());
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= prog.finish_with_output();
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1149,7 +1149,7 @@ mod tests {
|
||||
run::ProcessOptions::new());
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= prog.finish_with_output();
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1167,7 +1167,7 @@ mod tests {
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= prog.finish_with_output();
|
||||
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1195,7 +1195,7 @@ mod tests {
|
||||
let run::ProcessOutput {status, output, error}
|
||||
= prog.finish_with_output();
|
||||
|
||||
let output_str = str::from_bytes(output);
|
||||
let output_str = str::from_utf8(output);
|
||||
|
||||
assert_eq!(status, 0);
|
||||
assert_eq!(output_str.trim().to_owned(), ~"hello");
|
||||
@ -1272,7 +1272,7 @@ mod tests {
|
||||
fn test_keep_current_working_dir() {
|
||||
let mut prog = run_pwd(None);
|
||||
|
||||
let output = str::from_bytes(prog.finish_with_output().output);
|
||||
let output = str::from_utf8(prog.finish_with_output().output);
|
||||
let parent_dir = os::getcwd().normalize();
|
||||
let child_dir = Path(output.trim()).normalize();
|
||||
|
||||
@ -1290,7 +1290,7 @@ mod tests {
|
||||
let parent_dir = os::getcwd().dir_path().normalize();
|
||||
let mut prog = run_pwd(Some(&parent_dir));
|
||||
|
||||
let output = str::from_bytes(prog.finish_with_output().output);
|
||||
let output = str::from_utf8(prog.finish_with_output().output);
|
||||
let child_dir = Path(output.trim()).normalize();
|
||||
|
||||
let parent_stat = parent_dir.stat().unwrap();
|
||||
@ -1329,7 +1329,7 @@ mod tests {
|
||||
if running_on_valgrind() { return; }
|
||||
|
||||
let mut prog = run_env(None);
|
||||
let output = str::from_bytes(prog.finish_with_output().output);
|
||||
let output = str::from_utf8(prog.finish_with_output().output);
|
||||
|
||||
let r = os::env();
|
||||
for &(ref k, ref v) in r.iter() {
|
||||
@ -1343,7 +1343,7 @@ mod tests {
|
||||
if running_on_valgrind() { return; }
|
||||
|
||||
let mut prog = run_env(None);
|
||||
let output = str::from_bytes(prog.finish_with_output().output);
|
||||
let output = str::from_utf8(prog.finish_with_output().output);
|
||||
|
||||
let r = os::env();
|
||||
for &(ref k, ref v) in r.iter() {
|
||||
@ -1362,7 +1362,7 @@ mod tests {
|
||||
new_env.push((~"RUN_TEST_NEW_ENV", ~"123"));
|
||||
|
||||
let mut prog = run_env(Some(new_env));
|
||||
let output = str::from_bytes(prog.finish_with_output().output);
|
||||
let output = str::from_utf8(prog.finish_with_output().output);
|
||||
|
||||
assert!(output.contains("RUN_TEST_NEW_ENV=123"));
|
||||
}
|
||||
|
@ -55,13 +55,13 @@ Section: Creating a string
|
||||
/// # Failure
|
||||
///
|
||||
/// Raises the `not_utf8` condition if invalid UTF-8
|
||||
pub fn from_bytes(vv: &[u8]) -> ~str {
|
||||
pub fn from_utf8(vv: &[u8]) -> ~str {
|
||||
use str::not_utf8::cond;
|
||||
|
||||
match from_bytes_opt(vv) {
|
||||
match from_utf8_opt(vv) {
|
||||
None => {
|
||||
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
|
||||
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
|
||||
cond.raise(fmt!("from_utf8: input is not UTF-8; first bad byte is %u",
|
||||
first_bad_byte as uint))
|
||||
}
|
||||
Some(s) => s
|
||||
@ -70,9 +70,9 @@ pub fn from_bytes(vv: &[u8]) -> ~str {
|
||||
|
||||
/// Convert a vector of bytes to a new UTF-8 string, if possible.
|
||||
/// Returns None if the vector contains invalid UTF-8.
|
||||
pub fn from_bytes_opt(vv: &[u8]) -> Option<~str> {
|
||||
pub fn from_utf8_opt(vv: &[u8]) -> Option<~str> {
|
||||
if is_utf8(vv) {
|
||||
Some(unsafe { raw::from_bytes(vv) })
|
||||
Some(unsafe { raw::from_utf8(vv) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -83,23 +83,23 @@ pub fn from_bytes_opt(vv: &[u8]) -> Option<~str> {
|
||||
/// # Failure
|
||||
///
|
||||
/// Raises the `not_utf8` condition if invalid UTF-8
|
||||
pub fn from_bytes_owned(vv: ~[u8]) -> ~str {
|
||||
pub fn from_utf8_owned(vv: ~[u8]) -> ~str {
|
||||
use str::not_utf8::cond;
|
||||
|
||||
if !is_utf8(vv) {
|
||||
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
|
||||
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
|
||||
cond.raise(fmt!("from_utf8: input is not UTF-8; first bad byte is %u",
|
||||
first_bad_byte as uint))
|
||||
} else {
|
||||
unsafe { raw::from_bytes_owned(vv) }
|
||||
unsafe { raw::from_utf8_owned(vv) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes a vector of bytes to create a new utf-8 string.
|
||||
/// Returns None if the vector contains invalid UTF-8.
|
||||
pub fn from_bytes_owned_opt(vv: ~[u8]) -> Option<~str> {
|
||||
pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> {
|
||||
if is_utf8(vv) {
|
||||
Some(unsafe { raw::from_bytes_owned(vv) })
|
||||
Some(unsafe { raw::from_utf8_owned(vv) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -113,14 +113,14 @@ pub fn from_bytes_owned_opt(vv: ~[u8]) -> Option<~str> {
|
||||
/// # Failure
|
||||
///
|
||||
/// Fails if invalid UTF-8
|
||||
pub fn from_bytes_slice<'a>(v: &'a [u8]) -> &'a str {
|
||||
from_bytes_slice_opt(v).expect("from_bytes_slice: not utf-8")
|
||||
pub fn from_utf8_slice<'a>(v: &'a [u8]) -> &'a str {
|
||||
from_utf8_slice_opt(v).expect("from_utf8_slice: not utf-8")
|
||||
}
|
||||
|
||||
/// Converts a vector to a string slice without performing any allocations.
|
||||
///
|
||||
/// Returns None if the slice is not utf-8.
|
||||
pub fn from_bytes_slice_opt<'a>(v: &'a [u8]) -> Option<&'a str> {
|
||||
pub fn from_utf8_slice_opt<'a>(v: &'a [u8]) -> Option<&'a str> {
|
||||
if is_utf8(v) {
|
||||
Some(unsafe { cast::transmute(v) })
|
||||
} else { None }
|
||||
@ -1000,7 +1000,7 @@ pub mod raw {
|
||||
}
|
||||
|
||||
/// Converts a vector of bytes to a new owned string.
|
||||
pub unsafe fn from_bytes(v: &[u8]) -> ~str {
|
||||
pub unsafe fn from_utf8(v: &[u8]) -> ~str {
|
||||
do v.as_imm_buf |buf, len| {
|
||||
from_buf_len(buf, len)
|
||||
}
|
||||
@ -1009,12 +1009,12 @@ pub mod raw {
|
||||
/// Converts an owned vector of bytes to a new owned string. This assumes
|
||||
/// that the utf-8-ness of the vector has already been validated
|
||||
#[inline]
|
||||
pub unsafe fn from_bytes_owned(v: ~[u8]) -> ~str {
|
||||
pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str {
|
||||
cast::transmute(v)
|
||||
}
|
||||
|
||||
/// Converts a byte to a string.
|
||||
pub unsafe fn from_byte(u: u8) -> ~str { from_bytes([u]) }
|
||||
pub unsafe fn from_byte(u: u8) -> ~str { from_utf8([u]) }
|
||||
|
||||
/// Form a slice from a C string. Unsafe because the caller must ensure the
|
||||
/// C string has the static lifetime, or else the return value may be
|
||||
@ -2975,14 +2975,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unsafe_from_bytes() {
|
||||
fn test_unsafe_from_utf8() {
|
||||
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8];
|
||||
let b = unsafe { raw::from_bytes(a) };
|
||||
let b = unsafe { raw::from_utf8(a) };
|
||||
assert_eq!(b, ~"AAAAAAA");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_bytes() {
|
||||
fn test_from_utf8() {
|
||||
let ss = ~"ศไทย中华Việt Nam";
|
||||
let bb = ~[0xe0_u8, 0xb8_u8, 0xa8_u8,
|
||||
0xe0_u8, 0xb9_u8, 0x84_u8,
|
||||
@ -2996,9 +2996,9 @@ mod tests {
|
||||
0x6d_u8];
|
||||
|
||||
|
||||
assert_eq!(ss, from_bytes(bb));
|
||||
assert_eq!(ss, from_utf8(bb));
|
||||
assert_eq!(~"𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰",
|
||||
from_bytes(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰")));
|
||||
from_utf8(bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -3028,7 +3028,7 @@ mod tests {
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_from_bytes_fail() {
|
||||
fn test_from_utf8_fail() {
|
||||
use str::not_utf8::cond;
|
||||
|
||||
let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8,
|
||||
@ -3044,11 +3044,11 @@ mod tests {
|
||||
|
||||
let mut error_happened = false;
|
||||
let _x = do cond.trap(|err| {
|
||||
assert_eq!(err, ~"from_bytes: input is not UTF-8; first bad byte is 255");
|
||||
assert_eq!(err, ~"from_utf8: input is not UTF-8; first bad byte is 255");
|
||||
error_happened = true;
|
||||
~""
|
||||
}).inside {
|
||||
from_bytes(bb)
|
||||
from_utf8(bb)
|
||||
};
|
||||
assert!(error_happened);
|
||||
}
|
||||
@ -3133,7 +3133,7 @@ mod tests {
|
||||
let s1: ~str = ~"All mimsy were the borogoves";
|
||||
|
||||
let v: ~[u8] = s1.as_bytes().to_owned();
|
||||
let s2: ~str = from_bytes(v);
|
||||
let s2: ~str = from_utf8(v);
|
||||
let mut i: uint = 0u;
|
||||
let n1: uint = s1.len();
|
||||
let n2: uint = v.len();
|
||||
@ -3656,73 +3656,73 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes_slice() {
|
||||
fn test_str_from_utf8_slice() {
|
||||
let xs = bytes!("hello");
|
||||
assert_eq!(from_bytes_slice(xs), "hello");
|
||||
assert_eq!(from_utf8_slice(xs), "hello");
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam");
|
||||
assert_eq!(from_bytes_slice(xs), "ศไทย中华Việt Nam");
|
||||
assert_eq!(from_utf8_slice(xs), "ศไทย中华Việt Nam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn test_str_from_bytes_slice_invalid() {
|
||||
fn test_str_from_utf8_slice_invalid() {
|
||||
let xs = bytes!("hello", 0xff);
|
||||
let _ = from_bytes_slice(xs);
|
||||
let _ = from_utf8_slice(xs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes_slice_opt() {
|
||||
fn test_str_from_utf8_slice_opt() {
|
||||
let xs = bytes!("hello");
|
||||
assert_eq!(from_bytes_slice_opt(xs), Some("hello"));
|
||||
assert_eq!(from_utf8_slice_opt(xs), Some("hello"));
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam");
|
||||
assert_eq!(from_bytes_slice_opt(xs), Some("ศไทย中华Việt Nam"));
|
||||
assert_eq!(from_utf8_slice_opt(xs), Some("ศไทย中华Việt Nam"));
|
||||
|
||||
let xs = bytes!("hello", 0xff);
|
||||
assert_eq!(from_bytes_slice_opt(xs), None);
|
||||
assert_eq!(from_utf8_slice_opt(xs), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes() {
|
||||
fn test_str_from_utf8() {
|
||||
let xs = bytes!("hello");
|
||||
assert_eq!(from_bytes(xs), ~"hello");
|
||||
assert_eq!(from_utf8(xs), ~"hello");
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam");
|
||||
assert_eq!(from_bytes(xs), ~"ศไทย中华Việt Nam");
|
||||
assert_eq!(from_utf8(xs), ~"ศไทย中华Việt Nam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes_opt() {
|
||||
fn test_str_from_utf8_opt() {
|
||||
let xs = bytes!("hello").to_owned();
|
||||
assert_eq!(from_bytes_opt(xs), Some(~"hello"));
|
||||
assert_eq!(from_utf8_opt(xs), Some(~"hello"));
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam");
|
||||
assert_eq!(from_bytes_opt(xs), Some(~"ศไทย中华Việt Nam"));
|
||||
assert_eq!(from_utf8_opt(xs), Some(~"ศไทย中华Việt Nam"));
|
||||
|
||||
let xs = bytes!("hello", 0xff);
|
||||
assert_eq!(from_bytes_opt(xs), None);
|
||||
assert_eq!(from_utf8_opt(xs), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes_owned() {
|
||||
fn test_str_from_utf8_owned() {
|
||||
let xs = bytes!("hello").to_owned();
|
||||
assert_eq!(from_bytes_owned(xs), ~"hello");
|
||||
assert_eq!(from_utf8_owned(xs), ~"hello");
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam").to_owned();
|
||||
assert_eq!(from_bytes_owned(xs), ~"ศไทย中华Việt Nam");
|
||||
assert_eq!(from_utf8_owned(xs), ~"ศไทย中华Việt Nam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_from_bytes_owned_opt() {
|
||||
fn test_str_from_utf8_owned_opt() {
|
||||
let xs = bytes!("hello").to_owned();
|
||||
assert_eq!(from_bytes_owned_opt(xs), Some(~"hello"));
|
||||
assert_eq!(from_utf8_owned_opt(xs), Some(~"hello"));
|
||||
|
||||
let xs = bytes!("ศไทย中华Việt Nam").to_owned();
|
||||
assert_eq!(from_bytes_owned_opt(xs), Some(~"ศไทย中华Việt Nam"));
|
||||
assert_eq!(from_utf8_owned_opt(xs), Some(~"ศไทย中华Việt Nam"));
|
||||
|
||||
let xs = bytes!("hello", 0xff).to_owned();
|
||||
assert_eq!(from_bytes_owned_opt(xs), None);
|
||||
assert_eq!(from_utf8_owned_opt(xs), None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ pub fn log_str<T>(t: &T) -> ~str {
|
||||
|
||||
let mut result = io::mem::MemWriter::new();
|
||||
repr::write_repr(&mut result as &mut io::Writer, t);
|
||||
str::from_bytes_owned(result.inner())
|
||||
str::from_utf8_owned(result.inner())
|
||||
}
|
||||
#[cfg(stage0)]
|
||||
pub fn log_str<T>(t: &T) -> ~str {
|
||||
|
@ -338,7 +338,7 @@ pub fn gather_comments_and_literals(span_diagnostic:
|
||||
path: @str,
|
||||
srdr: @io::Reader)
|
||||
-> (~[cmnt], ~[lit]) {
|
||||
let src = str::from_bytes(srdr.read_whole_stream()).to_managed();
|
||||
let src = str::from_utf8(srdr.read_whole_stream()).to_managed();
|
||||
let cm = CodeMap::new();
|
||||
let filemap = cm.new_filemap(path, src);
|
||||
let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);
|
||||
|
@ -72,7 +72,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
|
||||
for kv in pairs_sorted.iter() {
|
||||
let (k,v) = (*kv).clone();
|
||||
unsafe {
|
||||
let b = str::raw::from_bytes(k);
|
||||
let b = str::raw::from_utf8(k);
|
||||
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
|
||||
// to_ascii_move and to_str_move to not do a unnecessary copy.
|
||||
buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v));
|
||||
|
@ -60,7 +60,7 @@ impl Code {
|
||||
}
|
||||
|
||||
reverse(result);
|
||||
str::from_bytes(result)
|
||||
str::from_utf8(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,13 @@ static C: *u8 = B as *u8;
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let foo = &A as *u8;
|
||||
assert_eq!(str::raw::from_bytes(A), ~"hi");
|
||||
assert_eq!(str::raw::from_utf8(A), ~"hi");
|
||||
assert_eq!(str::raw::from_buf_len(foo, A.len()), ~"hi");
|
||||
assert_eq!(str::raw::from_buf_len(C, B.len()), ~"hi");
|
||||
assert!(*C == A[0]);
|
||||
assert!(*(&B[0] as *u8) == A[0]);
|
||||
|
||||
let bar = str::raw::from_bytes(A).to_c_str();
|
||||
let bar = str::raw::from_utf8(A).to_c_str();
|
||||
assert_eq!(bar.with_ref(|buf| str::raw::from_c_str(buf)), ~"hi");
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +44,13 @@ fn test_destroy_actually_kills(force: bool) {
|
||||
#[cfg(unix,not(target_os="android"))]
|
||||
fn process_exists(pid: libc::pid_t) -> bool {
|
||||
let run::ProcessOutput {output, _} = run::process_output("ps", [~"-p", pid.to_str()]);
|
||||
str::from_bytes(output).contains(pid.to_str())
|
||||
str::from_utf8(output).contains(pid.to_str())
|
||||
}
|
||||
|
||||
#[cfg(unix,target_os="android")]
|
||||
fn process_exists(pid: libc::pid_t) -> bool {
|
||||
let run::ProcessOutput {output, _} = run::process_output("/system/bin/ps", [pid.to_str()]);
|
||||
str::from_bytes(output).contains(~"root")
|
||||
str::from_utf8(output).contains(~"root")
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
@ -80,7 +80,7 @@ mod map_reduce {
|
||||
mapper_done => { num_mappers -= 1; }
|
||||
find_reducer(k, cc) => {
|
||||
let mut c;
|
||||
match reducers.find(&str::from_bytes(k)) {
|
||||
match reducers.find(&str::from_utf8(k)) {
|
||||
Some(&_c) => { c = _c; }
|
||||
None => { c = 0; }
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ fn test_write() {
|
||||
writeln!(w, "{foo}", foo="bar");
|
||||
}
|
||||
|
||||
let s = str::from_bytes_owned(buf.inner());
|
||||
let s = str::from_utf8_owned(buf.inner());
|
||||
t!(s, "34helloline\nbar\n");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user