Skip to content

Commit de39874

Browse files
committed
Rename str::from_bytes to str::from_utf8, closes #8985
1 parent 422dcbd commit de39874

38 files changed

+147
-147
lines changed

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn run(lib_path: &str,
6363

6464
Result {
6565
status: output.status,
66-
out: str::from_bytes(output.output),
67-
err: str::from_bytes(output.error)
66+
out: str::from_utf8(output.output),
67+
err: str::from_utf8(output.error)
6868
}
6969
}

src/libextra/base64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'self> ToBase64 for &'self [u8] {
145145
}
146146

147147
unsafe {
148-
str::raw::from_bytes_owned(v)
148+
str::raw::from_utf8_owned(v)
149149
}
150150
}
151151
}
@@ -162,7 +162,7 @@ impl<'self> FromBase64 for &'self str {
162162
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
163163
* to the byte values it encodes.
164164
*
165-
* You can use the `from_bytes` function in `std::str`
165+
* You can use the `from_utf8` function in `std::str`
166166
* to turn a `[u8]` into a string with characters corresponding to those
167167
* values.
168168
*
@@ -180,7 +180,7 @@ impl<'self> FromBase64 for &'self str {
180180
* printfln!("%s", hello_str);
181181
* let bytes = hello_str.from_base64();
182182
* printfln!("%?", bytes);
183-
* let result_str = str::from_bytes(bytes);
183+
* let result_str = str::from_utf8(bytes);
184184
* printfln!("%s", result_str);
185185
* }
186186
* ~~~

src/libextra/bitv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl Bitv {
523523
* with the most significant bits of each byte coming first. Each
524524
* bit becomes true if equal to 1 or false if equal to 0.
525525
*/
526-
pub fn from_bytes(bytes: &[u8]) -> Bitv {
526+
pub fn from_utf8(bytes: &[u8]) -> Bitv {
527527
from_fn(bytes.len() * 8, |i| {
528528
let b = bytes[i / 8] as uint;
529529
let offset = i % 8;
@@ -1275,8 +1275,8 @@ mod tests {
12751275
}
12761276
12771277
#[test]
1278-
fn test_from_bytes() {
1279-
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
1278+
fn test_from_utf8() {
1279+
let bitv = from_utf8([0b10110110, 0b00000000, 0b11111111]);
12801280
let str = ~"10110110" + "00000000" + "11111111";
12811281
assert_eq!(bitv.to_str(), str);
12821282
}
@@ -1302,7 +1302,7 @@ mod tests {
13021302
#[test]
13031303
fn test_to_bools() {
13041304
let bools = ~[false, false, true, false, false, true, true, false];
1305-
assert_eq!(from_bytes([0b00100110]).to_bools(), bools);
1305+
assert_eq!(from_utf8([0b00100110]).to_bools(), bools);
13061306
}
13071307
13081308
#[test]

src/libextra/ebml.rs

Lines changed: 1 addition & 1 deletion
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_bytes_slice(self.data.slice(self.start, self.end))
44+
str::from_utf8_slice(self.data.slice(self.start, self.end))
4545
}
4646

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

src/libextra/hex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'self> ToHex for &'self [u8] {
4545
}
4646

4747
unsafe {
48-
str::raw::from_bytes_owned(v)
48+
str::raw::from_utf8_owned(v)
4949
}
5050
}
5151
}
@@ -62,7 +62,7 @@ impl<'self> FromHex for &'self str {
6262
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
6363
* to the byte values it encodes.
6464
*
65-
* You can use the `from_bytes` function in `std::str`
65+
* You can use the `from_utf8` function in `std::str`
6666
* to turn a `[u8]` into a string with characters corresponding to those
6767
* values.
6868
*
@@ -80,7 +80,7 @@ impl<'self> FromHex for &'self str {
8080
* printfln!("%s", hello_str);
8181
* let bytes = hello_str.from_hex().unwrap();
8282
* printfln!("%?", bytes);
83-
* let result_str = str::from_bytes(bytes);
83+
* let result_str = str::from_utf8(bytes);
8484
* printfln!("%s", result_str);
8585
* }
8686
* ~~~

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ impl<T : iterator::Iterator<char>> Parser<T> {
858858

859859
/// Decodes a json value from an @io::Reader
860860
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
861-
let s = str::from_bytes(rdr.read_whole_stream());
861+
let s = str::from_utf8(rdr.read_whole_stream());
862862
let mut parser = Parser(~s.iter());
863863
parser.parse()
864864
}

src/libextra/terminfo/parser/compiled.rs

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

216-
let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
216+
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
217217
let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect();
218218

219219
file.read_byte(); // consume NUL

src/libextra/uuid.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Uuid {
210210
///
211211
/// # Arguments
212212
/// * `b` An array or slice of 16 bytes
213-
pub fn from_bytes(b: &[u8]) -> Option<Uuid> {
213+
pub fn from_utf8(b: &[u8]) -> Option<Uuid> {
214214
if b.len() != 16 {
215215
return None
216216
}
@@ -307,7 +307,7 @@ impl Uuid {
307307
s[i*2+0] = digit[0];
308308
s[i*2+1] = digit[1];
309309
}
310-
str::from_bytes(s)
310+
str::from_utf8(s)
311311
}
312312

313313
/// Returns a string of hexadecimal digits, separated into groups with a hypen
@@ -413,7 +413,7 @@ impl Uuid {
413413
ub[i] = FromStrRadix::from_str_radix(vs.slice(i*2, (i+1)*2), 16).unwrap();
414414
}
415415

416-
Ok(Uuid::from_bytes(ub).unwrap())
416+
Ok(Uuid::from_utf8(ub).unwrap())
417417
}
418418
}
419419

@@ -705,11 +705,11 @@ mod test {
705705
}
706706

707707
#[test]
708-
fn test_from_bytes() {
708+
fn test_from_utf8() {
709709
let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
710710
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
711711

712-
let u = Uuid::from_bytes(b).unwrap();
712+
let u = Uuid::from_utf8(b).unwrap();
713713
let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8";
714714

715715
assert!(u.to_simple_str() == expected);
@@ -729,7 +729,7 @@ mod test {
729729
let b_in: [u8, ..16] = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2,
730730
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ];
731731

732-
let u = Uuid::from_bytes(b_in.clone()).unwrap();
732+
let u = Uuid::from_utf8(b_in.clone()).unwrap();
733733

734734
let b_out = u.to_bytes();
735735

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub mod write {
386386
cc_prog, prog.status));
387387
sess.note(fmt!("%s arguments: %s",
388388
cc_prog, cc_args.connect(" ")));
389-
sess.note(str::from_bytes(prog.error + prog.output));
389+
sess.note(str::from_utf8(prog.error + prog.output));
390390
sess.abort_if_errors();
391391
}
392392
}
@@ -943,7 +943,7 @@ pub fn link_binary(sess: Session,
943943
cc_prog, prog.status));
944944
sess.note(fmt!("%s arguments: %s",
945945
cc_prog, cc_args.connect(" ")));
946-
sess.note(str::from_bytes(prog.error + prog.output));
946+
sess.note(str::from_utf8(prog.error + prog.output));
947947
sess.abort_if_errors();
948948
}
949949

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ fn read_path(d: ebml::Doc) -> (~str, uint) {
12391239
do reader::with_doc_data(d) |desc| {
12401240
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
12411241
let pathbytes = desc.slice(4u, desc.len());
1242-
let path = str::from_bytes(pathbytes);
1242+
let path = str::from_utf8(pathbytes);
12431243

12441244
(path, pos)
12451245
}

0 commit comments

Comments
 (0)