Skip to content

Commit

Permalink
libcore: Add from_buf_len_nocopy
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton authored and catamorphism committed Aug 28, 2012
1 parent 5322984 commit 1359439
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,7 @@ mod unsafe {
export
from_buf,
from_buf_len,
from_buf_len_nocopy,
from_c_str,
from_c_str_len,
from_bytes,
Expand Down Expand Up @@ -1799,6 +1800,13 @@ mod unsafe {
return ::unsafe::transmute(v);
}

/// Create a Rust string from a *u8 buffer of the given length without copying
unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str {
let v = (*buf, len + 1);
assert is_utf8(::unsafe::reinterpret_cast(v));
return ::unsafe::transmute(v);
}

/// Create a Rust string from a null-terminated C string
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
from_buf(::unsafe::reinterpret_cast(c_str))
Expand Down

0 comments on commit 1359439

Please sign in to comment.