[前][次][番号順一覧][スレッド一覧]

ruby-changes:5140

From: knu <ko1@a...>
Date: Tue, 27 May 2008 19:05:13 +0900 (JST)
Subject: [ruby-changes:5140] Ruby:r16635 (trunk): * ext/stringio/stringio.c (strio_each_char, Init_stringio): Add

knu	2008-05-27 19:03:23 +0900 (Tue, 27 May 2008)

  New Revision: 16635

  Modified files:
    trunk/ChangeLog
    trunk/ext/stringio/stringio.c

  Log:
    * ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
      StringIO#{each_char,chars}.
      (Init_stringio): Fix StringIO#bytes.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16635&r2=16634&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/stringio/stringio.c?r1=16635&r2=16634&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16634)
+++ ChangeLog	(revision 16635)
@@ -1,3 +1,9 @@
+Tue May 27 19:00:22 2008  Akinori MUSHA  <knu@i...>
+
+	* ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
+	  StringIO#{each_char,chars}.
+	  (Init_stringio): Fix StringIO#bytes.
+
 Tue May 27 17:54:35 2008  Akinori MUSHA  <knu@i...>
 
 	* ext/stringio/stringio.c (strio_each_byte): Return self instead
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 16634)
+++ ext/stringio/stringio.c	(revision 16635)
@@ -755,6 +755,25 @@
     return c;
 }
 
+/*
+ * call-seq:
+ *   strio.each_char {|char| block }  -> strio
+ *
+ * See IO#each_char.
+ */
+static VALUE
+strio_each_char(VALUE self)
+{
+    VALUE c;
+
+    RETURN_ENUMERATOR(self, 0, 0);
+
+    while (!NIL_P(c = strio_getc(self))) {
+	rb_yield(c);
+    }
+    return self;
+}
+
 /* Boyer-Moore search: copied from regex.c */
 static void
 bm_init_skip(long *skip, const char *pat, long m)
@@ -1237,10 +1256,12 @@
     rb_define_method(StringIO, "path", strio_path, 0);
 
     rb_define_method(StringIO, "each", strio_each, -1);
-    rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
-    rb_define_method(StringIO, "bytes", strio_each_byte, -1);
     rb_define_method(StringIO, "each_line", strio_each, -1);
     rb_define_method(StringIO, "lines", strio_each, -1);
+    rb_define_method(StringIO, "each_byte", strio_each_byte, 0);
+    rb_define_method(StringIO, "bytes", strio_each_byte, 0);
+    rb_define_method(StringIO, "each_char", strio_each_char, 0);
+    rb_define_method(StringIO, "chars", strio_each_char, 0);
     rb_define_method(StringIO, "getc", strio_getc, 0);
     rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
     rb_define_method(StringIO, "readchar", strio_readchar, 0);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]