Convert all uses of unsafe_from_bytes to unsafe_from_bytes_ivec
This commit is contained in:
@@ -311,8 +311,8 @@ fn sanitize(s: &str) -> str {
|
|||||||
if c != 10u8 && c != '}' as u8 && c != ')' as u8 &&
|
if c != 10u8 && c != '}' as u8 && c != ')' as u8 &&
|
||||||
c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
|
c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
|
||||||
{
|
{
|
||||||
let v = [c];
|
let v = ~[c];
|
||||||
result += str::unsafe_from_bytes(v);
|
result += str::unsafe_from_bytes_ivec(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,11 +177,11 @@ fn scan_exponent(rdr: &reader) -> option::t[str] {
|
|||||||
let c = rdr.curr();
|
let c = rdr.curr();
|
||||||
let rslt = "";
|
let rslt = "";
|
||||||
if c == 'e' || c == 'E' {
|
if c == 'e' || c == 'E' {
|
||||||
rslt += str::unsafe_from_bytes([c as u8]);
|
rslt += str::unsafe_from_bytes_ivec(~[c as u8]);
|
||||||
rdr.bump();
|
rdr.bump();
|
||||||
c = rdr.curr();
|
c = rdr.curr();
|
||||||
if c == '-' || c == '+' {
|
if c == '-' || c == '+' {
|
||||||
rslt += str::unsafe_from_bytes([c as u8]);
|
rslt += str::unsafe_from_bytes_ivec(~[c as u8]);
|
||||||
rdr.bump();
|
rdr.bump();
|
||||||
}
|
}
|
||||||
let exponent = scan_dec_digits(rdr);
|
let exponent = scan_dec_digits(rdr);
|
||||||
@@ -195,7 +195,7 @@ fn scan_dec_digits(rdr: &reader) -> str {
|
|||||||
let c = rdr.curr();
|
let c = rdr.curr();
|
||||||
let rslt: str = "";
|
let rslt: str = "";
|
||||||
while is_dec_digit(c) || c == '_' {
|
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();
|
rdr.bump();
|
||||||
c = rdr.curr();
|
c = rdr.curr();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1385,8 +1385,8 @@ fn print_literal(s: &ps, lit: &@ast::lit) {
|
|||||||
print_string(s, st);
|
print_string(s, st);
|
||||||
}
|
}
|
||||||
ast::lit_char(ch) {
|
ast::lit_char(ch) {
|
||||||
word(s.s, "'" +
|
word(s.s, "'" + escape_str(
|
||||||
escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + "'");
|
str::unsafe_from_bytes_ivec(~[ch as u8]), '\'') + "'");
|
||||||
}
|
}
|
||||||
ast::lit_int(val) { word(s.s, int::str(val)); }
|
ast::lit_int(val) { word(s.s, int::str(val)); }
|
||||||
ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); }
|
ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); }
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
|||||||
}
|
}
|
||||||
ty_var(v) { s += "<T" + int::str(v) + ">"; }
|
ty_var(v) { s += "<T" + int::str(v) + ">"; }
|
||||||
ty_param(id,_) {
|
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); }
|
_ { s += ty_to_short_str(cx, typ); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,9 +356,9 @@ mod rt {
|
|||||||
|
|
||||||
// FIXME: This might be useful in str: but needs to be utf8 safe first
|
// FIXME: This might be useful in str: but needs to be utf8 safe first
|
||||||
fn str_init_elt(c: char, n_elts: uint) -> str {
|
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; }
|
tag pad_mode { pad_signed; pad_unsigned; pad_nozero; }
|
||||||
fn pad(cv: &conv, s: str, mode: pad_mode) -> str {
|
fn pad(cv: &conv, s: str, mode: pad_mode) -> str {
|
||||||
@@ -407,7 +407,7 @@ mod rt {
|
|||||||
if signed && zero_padding && str::byte_len(s) > 0u {
|
if signed && zero_padding && str::byte_len(s) > 0u {
|
||||||
let head = s.(0);
|
let head = s.(0);
|
||||||
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
|
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 bytelen = str::byte_len(s);
|
||||||
let numpart = str::substr(s, 1u, bytelen - 1u);
|
let numpart = str::substr(s, 1u, bytelen - 1u);
|
||||||
ret headstr + padstr + numpart;
|
ret headstr + padstr + numpart;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ obj new_reader(rdr: buf_reader) {
|
|||||||
go_on = false;
|
go_on = false;
|
||||||
} else { vec::push[u8](buf, ch as u8); }
|
} 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 {
|
fn read_c_str() -> str {
|
||||||
let buf: vec[u8] = [];
|
let buf: vec[u8] = [];
|
||||||
@@ -131,7 +131,7 @@ obj new_reader(rdr: buf_reader) {
|
|||||||
go_on = false;
|
go_on = false;
|
||||||
} else { vec::push[u8](buf, ch as u8); }
|
} 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?
|
// FIXME deal with eof?
|
||||||
@@ -440,7 +440,9 @@ fn string_writer() -> str_writer {
|
|||||||
let buf: mutable_byte_buf = @{mutable buf: b, mutable pos: 0u};
|
let buf: mutable_byte_buf = @{mutable buf: b, mutable pos: 0u};
|
||||||
obj str_writer_wrap(wr: writer, buf: mutable_byte_buf) {
|
obj str_writer_wrap(wr: writer, buf: mutable_byte_buf) {
|
||||||
fn get_writer() -> writer { ret wr; }
|
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);
|
ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ native "rust" mod rustrt {
|
|||||||
count: uint);
|
count: uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_vec[@T](v: &vec[T]) -> [T] {
|
fn from_vec[@T](v: &vec[mutable? T]) -> [T] {
|
||||||
let iv = ~[];
|
let iv = ~[];
|
||||||
for e in v {
|
for e in v {
|
||||||
iv += ~[e];
|
iv += ~[e];
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ fn start_program(prog: str, args: vec[str]) -> @program_res {
|
|||||||
fn read_all(rd: &io::reader) -> str {
|
fn read_all(rd: &io::reader) -> str {
|
||||||
let buf = "";
|
let buf = "";
|
||||||
while !rd.eof() {
|
while !rd.eof() {
|
||||||
let bytes = rd.read_bytes(4096u);
|
let bytes = ivec::from_vec(rd.read_bytes(4096u));
|
||||||
buf += str::unsafe_from_bytes(bytes);
|
buf += str::unsafe_from_bytes_ivec(bytes);
|
||||||
}
|
}
|
||||||
ret buf;
|
ret buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ fn readclose(fd: int) -> str {
|
|||||||
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
||||||
let buf = "";
|
let buf = "";
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let bytes = reader.read_bytes(4096u);
|
let bytes = ivec::from_vec(reader.read_bytes(4096u));
|
||||||
buf += str::unsafe_from_bytes(bytes);
|
buf += str::unsafe_from_bytes_ivec(bytes);
|
||||||
}
|
}
|
||||||
os::libc::fclose(file);
|
os::libc::fclose(file);
|
||||||
ret buf;
|
ret buf;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import std::os;
|
|||||||
import std::io;
|
import std::io;
|
||||||
import std::option;
|
import std::option;
|
||||||
import std::str;
|
import std::str;
|
||||||
|
import std::ivec;
|
||||||
|
|
||||||
// Regression test for memory leaks
|
// Regression test for memory leaks
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@@ -58,8 +59,8 @@ fn test_pipes() {
|
|||||||
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
||||||
let buf = "";
|
let buf = "";
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let bytes = reader.read_bytes(4096u);
|
let bytes = ivec::from_vec(reader.read_bytes(4096u));
|
||||||
buf += str::unsafe_from_bytes(bytes);
|
buf += str::unsafe_from_bytes_ivec(bytes);
|
||||||
}
|
}
|
||||||
os::libc::fclose(file);
|
os::libc::fclose(file);
|
||||||
ret buf;
|
ret buf;
|
||||||
|
|||||||
@@ -3,24 +3,17 @@
|
|||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
use std;
|
use std;
|
||||||
import std::str;
|
import std::str;
|
||||||
import std::vec;
|
|
||||||
import std::ivec;
|
import std::ivec;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
let s1: str = "All mimsy were the borogoves";
|
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 v: [u8] = str::bytes(s1);
|
||||||
let s2: str = str::unsafe_from_bytes(v);
|
let s2: str = str::unsafe_from_bytes_ivec(v);
|
||||||
let i: uint = 0u;
|
let i: uint = 0u;
|
||||||
let n1: uint = str::byte_len(s1);
|
let n1: uint = str::byte_len(s1);
|
||||||
let n2: uint = vec::len[u8](v);
|
let n2: uint = ivec::len[u8](v);
|
||||||
assert (n1 == n2);
|
assert (n1 == n2);
|
||||||
while i < n1 {
|
while i < n1 {
|
||||||
let a: u8 = s1.(i);
|
let a: u8 = s1.(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user