summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 04:22:56 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 04:22:56 +0000
commit6b7869ae42c2400b79ee519ca1411f70fb96389b (patch)
treef55f7badb2231c44777065eeff367bcc4171dd3e
parentcb49b26e7ca353580f25fa47e388f8770f55031c (diff)
* io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
IO#{lines,bytes} and ARGF.{lines,bytes}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--NEWS4
-rw-r--r--io.c50
3 files changed, 59 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 47922ec927..7bb6ea6e89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue May 27 13:20:35 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
+ IO#{lines,bytes} and ARGF.{lines,bytes}.
+
Tue May 27 12:13:17 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (BUFCHECK): wrong condition. [ruby-core:16921]
diff --git a/NEWS b/NEWS
index ae520a971d..e08acc885d 100644
--- a/NEWS
+++ b/NEWS
@@ -171,10 +171,14 @@ with all sufficient information, see the ChangeLog file.
* IO#each
* IO#each_line
* IO#each_byte
+ * IO#lines
+ * IO#bytes
* IO.foreach
* ARGF.each
* ARGF.each_line
* ARGF.each_byte
+ * ARGF.lines
+ * ARGF.bytes
Return an enumerator if no block is given.
diff --git a/io.c b/io.c
index 83e748f633..8bf3747458 100644
--- a/io.c
+++ b/io.c
@@ -2028,6 +2028,52 @@ rb_io_each_byte(io)
/*
* call-seq:
+ * ios.lines(sep=$/) => anEnumerator
+ * ios.lines(limit) => anEnumerator
+ * ios.lines(sep, limit) => anEnumerator
+ *
+ * Returns an enumerator that gives each line in <em>ios</em>.
+ * The stream must be opened for reading or an <code>IOError</code>
+ * will be raised.
+ *
+ * f = File.new("testfile")
+ * f.lines.to_a #=> ["foo\n", "bar\n"]
+ * f.rewind
+ * f.lines.sort #=> ["bar\n", "foo\n"]
+ */
+
+static VALUE
+rb_io_lines(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
+{
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
+}
+
+/*
+ * call-seq:
+ * ios.bytes => anEnumerator
+ *
+ * Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
+ * The stream must be opened for reading or an <code>IOError</code>
+ * will be raised.
+ *
+ * f = File.new("testfile")
+ * f.bytes.to_a #=> [104, 101, 108, 108, 111]
+ * f.rewind
+ * f.bytes.sort #=> [101, 104, 108, 108, 111]
+ */
+
+static VALUE
+rb_io_bytes(io)
+ VALUE io;
+{
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
+}
+
+/*
+ * call-seq:
* ios.getc => fixnum or nil
*
* Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
@@ -5808,6 +5854,8 @@ Init_IO()
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
+ rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
+ rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
@@ -5895,6 +5943,8 @@ Init_IO()
rb_define_singleton_method(argf, "each", argf_each_line, -1);
rb_define_singleton_method(argf, "each_line", argf_each_line, -1);
rb_define_singleton_method(argf, "each_byte", argf_each_byte, 0);
+ rb_define_singleton_method(argf, "lines", argf_lines, -1);
+ rb_define_singleton_method(argf, "bytes", argf_bytes, 0);
rb_define_singleton_method(argf, "read", argf_read, -1);
rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);