diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2011-07-08 22:23:11 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2011-07-08 22:23:11 -0700 |
| commit | 91d45b91e64c4db6f07b9dd21837dac84f0a1255 (patch) | |
| tree | 993e31b0f6894019017ed4c8a8d2f7c91b36c909 /src/rt/rust_builtin.cpp | |
| parent | aa0f6f49610962466972e659605e3c8e676ce7b5 (diff) | |
| download | rust-91d45b91e64c4db6f07b9dd21837dac84f0a1255.tar.gz rust-91d45b91e64c4db6f07b9dd21837dac84f0a1255.zip | |
stdlib: Implement str::unsafe_from_bytes_ivec()
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 33f4a5114ce..6057ee4cb6c 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -314,6 +314,26 @@ str_byte_len(rust_task *task, rust_str *s) } 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) { rust_str *st = |
