mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb0a4c0f62
commit
3e0becb42d
3 changed files with 60 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Mon Nov 26 16:36:13 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]
|
||||
|
||||
Mon Nov 26 15:50:29 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* bignum.c (bigdivrem): restart calculation when bigdivrem1 was
|
||||
|
|
32
io.c
32
io.c
|
@ -10860,6 +10860,36 @@ argf_each_char(VALUE argf)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ARGF.codepoints {|codepoint| block } -> ARGF
|
||||
* ARGF.codepoints -> an_enumerator
|
||||
*
|
||||
* ARGF.each_codepoint {|codepoint| block } -> ARGF
|
||||
* ARGF.each_codepoint -> an_enumerator
|
||||
*
|
||||
* Iterates over each codepoint of each file in +ARGF+.
|
||||
*
|
||||
* This method allows you to treat the files supplied on the command line as
|
||||
* a single file consisting of the concatenation of each named file. After
|
||||
* the last codepoint of the first file has been returned, the first
|
||||
* codepoint of the second file is returned. The +ARGF.filename+ method can
|
||||
* be used to determine the name of the file in which the current codepoint
|
||||
* appears.
|
||||
*
|
||||
* If no block is given, an enumerator is returned instead.
|
||||
*/
|
||||
static VALUE
|
||||
argf_each_codepoint(VALUE argf)
|
||||
{
|
||||
RETURN_ENUMERATOR(argf, 0, 0);
|
||||
for (;;) {
|
||||
if (!next_argv()) return argf;
|
||||
rb_block_call(ARGF.current_file, rb_intern("each_codepoint"), 0, 0, 0, 0);
|
||||
ARGF.next_p = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ARGF.filename -> String
|
||||
|
@ -11557,9 +11587,11 @@ Init_IO(void)
|
|||
rb_define_method(rb_cARGF, "each_line", argf_each_line, -1);
|
||||
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
|
||||
rb_define_method(rb_cARGF, "each_char", argf_each_char, 0);
|
||||
rb_define_method(rb_cARGF, "each_codepoint", argf_each_codepoint, 0);
|
||||
rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
|
||||
rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
|
||||
rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
|
||||
rb_define_method(rb_cARGF, "codepoints", argf_each_codepoint, 0);
|
||||
|
||||
rb_define_method(rb_cARGF, "read", argf_read, -1);
|
||||
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);
|
||||
|
|
|
@ -770,4 +770,28 @@ class TestArgf < Test::Unit::TestCase
|
|||
bug5952 = '[ruby-dev:45160]'
|
||||
assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952)
|
||||
end
|
||||
|
||||
def test_bytes
|
||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
||||
print Marshal.dump(ARGF.bytes.to_a)
|
||||
SRC
|
||||
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
|
||||
end
|
||||
end
|
||||
|
||||
def test_chars
|
||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
||||
print Marshal.dump(ARGF.chars.to_a)
|
||||
SRC
|
||||
assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read))
|
||||
end
|
||||
end
|
||||
|
||||
def test_codepoints
|
||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
||||
print Marshal.dump(ARGF.codepoints.to_a)
|
||||
SRC
|
||||
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue