[macruby-changes] [4906] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 15 15:36:49 PST 2010
Revision: 4906
http://trac.macosforge.org/projects/ruby/changeset/4906
Author: watson1978 at gmail.com
Date: 2010-11-15 15:36:47 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.each_{line | byte | char} will be passed the multiple file path.
Test Script:
{{{
require 'tempfile'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
t1 = Tempfile.new("foo")
t1.puts "1"
t1.puts "2"
t1.close
t2 = Tempfile.new("bar")
t2.puts "3"
t2.puts "4"
t2.close
def ruby(*args)
args = ['-e', '$>.write($<.read)'] if args.empty?
ruby = "/usr/local/bin/macruby"
f = IO.popen([ruby] + args, 'r+')
yield(f)
ensure
f.close unless !f || f.closed?
end
ruby('-e', <<-SRC, t1.path, t2.path) do |f|
s = []
ARGF.each_byte {|c| s << c }
p s
SRC
assert_equal("[49, 10, 50, 10, 51, 10, 52, 10]?\194?\165n", f.read)
end
ruby('-e', <<-SRC, t1.path, t2.path) do |f|
s = ""
ARGF.each_char {|c| s << c }
puts s
SRC
assert_equal("1?\194?\165n2?\194?\165n3?\194?\165n4?\194?\165n", f.read)
end
ruby('-e', <<-SRC, t1.path, t2.path) do |f|
s = []
ARGF.each_line {|l| s << l }
p s
SRC
assert_equal("[?\194?\165"1?\194?\165?\194?\165n?\194?\165", ?\194?\165"2?\194?\165?\194?\165n?\194?\165", ?\194?\165"3?\194?\165?\194?\165n?\194?\165", ?\194?\165"4?\194?\165?\194?\165n?\194?\165"]?\194?\165n", f.read)
end
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-15 12:49:27 UTC (rev 4905)
+++ MacRuby/trunk/io.c 2010-11-15 23:36:47 UTC (rev 4906)
@@ -4376,25 +4376,40 @@
static VALUE
argf_each_line(VALUE argf, SEL sel, int argc, VALUE *argv)
{
- next_argv();
- ARGF_FORWARD(0, 0);
- return rb_io_each_line(ARGF.current_file, sel, argc, argv);
+ RETURN_ENUMERATOR(argf, argc, argv);
+ while (true) {
+ if (!next_argv()) {
+ return argf;
+ }
+ rb_io_each_line(ARGF.current_file, sel, argc, argv);
+ ARGF.next_p = 1;
+ }
}
static VALUE
argf_each_byte(VALUE argf, SEL sel)
{
- next_argv();
- ARGF_FORWARD(0, 0);
- return rb_io_each_byte(ARGF.current_file, sel);
+ RETURN_ENUMERATOR(argf, 0, 0);
+ while (true) {
+ if (!next_argv()) {
+ return argf;
+ }
+ rb_io_each_byte(ARGF.current_file, sel);
+ ARGF.next_p = 1;
+ }
}
static VALUE
argf_each_char(VALUE argf, SEL sel)
{
- next_argv();
- ARGF_FORWARD(0, 0);
- return rb_io_each_char(ARGF.current_file, sel);
+ RETURN_ENUMERATOR(argf, 0, 0);
+ while (true) {
+ if (!next_argv()) {
+ return argf;
+ }
+ rb_io_each_char(ARGF.current_file, sel);
+ ARGF.next_p = 1;
+ }
}
static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/c28cc769/attachment.html>
More information about the macruby-changes
mailing list