summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 10:03:23 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 10:03:23 +0000
commitf15c0dd7dd28bfcd53a3c68dc4c726595d207d3f (patch)
tree551a531d6caa89df03e5a0af713fbcaf29d22a9b /ext
parentf7213e1c521095a66606d31023b6a1cfea3079b7 (diff)
* ext/stringio/stringio.c (strio_each_char, Init_stringio): Add
StringIO#{each_char,chars}. (Init_stringio): Fix StringIO#bytes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index b72f5a9a32..2f32d5a30d 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -755,6 +755,25 @@ strio_readbyte(VALUE self)
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 @@ Init_stringio()
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);