From a0ff5cae7c778e3c8b2b1e387c0c0163010d6c00 Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 2 Mar 2010 12:19:24 +0000 Subject: * io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints): change to alias to each_*, in similar way to ARGF and String. [ruby-core:23948] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 +++ io.c | 138 ++++++++++++++++++++++++++------------------------------------ 2 files changed, 63 insertions(+), 81 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6422e89e5d..7c102e429f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Mar 2 21:16:48 2010 Yusuke Endoh + + * io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints): + change to alias to each_*, in similar way to ARGF and String. + [ruby-core:23948] + Tue Mar 2 15:54:40 2010 NARUSE, Yui * regcomp.c (noname_disable_map): add NT_ANCHOR case. diff --git a/io.c b/io.c index 8026ea3784..8e75a6db57 100644 --- a/io.c +++ b/io.c @@ -2611,6 +2611,22 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io) return ary; } +/* + * call-seq: + * ios.lines(sep=$/) => anEnumerator + * ios.lines(limit) => anEnumerator + * ios.lines(sep, limit) => anEnumerator + * + * Returns an enumerator that gives each line in ios. + * The stream must be opened for reading or an IOError + * will be raised. + * + * f = File.new("testfile") + * f.lines.to_a #=> ["foo\n", "bar\n"] + * f.rewind + * f.lines.sort #=> ["bar\n", "foo\n"] + */ + /* * call-seq: * ios.each(sep=$/) {|line| block } => ios @@ -2649,6 +2665,20 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io) return io; } +/* + * call-seq: + * ios.bytes => anEnumerator + * + * Returns an enumerator that gives each byte (0..255) in ios. + * The stream must be opened for reading or an IOError + * 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] + */ + /* * call-seq: * ios.each_byte {|byte| block } => ios @@ -2781,6 +2811,20 @@ io_getc(rb_io_t *fptr, rb_encoding *enc) return str; } +/* + * call-seq: + * ios.chars => anEnumerator + * + * Returns an enumerator that gives each character in ios. + * The stream must be opened for reading or an IOError + * will be raised. + * + * f = File.new("testfile") + * f.chars.to_a #=> ["h", "e", "l", "l", "o"] + * f.rewind + * f.chars.sort #=> ["e", "h", "l", "l", "o"] + */ + /* * call-seq: * ios.each_char {|c| block } => ios @@ -2814,6 +2858,15 @@ rb_io_each_char(VALUE io) +/* + * call-seq: + * ios.codepoints => anEnumerator + * + * Returns an enumerator that gives each codepoint in ios. + * The stream must be opened for reading or an IOError + * will be raised. + */ + /* * call-seq: * ios.each_codepoint {|c| block } => ios @@ -2899,83 +2952,6 @@ rb_io_each_codepoint(VALUE io) -/* - * call-seq: - * ios.lines(sep=$/) => anEnumerator - * ios.lines(limit) => anEnumerator - * ios.lines(sep, limit) => anEnumerator - * - * Returns an enumerator that gives each line in ios. - * The stream must be opened for reading or an IOError - * 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(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 ios. - * The stream must be opened for reading or an IOError - * 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(VALUE io) -{ - return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0); -} - -/* - * call-seq: - * ios.chars => anEnumerator - * - * Returns an enumerator that gives each character in ios. - * The stream must be opened for reading or an IOError - * will be raised. - * - * f = File.new("testfile") - * f.chars.to_a #=> ["h", "e", "l", "l", "o"] - * f.rewind - * f.chars.sort #=> ["e", "h", "l", "l", "o"] - */ - -static VALUE -rb_io_chars(VALUE io) -{ - return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0); -} - -/* - * call-seq: - * ios.codepoints => anEnumerator - * - * Returns an enumerator that gives each codepoint in ios. - * The stream must be opened for reading or an IOError - * will be raised. - */ - -static VALUE -rb_io_codepoints(VALUE io) -{ - return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0); -} - /* * call-seq: * ios.getc => string or nil @@ -9764,10 +9740,10 @@ Init_IO(void) rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0); rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0); rb_define_method(rb_cIO, "each_codepoint", rb_io_each_codepoint, 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, "chars", rb_io_chars, 0); - rb_define_method(rb_cIO, "codepoints", rb_io_codepoints, 0); + rb_define_method(rb_cIO, "lines", rb_io_each_line, -1); + rb_define_method(rb_cIO, "bytes", rb_io_each_byte, 0); + rb_define_method(rb_cIO, "chars", rb_io_each_char, 0); + rb_define_method(rb_cIO, "codepoints", rb_io_each_codepoint, 0); rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1); rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1); -- cgit v1.2.3