[macruby-changes] [3550] MacRuby/branches/icu/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 15 20:11:06 PST 2010
Revision: 3550
http://trac.macosforge.org/projects/ruby/changeset/3550
Author: lsansonetti at apple.com
Date: 2010-02-15 20:11:01 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
more MRI functions
Modified Paths:
--------------
MacRuby/branches/icu/string.c
Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c 2010-02-16 03:32:07 UTC (rev 3549)
+++ MacRuby/branches/icu/string.c 2010-02-16 04:11:01 UTC (rev 3550)
@@ -211,7 +211,9 @@
self->capacity_in_bytes = self->length_in_bytes = len;
if (len > 0) {
GC_WB(&self->data.bytes, xmalloc(len));
- memcpy(self->data.bytes, bytes, len);
+ if (bytes != NULL) {
+ memcpy(self->data.bytes, bytes, len);
+ }
}
else {
self->data.bytes = NULL;
@@ -225,7 +227,7 @@
return;
}
str_replace_with_bytes(self, source->data.bytes, source->length_in_bytes,
- source->encoding);
+ source->encoding);
self->flags = source->flags;
}
@@ -1350,6 +1352,7 @@
rb_objc_define_method(rb_cRubyString, "include?", mr_str_include, 1);
rb_objc_define_method(rb_cRubyString, "to_s", mr_str_to_s, 0);
rb_objc_define_method(rb_cRubyString, "to_str", mr_str_to_s, 0);
+ rb_objc_define_method(rb_cRubyString, "to_sym", mr_str_intern, 0);
rb_objc_define_method(rb_cRubyString, "intern", mr_str_intern, 0);
// added for MacRuby
@@ -1373,6 +1376,12 @@
}
VALUE
+rb_str_buf_new(long len)
+{
+ return rb_str_new(NULL, len);
+}
+
+VALUE
rb_str_new2(const char *cstr)
{
return rb_str_new(cstr, strlen(cstr));
@@ -1422,7 +1431,6 @@
return rb_usascii_str_new(cstr, strlen(cstr));
}
-
const char *
rb_str_cstr(VALUE str)
{
@@ -1430,7 +1438,7 @@
str_make_data_binary(RSTR(str));
return RSTR(str)->data.bytes;
}
- return ""; // TODO
+ abort(); // TODO
}
long
@@ -1440,7 +1448,7 @@
str_make_data_binary(RSTR(str));
return RSTR(str)->length_in_bytes;
}
- return 0; // TODO
+ abort(); // TODO
}
char *
@@ -1509,3 +1517,91 @@
return SYM2ID(name);
}
}
+
+VALUE
+rb_str_length(VALUE str)
+{
+ if (IS_RSTR(str)) {
+ return mr_str_length(str, 0);
+ }
+ return INT2FIX(CFStringGetLength((CFStringRef)str));
+}
+
+VALUE
+rb_str_buf_new2(const char *cstr)
+{
+ return rb_str_new2(cstr);
+}
+
+VALUE
+rb_str_buf_cat(VALUE str, const char *cstr, long len)
+{
+ if (IS_RSTR(str)) {
+ // XXX this could be optimized
+ VALUE substr = rb_str_new(cstr, len);
+ str_concat_string(RSTR(str), RSTR(substr));
+ }
+ else {
+ abort(); // TODO
+ }
+ return str;
+}
+
+VALUE
+rb_str_buf_cat2(VALUE str, const char *cstr)
+{
+ return rb_str_buf_cat(str, cstr, strlen(cstr));
+}
+
+VALUE
+rb_str_cat(VALUE str, const char *cstr, long len)
+{
+ return rb_str_buf_cat(str, cstr, len);
+}
+
+VALUE
+rb_str_cat2(VALUE str, const char *cstr)
+{
+ return rb_str_buf_cat2(str, cstr);
+}
+
+VALUE
+rb_str_buf_append(VALUE str, VALUE str2)
+{
+ if (IS_RSTR(str)) {
+ return mr_str_concat(str, 0, str2);
+ }
+ CFStringAppend((CFMutableStringRef)str, (CFStringRef)str2);
+ return str;
+}
+
+VALUE
+rb_str_append(VALUE str, VALUE str2)
+{
+ return rb_str_buf_append(str, str2);
+}
+
+VALUE
+rb_str_concat(VALUE str, VALUE str2)
+{
+ return rb_str_buf_append(str, str2);
+}
+
+void
+rb_str_associate(VALUE str, VALUE add)
+{
+ // Do nothing.
+}
+
+VALUE
+rb_str_associated(VALUE str)
+{
+ // Do nothing.
+ return Qfalse;
+}
+
+VALUE
+rb_str_resize(VALUE str, long len)
+{
+ abort(); // TODO
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/b277b5db/attachment.html>
More information about the macruby-changes
mailing list