mozilla/rust — pull request #7039 by erickt (2013-06-10 04:58:38+00:00)
Title: str convert-from-bytes API cleanup

Good evening. This patch series cleans up the string API. `str::from_bytes*` was a bit of a mess. We had ways of taking a `&[u8]` and getting a `~str` or `&str`, but no way to cheaply move a `~[u8]` into a `~str`. This patch series adds or changes to `str`:

```
fn from_bytes(v: ~[u8]) -> ~str;
fn from_bytes_with_null(v: ~[u8]) -> ~str;

fn from_bytes_slice<'a>(v: &'a [u8]) -> &'a str;
fn from_bytes_slice_with_null<'a>(v: &'a [u8]) -> &'a str;
```

and adds these to `str::raw`:

```
fn buf_len(buf: *u8) -> uint;

fn from_buf(buf: *u8) -> ~str;
fn from_buf_len(buf: *u8, len: uint) -> ~str;

fn buf_as_slice(buf: *u8, f: &fn(&str) -> T) -> T;
fn buf_len_as_slice(buf: *u8, len: uint, f: &fn(&str) -> T) -> T;

fn c_str_as_slice(buf: *libc::c_char, f: &fn(&str) -> T) -> T;
```

And removes `str_byte_slice` and `str_byte_slice_no_callback` as those two functions are redundant. This fixes #7019.