[macruby-changes] [4865] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 1 14:06:41 PDT 2010
Revision: 4865
http://trac.macosforge.org/projects/ruby/changeset/4865
Author: watson1978 at gmail.com
Date: 2010-11-01 14:06:39 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
IO#gets(nil) will return all data which was read from the stream.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
string = "a\n\nb\n\n"
r, w = IO.pipe
w.print string
w.close
assert_equal(string, r.gets(nil))
r.close
r, w = IO.pipe
w.print string
w.close
r.each(nil) {|line| assert_equal(string, line)}
r.close
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-01 00:14:50 UTC (rev 4864)
+++ MacRuby/trunk/io.c 2010-11-01 21:06:39 UTC (rev 4865)
@@ -1366,8 +1366,10 @@
if (NIL_P(sep)) {
// no arguments were passed at all.
// FIXME: if you pass nil, it's suppose to read everything. that sucks.
- sep = rb_rs;
- limit = Qnil;
+ if (argc == 0) {
+ sep = rb_rs;
+ limit = Qnil;
+ }
}
else {
if (TYPE(sep) != T_STRING) {
@@ -1382,7 +1384,13 @@
const long line_limit = NIL_P(limit) ? -1 : FIX2LONG(limit);
VALUE bstr = rb_bstr_new();
- if (line_limit != -1) {
+ if (NIL_P(sep)) {
+ rb_io_read_all(io_struct, bstr);
+ if (rb_bstr_length(bstr) == 0) {
+ return Qnil;
+ }
+ }
+ else if (line_limit != -1) {
rb_bstr_resize(bstr, line_limit);
uint8_t *bytes = rb_bstr_bytes(bstr);
long r = rb_io_read_internal(io_struct, bytes, line_limit);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101101/ca540010/attachment.html>
More information about the macruby-changes
mailing list