Convert all uses of unsafe_from_bytes to unsafe_from_bytes_ivec

This commit is contained in:
Brian Anderson 2011-08-11 17:02:13 -07:00
parent 49b80f9bf7
commit a9ce342fa3
11 changed files with 27 additions and 31 deletions

View File

@ -311,8 +311,8 @@ fn sanitize(s: &str) -> str {
if c != 10u8 && c != '}' as u8 && c != ')' as u8 &&
c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
{
let v = [c];
result += str::unsafe_from_bytes(v);
let v = ~[c];
result += str::unsafe_from_bytes_ivec(v);
}
}
}

View File

@ -177,11 +177,11 @@ fn scan_exponent(rdr: &reader) -> option::t[str] {
let c = rdr.curr();
let rslt = "";
if c == 'e' || c == 'E' {
rslt += str::unsafe_from_bytes([c as u8]);
rslt += str::unsafe_from_bytes_ivec(~[c as u8]);
rdr.bump();
c = rdr.curr();
if c == '-' || c == '+' {
rslt += str::unsafe_from_bytes([c as u8]);
rslt += str::unsafe_from_bytes_ivec(~[c as u8]);
rdr.bump();
}
let exponent = scan_dec_digits(rdr);
@ -195,7 +195,7 @@ fn scan_dec_digits(rdr: &reader) -> str {
let c = rdr.curr();
let rslt: str = "";
while is_dec_digit(c) || c == '_' {
if c != '_' { rslt += str::unsafe_from_bytes([c as u8]); }
if c != '_' { rslt += str::unsafe_from_bytes_ivec(~[c as u8]); }
rdr.bump();
c = rdr.curr();
}

View File

@ -1385,8 +1385,8 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
print_string(s, st);
}
ast::lit_char(ch) {
word(s.s, "'" +
escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + "'");
word(s.s, "'" + escape_str(
str::unsafe_from_bytes_ivec(~[ch as u8]), '\'') + "'");
}
ast::lit_int(val) { word(s.s, int::str(val)); }
ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); }

View File

@ -132,7 +132,7 @@ fn mt_to_str(cx: &ctxt, m: &mt) -> str {
}
ty_var(v) { s += "<T" + int::str(v) + ">"; }
ty_param(id,_) {
s += "'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)]);
s += "'" + str::unsafe_from_bytes_ivec(~[('a' as u8) + (id as u8)]);
}
_ { s += ty_to_short_str(cx, typ); }
}

View File

@ -356,9 +356,9 @@ fn get_int_precision(cv: &conv) -> uint {
// FIXME: This might be useful in str: but needs to be utf8 safe first
fn str_init_elt(c: char, n_elts: uint) -> str {
let svec = vec::init_elt[u8](c as u8, n_elts);
let svec = ivec::from_vec(vec::init_elt[u8](c as u8, n_elts));
ret str::unsafe_from_bytes(svec);
ret str::unsafe_from_bytes_ivec((svec));
}
tag pad_mode { pad_signed; pad_unsigned; pad_nozero; }
fn pad(cv: &conv, s: str, mode: pad_mode) -> str {
@ -407,7 +407,7 @@ fn have_precision(cv: &conv) -> bool {
if signed && zero_padding && str::byte_len(s) > 0u {
let head = s.(0);
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
let headstr = str::unsafe_from_bytes([head]);
let headstr = str::unsafe_from_bytes_ivec(~[head]);
let bytelen = str::byte_len(s);
let numpart = str::substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart;

View File

@ -120,7 +120,7 @@ fn read_line() -> str {
go_on = false;
} else { vec::push[u8](buf, ch as u8); }
}
ret str::unsafe_from_bytes(buf);
ret str::unsafe_from_bytes_ivec(ivec::from_vec(buf));
}
fn read_c_str() -> str {
let buf: vec[u8] = [];
@ -131,7 +131,7 @@ fn read_c_str() -> str {
go_on = false;
} else { vec::push[u8](buf, ch as u8); }
}
ret str::unsafe_from_bytes(buf);
ret str::unsafe_from_bytes_ivec(ivec::from_vec(buf));
}
// FIXME deal with eof?
@ -440,7 +440,9 @@ fn string_writer() -> str_writer {
let buf: mutable_byte_buf = @{mutable buf: b, mutable pos: 0u};
obj str_writer_wrap(wr: writer, buf: mutable_byte_buf) {
fn get_writer() -> writer { ret wr; }
fn get_str() -> str { ret str::unsafe_from_bytes(buf.buf); }
fn get_str() -> str {
ret str::unsafe_from_bytes_ivec(ivec::from_vec(buf.buf));
}
}
ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
}

View File

@ -17,7 +17,7 @@ fn ivec_copy_from_buf_shared[T](v: &mutable [mutable? T], ptr: *T,
count: uint);
}
fn from_vec[@T](v: &vec[T]) -> [T] {
fn from_vec[@T](v: &vec[mutable? T]) -> [T] {
let iv = ~[];
for e in v {
iv += ~[e];

View File

@ -103,8 +103,8 @@ fn destroy() {
fn read_all(rd: &io::reader) -> str {
let buf = "";
while !rd.eof() {
let bytes = rd.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes);
let bytes = ivec::from_vec(rd.read_bytes(4096u));
buf += str::unsafe_from_bytes_ivec(bytes);
}
ret buf;
}

View File

@ -87,8 +87,8 @@ fn readclose(fd: int) -> str {
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
let buf = "";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes);
let bytes = ivec::from_vec(reader.read_bytes(4096u));
buf += str::unsafe_from_bytes_ivec(bytes);
}
os::libc::fclose(file);
ret buf;

View File

@ -4,6 +4,7 @@
import std::io;
import std::option;
import std::str;
import std::ivec;
// Regression test for memory leaks
#[cfg(target_os = "linux")]
@ -58,8 +59,8 @@ fn readclose(fd: int) -> str {
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
let buf = "";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes);
let bytes = ivec::from_vec(reader.read_bytes(4096u));
buf += str::unsafe_from_bytes_ivec(bytes);
}
os::libc::fclose(file);
ret buf;

View File

@ -3,24 +3,17 @@
// -*- rust -*-
use std;
import std::str;
import std::vec;
import std::ivec;
#[test]
fn test_simple() {
let s1: str = "All mimsy were the borogoves";
/*
* FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is
* unimplemented and thereby just fails. This doesn't stop us from
* using from_bytes for now since the constraint system isn't fully
* working, but we should implement is_utf8 before that happens.
*/
let v: vec[u8] = ivec::to_vec(str::bytes(s1));
let s2: str = str::unsafe_from_bytes(v);
let v: [u8] = str::bytes(s1);
let s2: str = str::unsafe_from_bytes_ivec(v);
let i: uint = 0u;
let n1: uint = str::byte_len(s1);
let n2: uint = vec::len[u8](v);
let n2: uint = ivec::len[u8](v);
assert (n1 == n2);
while i < n1 {
let a: u8 = s1.(i);