[macruby-changes] [2025] MacRuby/branches/experimental/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jul 14 18:15:47 PDT 2009
Revision: 2025
http://trac.macosforge.org/projects/ruby/changeset/2025
Author: pthomson at apple.com
Date: 2009-07-14 18:15:47 -0700 (Tue, 14 Jul 2009)
Log Message:
-----------
Implemented ByteString#getbyte and ByteString#setbyte. Not particularly useful as of yet, but their time will come.
Modified Paths:
--------------
MacRuby/branches/experimental/string.c
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-07-14 23:48:56 UTC (rev 2024)
+++ MacRuby/branches/experimental/string.c 2009-07-15 01:15:47 UTC (rev 2025)
@@ -36,6 +36,7 @@
static ptrdiff_t wrappedDataOffset;
#define WRAPPED_DATA_IV_NAME "wrappedData"
+#define BYTESTRING_ENCODING_IV_NAME "encoding"
VALUE
rb_str_freeze(VALUE str)
@@ -5418,6 +5419,32 @@
return rb_bytestring_length((VALUE)rcv);
}
+static VALUE
+rb_bytestring_getbyte(VALUE bstr, SEL sel, VALUE idx)
+{
+ long index = NUM2LONG(idx);
+ while(idx < 0)
+ {
+ // adjusting for negative indices
+ idx += rb_bytestring_length(bstr);
+ }
+ return INT2FIX(rb_bytestring_byte_pointer(bstr)[index]);
+}
+
+static VALUE
+rb_bytestring_setbyte(VALUE bstr, SEL sel, VALUE idx, VALUE newbyte)
+{
+ long index = NUM2LONG(idx);
+ while(idx < 0)
+ {
+ // adjusting for negative indices
+ idx += rb_bytestring_length(bstr);
+ }
+ rb_bytestring_byte_pointer(bstr)[index] = FIX2UINT(newbyte);
+ return Qnil;
+}
+
+
static UniChar
imp_rb_bytestring_characterAtIndex(void *rcv, SEL sel, CFIndex idx)
{
@@ -5670,7 +5697,8 @@
rb_bytestring_initialize, -1);
rb_objc_define_method(*(VALUE *)rb_cByteString, "alloc",
rb_bytestring_alloc, 0);
-
+ rb_objc_define_method(rb_cByteString, "getbyte", rb_bytestring_getbyte, 1);
+ rb_objc_define_method(rb_cByteString, "setbyte", rb_bytestring_setbyte, 2);
wrappedDataOffset = ivar_getOffset(
class_getInstanceVariable((Class)rb_cByteString,
WRAPPED_DATA_IV_NAME));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090714/6ee23b52/attachment-0001.html>
More information about the macruby-changes
mailing list