[macruby-changes] [3701] MacRuby/branches/icu/string.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 4 18:21:32 PST 2010


Revision: 3701
          http://trac.macosforge.org/projects/ruby/changeset/3701
Author:   lsansonetti at apple.com
Date:     2010-03-04 18:21:32 -0800 (Thu, 04 Mar 2010)
Log Message:
-----------
added #bytes

Modified Paths:
--------------
    MacRuby/branches/icu/string.c

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-03-05 01:51:40 UTC (rev 3700)
+++ MacRuby/branches/icu/string.c	2010-03-05 02:21:32 UTC (rev 3701)
@@ -4159,7 +4159,33 @@
 }
 
 /*
+ *  Document-method: each_byte
  *  call-seq:
+ *     str.each_byte {|fixnum| block }    => str
+ *  
+ *  Passes each byte in <i>str</i> to the given block.
+ *     
+ *     "hello".each_byte {|c| print c, ' ' }
+ *     
+ *  <em>produces:</em>
+ *     
+ *     104 101 108 108 111
+ */
+
+static VALUE
+rstr_each_byte(VALUE str, SEL sel)
+{
+    RETURN_ENUMERATOR(str, 0, 0);
+
+    for (long i = 0; i < RSTR(str)->length_in_bytes; i++) {
+	rb_yield(INT2FIX(RSTR(str)->data.bytes[i]));
+	RETURN_IF_BROKEN();
+    }
+    return str;
+}
+
+/*
+ *  call-seq:
  *     str.succ   => new_str
  *     str.next   => new_str
  *  
@@ -4946,6 +4972,8 @@
     rb_objc_define_method(rb_cRubyString, "each_line", rstr_each_line, -1);
     rb_objc_define_method(rb_cRubyString, "chars", rstr_each_char, 0);
     rb_objc_define_method(rb_cRubyString, "each_char", rstr_each_char, 0);
+    rb_objc_define_method(rb_cRubyString, "bytes", rstr_each_byte, 0);
+    rb_objc_define_method(rb_cRubyString, "each_byte", rstr_each_byte, 0);
     rb_objc_define_method(rb_cRubyString, "succ", rstr_succ, 0);
     rb_objc_define_method(rb_cRubyString, "succ!", rstr_succ_bang, 0);
     rb_objc_define_method(rb_cRubyString, "next", rstr_succ, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100304/f2cc2f41/attachment-0001.html>


More information about the macruby-changes mailing list