diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-03-24 12:11:32 +0100 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-03-25 08:22:52 -0700 |
| commit | a0455144774de6c9dc0ff0e87fe4352f8a70cac3 (patch) | |
| tree | a487499a7e61e5fbda47d93eba806fb02373d1ed /src/rt/rust_builtin.cpp | |
| parent | d3b49f5aab6a9e9efc2ab1d6713cc0d2bde94f4e (diff) | |
| download | rust-a0455144774de6c9dc0ff0e87fe4352f8a70cac3.tar.gz rust-a0455144774de6c9dc0ff0e87fe4352f8a70cac3.zip | |
Start making the standard-lib utf-8 aware
Finally implements _str.is_utf8, adds from_chars, from_char, to_chars, char_at, char_len, (push|pop|shift|unshift)_char. Also, proper character I/O for streams.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 3f2ae511551..e20cadeae49 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -196,6 +196,27 @@ str_alloc(rust_task *task, size_t n_bytes) return st; } +extern "C" CDECL rust_str* +str_push_byte(rust_task* task, rust_str* v, size_t byte) +{ + size_t fill = v->fill; + size_t alloc = next_power_of_two(sizeof(rust_vec) + fill + 1); + if (v->ref_count > 1 || v->alloc < alloc) { + v = vec_alloc_with_data(task, fill + 1, fill, 1, (void*)&v->data[0]); + if (!v) { + task->fail(2); + return NULL; + } + } + else if (v->ref_count != CONST_REFCOUNT) { + v->ref(); + } + v->data[fill-1] = (char)byte; + v->data[fill] = '\0'; + v->fill++; + return v; +} + extern "C" CDECL char const * str_buf(rust_task *task, rust_str *s) { |
