aboutsummaryrefslogtreecommitdiff
path: root/src/rt
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-03-24 12:11:32 +0100
committerGraydon Hoare <[email protected]>2011-03-25 08:22:52 -0700
commita0455144774de6c9dc0ff0e87fe4352f8a70cac3 (patch)
treea487499a7e61e5fbda47d93eba806fb02373d1ed /src/rt
parentfix pretty-printer (diff)
downloadrust-a0455144774de6c9dc0ff0e87fe4352f8a70cac3.tar.xz
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')
-rw-r--r--src/rt/rust_builtin.cpp21
-rw-r--r--src/rt/rustrt.def.in1
2 files changed, 22 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 3f2ae511..e20cadea 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)
{
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index be51770a..5f9300f7 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -29,6 +29,7 @@ str_byte_len
str_from_buf
str_from_cstr
str_from_vec
+str_push_byte
task_sleep
unsupervise
upcall_clone_chan