diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-11-28 23:52:11 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-04 22:35:53 +1100 |
| commit | 9d64e46013096997627da62ecc65225bc22682e8 (patch) | |
| tree | fa20c8fd1d653acff5f996253d16103dd61addd9 /src/libextra | |
| parent | 9635c763ba5edc8c8ea2868b895548b52f640e5a (diff) | |
| download | rust-9d64e46013096997627da62ecc65225bc22682e8.tar.gz rust-9d64e46013096997627da62ecc65225bc22682e8.zip | |
std::str: remove from_utf8.
This function had type &[u8] -> ~str, i.e. it allocates a string internally, even though the non-allocating version that take &[u8] -> &str and ~[u8] -> ~str are all that is necessary in most circumstances.
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/base64.rs | 4 | ||||
| -rw-r--r-- | src/libextra/hex.rs | 4 | ||||
| -rw-r--r-- | src/libextra/terminfo/parser/compiled.rs | 4 | ||||
| -rw-r--r-- | src/libextra/test.rs | 2 | ||||
| -rw-r--r-- | src/libextra/uuid.rs | 2 | ||||
| -rw-r--r-- | src/libextra/workcache.rs | 2 |
6 files changed, 10 insertions, 8 deletions
diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index 94e3917a7ec..c4247799cad 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -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_utf8` function in `std::str` + * You can use the `from_utf8_owned` 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 { * println!("base64 output: {}", hello_str); * let res = hello_str.from_base64(); * if res.is_ok() { - * let optBytes = str::from_utf8_opt(res.unwrap()); + * let optBytes = str::from_utf8_owned_opt(res.unwrap()); * if optBytes.is_some() { * println!("decoded from base64: {}", optBytes.unwrap()); * } diff --git a/src/libextra/hex.rs b/src/libextra/hex.rs index 5a1d1308f8c..7daba4c08f2 100644 --- a/src/libextra/hex.rs +++ b/src/libextra/hex.rs @@ -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_utf8` function in `std::str` + * You can use the `from_utf8_owned` 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 { * println!("{}", hello_str); * let bytes = hello_str.from_hex().unwrap(); * println!("{:?}", bytes); - * let result_str = str::from_utf8(bytes); + * let result_str = str::from_utf8_owned(bytes); * println!("{}", result_str); * } * ``` diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index af1532db935..bc997c5147d 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -215,7 +215,9 @@ pub fn parse(file: &mut io::Reader, return Err(~"incompatible file: more string offsets than expected"); } - let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL + // don't read NUL + let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1)); + let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect(); file.read_byte(); // consume NUL diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 93ffb8f9fde..693f4532a43 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -701,7 +701,7 @@ fn should_sort_failures_before_printing_them() { st.write_failures(); let s = match st.out { - Right(ref m) => str::from_utf8(*m.inner_ref()), + Right(ref m) => str::from_utf8_slice(*m.inner_ref()), Left(_) => unreachable!() }; diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs index d40eef732f1..0fbac7771dc 100644 --- a/src/libextra/uuid.rs +++ b/src/libextra/uuid.rs @@ -310,7 +310,7 @@ impl Uuid { s[i*2+0] = digit[0]; s[i*2+1] = digit[1]; } - str::from_utf8(s) + str::from_utf8_owned(s) } /// Returns a string of hexadecimal digits, separated into groups with a hypen diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index ab36defe522..d906896ff60 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -260,7 +260,7 @@ fn json_encode<'self, T:Encodable<json::Encoder<'self>>>(t: &T) -> ~str { let mut writer = MemWriter::new(); let mut encoder = json::Encoder::init(&mut writer as &mut io::Writer); t.encode(&mut encoder); - str::from_utf8(writer.inner_ref().as_slice()) + str::from_utf8_owned(writer.inner()) } // FIXME(#5121) |
