Rename str::unsafe to str::raw
This commit is contained in:
parent
59c3c6c147
commit
308ca06012
|
@ -170,7 +170,7 @@ impl T : FromStr {
|
|||
fn to_str(n: T, radix: uint) -> ~str {
|
||||
do to_str_bytes(n, radix) |slice| {
|
||||
do vec::as_buf(slice) |p, len| {
|
||||
unsafe { str::unsafe::from_buf_len(p, len) }
|
||||
unsafe { str::raw::from_buf_len(p, len) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
|
|||
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
|
||||
do vec::as_mut_buf(buf) |b, sz| {
|
||||
if f(b, sz as size_t) unsafe {
|
||||
Some(str::unsafe::from_buf(b as *u8))
|
||||
Some(str::raw::from_buf(b as *u8))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ mod global_env {
|
|||
option::None::<~str>
|
||||
} else {
|
||||
let s = unsafe::reinterpret_cast(&s);
|
||||
option::Some::<~str>(str::unsafe::from_buf(s))
|
||||
option::Some::<~str>(str::raw::from_buf(s))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ export
|
|||
escape_default,
|
||||
escape_unicode,
|
||||
|
||||
unsafe,
|
||||
raw,
|
||||
extensions,
|
||||
StrSlice,
|
||||
UniqueStr;
|
||||
|
@ -132,12 +132,12 @@ Section: Creating a string
|
|||
*/
|
||||
pure fn from_bytes(vv: &[const u8]) -> ~str {
|
||||
assert is_utf8(vv);
|
||||
return unsafe { unsafe::from_bytes(vv) };
|
||||
return unsafe { raw::from_bytes(vv) };
|
||||
}
|
||||
|
||||
/// Copy a slice into a new unique str
|
||||
pure fn from_slice(s: &str) -> ~str {
|
||||
unsafe { unsafe::slice_bytes(s, 0, len(s)) }
|
||||
unsafe { raw::slice_bytes(s, 0, len(s)) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,7 +219,7 @@ fn push_char(&s: ~str, ch: char) {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe::set_len(s, new_len);
|
||||
raw::set_len(s, new_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) {
|
|||
ptr::memcpy(dst, rbuf, rlen);
|
||||
}
|
||||
}
|
||||
unsafe::set_len(lhs, llen + rlen);
|
||||
raw::set_len(lhs, llen + rlen);
|
||||
}
|
||||
}
|
||||
/// Appends a string slice to the back of a string
|
||||
|
@ -271,7 +271,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
|
|||
ptr::memcpy(dst, rbuf, rlen);
|
||||
}
|
||||
}
|
||||
unsafe::set_len(lhs, llen + rlen);
|
||||
raw::set_len(lhs, llen + rlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ fn pop_char(&s: ~str) -> char {
|
|||
let end = len(s);
|
||||
assert end > 0u;
|
||||
let {ch, prev} = char_range_at_reverse(s, end);
|
||||
unsafe { unsafe::set_len(s, prev); }
|
||||
unsafe { raw::set_len(s, prev); }
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -331,7 +331,7 @@ fn pop_char(&s: ~str) -> char {
|
|||
*/
|
||||
fn shift_char(&s: ~str) -> char {
|
||||
let {ch, next} = char_range_at(s, 0u);
|
||||
s = unsafe { unsafe::slice_bytes(s, next, len(s)) };
|
||||
s = unsafe { raw::slice_bytes(s, next, len(s)) };
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ fn shift_char(&s: ~str) -> char {
|
|||
#[inline]
|
||||
fn view_shift_char(s: &a/str) -> (char, &a/str) {
|
||||
let {ch, next} = char_range_at(s, 0u);
|
||||
let next_s = unsafe { unsafe::view_bytes(s, next, len(s)) };
|
||||
let next_s = unsafe { raw::view_bytes(s, next, len(s)) };
|
||||
return (ch, next_s);
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
|
||||
match find(s, |c| !chars_to_trim.contains(c)) {
|
||||
None => ~"",
|
||||
Some(first) => unsafe { unsafe::slice_bytes(s, first, s.len()) }
|
||||
Some(first) => unsafe { raw::slice_bytes(s, first, s.len()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
None => ~"",
|
||||
Some(last) => {
|
||||
let {next, _} = char_range_at(s, last);
|
||||
unsafe { unsafe::slice_bytes(s, 0u, next) }
|
||||
unsafe { raw::slice_bytes(s, 0u, next) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ pure fn trim_chars(s: &str, chars_to_trim: &[char]) -> ~str {
|
|||
pure fn trim_left(s: &str) -> ~str {
|
||||
match find(s, |c| !char::is_whitespace(c)) {
|
||||
None => ~"",
|
||||
Some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) }
|
||||
Some(first) => unsafe { raw::slice_bytes(s, first, len(s)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ pure fn trim_right(s: &str) -> ~str {
|
|||
None => ~"",
|
||||
Some(last) => {
|
||||
let {next, _} = char_range_at(s, last);
|
||||
unsafe { unsafe::slice_bytes(s, 0u, next) }
|
||||
unsafe { raw::slice_bytes(s, 0u, next) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -482,7 +482,7 @@ pure fn substr(s: &str, begin: uint, n: uint) -> ~str {
|
|||
pure fn slice(s: &str, begin: uint, end: uint) -> ~str {
|
||||
assert is_char_boundary(s, begin);
|
||||
assert is_char_boundary(s, end);
|
||||
unsafe { unsafe::slice_bytes(s, begin, end) }
|
||||
unsafe { raw::slice_bytes(s, begin, end) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,7 +494,7 @@ pure fn slice(s: &str, begin: uint, end: uint) -> ~str {
|
|||
pure fn view(s: &a/str, begin: uint, end: uint) -> &a/str {
|
||||
assert is_char_boundary(s, begin);
|
||||
assert is_char_boundary(s, end);
|
||||
unsafe { unsafe::view_bytes(s, begin, end) }
|
||||
unsafe { raw::view_bytes(s, begin, end) }
|
||||
}
|
||||
|
||||
/// Splits a string into substrings at each occurrence of a given character
|
||||
|
@ -527,7 +527,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
|
|||
if s[i] == b {
|
||||
if allow_empty || start < i unchecked {
|
||||
vec::push(result,
|
||||
unsafe { unsafe::slice_bytes(s, start, i) });
|
||||
unsafe { raw::slice_bytes(s, start, i) });
|
||||
}
|
||||
start = i + 1u;
|
||||
done += 1u;
|
||||
|
@ -535,7 +535,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
|
|||
i += 1u;
|
||||
}
|
||||
if allow_empty || start < l {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, start, l) ) };
|
||||
unsafe { vec::push(result, raw::slice_bytes(s, start, l) ) };
|
||||
}
|
||||
move result
|
||||
} else {
|
||||
|
@ -570,7 +570,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
|
|||
let {ch, next} = char_range_at(s, i);
|
||||
if sepfn(ch) {
|
||||
if allow_empty || start < i unchecked {
|
||||
vec::push(result, unsafe { unsafe::slice_bytes(s, start, i)});
|
||||
vec::push(result, unsafe { raw::slice_bytes(s, start, i)});
|
||||
}
|
||||
start = next;
|
||||
done += 1u;
|
||||
|
@ -578,7 +578,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
|
|||
i = next;
|
||||
}
|
||||
if allow_empty || start < l unchecked {
|
||||
vec::push(result, unsafe { unsafe::slice_bytes(s, start, l) });
|
||||
vec::push(result, unsafe { raw::slice_bytes(s, start, l) });
|
||||
}
|
||||
move result
|
||||
}
|
||||
|
@ -632,7 +632,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
|
|||
pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] {
|
||||
let mut result = ~[];
|
||||
do iter_between_matches(s, sep) |from, to| {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
|
||||
unsafe { vec::push(result, raw::slice_bytes(s, from, to)); }
|
||||
}
|
||||
move result
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] {
|
|||
let mut result = ~[];
|
||||
do iter_between_matches(s, sep) |from, to| {
|
||||
if to > from {
|
||||
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
|
||||
unsafe { vec::push(result, raw::slice_bytes(s, from, to)); }
|
||||
}
|
||||
}
|
||||
move result
|
||||
|
@ -661,7 +661,7 @@ pure fn lines_any(s: &str) -> ~[~str] {
|
|||
let l = len(s);
|
||||
let mut cp = copy s;
|
||||
if l > 0u && s[l - 1u] == '\r' as u8 {
|
||||
unsafe { unsafe::set_len(cp, l - 1u); }
|
||||
unsafe { raw::set_len(cp, l - 1u); }
|
||||
}
|
||||
move cp
|
||||
})
|
||||
|
@ -703,7 +703,7 @@ pure fn replace(s: &str, from: &str, to: &str) -> ~str {
|
|||
let mut result = ~"", first = true;
|
||||
do iter_between_matches(s, from) |start, end| {
|
||||
if first { first = false; } else { unchecked {push_str(result, to); }}
|
||||
unsafe { push_str(result, unsafe::slice_bytes(s, start, end)); }
|
||||
unsafe { push_str(result, raw::slice_bytes(s, start, end)); }
|
||||
}
|
||||
move result
|
||||
}
|
||||
|
@ -1963,7 +1963,7 @@ pure fn escape_unicode(s: &str) -> ~str {
|
|||
}
|
||||
|
||||
/// Unsafe operations
|
||||
mod unsafe {
|
||||
mod raw {
|
||||
export
|
||||
from_buf,
|
||||
from_buf_len,
|
||||
|
@ -2029,7 +2029,7 @@ mod unsafe {
|
|||
}
|
||||
|
||||
/// Converts a byte to a string.
|
||||
unsafe fn from_byte(u: u8) -> ~str { unsafe::from_bytes([u]) }
|
||||
unsafe fn from_byte(u: u8) -> ~str { raw::from_bytes([u]) }
|
||||
|
||||
/**
|
||||
* Takes a bytewise (not UTF-8) slice from a string.
|
||||
|
@ -2112,7 +2112,7 @@ mod unsafe {
|
|||
let len = len(s);
|
||||
assert (len > 0u);
|
||||
let b = s[0];
|
||||
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
|
||||
s = unsafe { raw::slice_bytes(s, 1u, len) };
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -2646,9 +2646,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_unsafe_slice() {
|
||||
unsafe {
|
||||
assert ~"ab" == unsafe::slice_bytes(~"abc", 0u, 2u);
|
||||
assert ~"bc" == unsafe::slice_bytes(~"abc", 1u, 3u);
|
||||
assert ~"" == unsafe::slice_bytes(~"abc", 1u, 1u);
|
||||
assert ~"ab" == raw::slice_bytes(~"abc", 0u, 2u);
|
||||
assert ~"bc" == raw::slice_bytes(~"abc", 1u, 3u);
|
||||
assert ~"" == raw::slice_bytes(~"abc", 1u, 1u);
|
||||
fn a_million_letter_a() -> ~str {
|
||||
let mut i = 0;
|
||||
let mut rs = ~"";
|
||||
|
@ -2662,7 +2662,7 @@ mod tests {
|
|||
return rs;
|
||||
}
|
||||
assert half_a_million_letter_a() ==
|
||||
unsafe::slice_bytes(a_million_letter_a(), 0u, 500000u);
|
||||
raw::slice_bytes(a_million_letter_a(), 0u, 500000u);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2881,7 +2881,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_shift_byte() {
|
||||
let mut s = ~"ABC";
|
||||
let b = unsafe { unsafe::shift_byte(s) };
|
||||
let b = unsafe { raw::shift_byte(s) };
|
||||
assert (s == ~"BC");
|
||||
assert (b == 65u8);
|
||||
}
|
||||
|
@ -2889,7 +2889,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_pop_byte() {
|
||||
let mut s = ~"ABC";
|
||||
let b = unsafe { unsafe::pop_byte(s) };
|
||||
let b = unsafe { raw::pop_byte(s) };
|
||||
assert (s == ~"AB");
|
||||
assert (b == 67u8);
|
||||
}
|
||||
|
@ -2897,7 +2897,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_unsafe_from_bytes() {
|
||||
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8];
|
||||
let b = unsafe { unsafe::from_bytes(a) };
|
||||
let b = unsafe { raw::from_bytes(a) };
|
||||
assert (b == ~"AAAAAAA");
|
||||
}
|
||||
|
||||
|
@ -2941,7 +2941,7 @@ mod tests {
|
|||
unsafe {
|
||||
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
|
||||
let b = vec::raw::to_ptr(a);
|
||||
let c = unsafe::from_buf(b);
|
||||
let c = raw::from_buf(b);
|
||||
assert (c == ~"AAAAAAA");
|
||||
}
|
||||
}
|
||||
|
@ -2979,7 +2979,7 @@ mod tests {
|
|||
unsafe {
|
||||
let s = ~"hello";
|
||||
let sb = as_buf(s, |b, _l| b);
|
||||
let s_cstr = unsafe::from_buf(sb);
|
||||
let s_cstr = raw::from_buf(sb);
|
||||
assert s_cstr == s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
|
|||
pure fn to_str(num: T, radix: uint) -> ~str {
|
||||
do to_str_bytes(false, num, radix) |slice| {
|
||||
do vec::as_buf(slice) |p, len| {
|
||||
unsafe { str::unsafe::from_buf_len(p, len) }
|
||||
unsafe { str::raw::from_buf_len(p, len) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -834,7 +834,7 @@ unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
|
|||
// to see if it is the string representation of
|
||||
// INADDR_NONE (0xffffffff or 255.255.255.255 on
|
||||
// many platforms)
|
||||
str::unsafe::from_buf(dst_buf)
|
||||
str::raw::from_buf(dst_buf)
|
||||
}
|
||||
}
|
||||
unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
|
||||
|
@ -852,7 +852,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
|
|||
let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr,
|
||||
dst_buf, size as libc::size_t);
|
||||
match result {
|
||||
0i32 => str::unsafe::from_buf(dst_buf),
|
||||
0i32 => str::raw::from_buf(dst_buf),
|
||||
_ => ~""
|
||||
}
|
||||
}
|
||||
|
@ -962,8 +962,8 @@ unsafe fn free_base_of_buf(buf: uv_buf_t) {
|
|||
unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
|
||||
let err = last_error(uv_loop);
|
||||
let err_ptr = ptr::addr_of(err);
|
||||
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
|
||||
let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
|
||||
let err_name = str::raw::from_c_str(err_name(err_ptr));
|
||||
let err_msg = str::raw::from_c_str(strerror(err_ptr));
|
||||
return fmt!("LIBUV ERROR: name: %s msg: %s",
|
||||
err_name, err_msg);
|
||||
}
|
||||
|
@ -971,8 +971,8 @@ unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
|
|||
unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data {
|
||||
let err = last_error(uv_loop);
|
||||
let err_ptr = ptr::addr_of(err);
|
||||
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
|
||||
let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
|
||||
let err_name = str::raw::from_c_str(err_name(err_ptr));
|
||||
let err_msg = str::raw::from_c_str(strerror(err_ptr));
|
||||
{ err_name: err_name, err_msg: err_msg }
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ fn llvm_err(sess: session, msg: ~str) -> ! unsafe {
|
|||
let cstr = llvm::LLVMRustGetLastError();
|
||||
if cstr == ptr::null() {
|
||||
sess.fatal(msg);
|
||||
} else { sess.fatal(msg + ~": " + str::unsafe::from_c_str(cstr)); }
|
||||
} else { sess.fatal(msg + ~": " + str::raw::from_c_str(cstr)); }
|
||||
}
|
||||
|
||||
fn WriteOutputFile(sess:session,
|
||||
|
|
|
@ -181,7 +181,7 @@ fn get_metadata_section(os: os,
|
|||
let si = mk_section_iter(of.llof);
|
||||
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
|
||||
let name_buf = llvm::LLVMGetSectionName(si.llsi);
|
||||
let name = unsafe { str::unsafe::from_c_str(name_buf) };
|
||||
let name = unsafe { str::raw::from_c_str(name_buf) };
|
||||
if name == meta_section_name(os) {
|
||||
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
|
||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
|
|
|
@ -59,7 +59,7 @@ fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) unsa
|
|||
let mut op: ~str = ~"";
|
||||
let sl: uint = str::len(s);
|
||||
for uint::range(0u, n as uint) |i| {
|
||||
str::unsafe::push_byte(op, s[i % sl]);
|
||||
str::raw::push_byte(op, s[i % sl]);
|
||||
if str::len(op) >= LINE_LENGTH() {
|
||||
wr.write_line(op);
|
||||
op = ~"";
|
||||
|
|
|
@ -49,7 +49,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
|
|||
|
||||
pairs_sorted.each(fn&(kv: (~[u8], float)) -> bool unsafe {
|
||||
let (k,v) = kv;
|
||||
buffer += (fmt!("%s %0.3f\n", str::to_upper(str::unsafe::from_bytes(k)), v));
|
||||
buffer += (fmt!("%s %0.3f\n", str::to_upper(str::raw::from_bytes(k)), v));
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
|
|||
|
||||
pairs_sorted.each(fn&(kv: (~[u8], float)) -> bool unsafe {
|
||||
let (k,v) = kv;
|
||||
buffer += (fmt!("%s %0.3f\n", str::to_upper(str::unsafe::from_bytes(k)), v));
|
||||
buffer += (fmt!("%s %0.3f\n", str::to_upper(str::raw::from_bytes(k)), v));
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue