stdlib: Implement str::unsafe_from_bytes_ivec()

This commit is contained in:
Patrick Walton
2011-07-08 22:23:11 -07:00
parent aa0f6f4961
commit 91d45b91e6
3 changed files with 26 additions and 0 deletions

View File

@@ -313,6 +313,26 @@ str_byte_len(rust_task *task, rust_str *s)
return s->fill - 1; // -1 for the '\0' terminator.
}
extern "C" CDECL rust_str *
str_from_ivec(rust_task *task, rust_ivec *v)
{
uintptr_t fill = v->fill ? v->fill : v->payload.ptr->fill;
void *data = v->fill ? v->payload.data : v->payload.ptr->data;
rust_str *st =
vec_alloc_with_data(task,
fill + 1, // +1 to fit at least '\0'
fill,
1,
fill ? data : NULL);
if (!st) {
task->fail(2);
return NULL;
}
st->data[st->fill++] = '\0';
return st;
}
extern "C" CDECL rust_str *
str_from_vec(rust_task *task, rust_vec *v)
{