* io.c (rb_io_getline_fast, rb_io_getline): increase lineno
when met the delimiter or EOF. fixed: [ruby-dev:30081] * io.c (prepare_getline_args, rb_io_getline_1): split preparation of arguments and reading. [ruby-dev:30085] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
387b3e8970
commit
0ad41807a5
10
ChangeLog
10
ChangeLog
@ -1,3 +1,11 @@
|
|||||||
|
Sat Jan 6 18:46:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_io_getline_fast, rb_io_getline): increase lineno
|
||||||
|
when met the delimiter or EOF. fixed: [ruby-dev:30081]
|
||||||
|
|
||||||
|
* io.c (prepare_getline_args, rb_io_getline_1): split
|
||||||
|
preparation of arguments and reading. [ruby-dev:30085]
|
||||||
|
|
||||||
Sat Jan 6 13:48:36 2007 Koichi Sasada <ko1@atdot.net>
|
Sat Jan 6 13:48:36 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* insns.def (send): fix to optimize send() with Symbol.
|
* insns.def (send): fix to optimize send() with Symbol.
|
||||||
@ -24992,7 +25000,7 @@ Fri Aug 29 17:30:15 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
|||||||
* ext/tk/lib/tk.rb, ext/tk/lib/tkfont.rb, ext/tk/lib/tkcanvas.rb,
|
* ext/tk/lib/tk.rb, ext/tk/lib/tkfont.rb, ext/tk/lib/tkcanvas.rb,
|
||||||
ext/tk/lib/tktext.rb: fix bug of font handling
|
ext/tk/lib/tktext.rb: fix bug of font handling
|
||||||
|
|
||||||
* ext/tk/lib/tkfont.rb TkFont.new() accepts compound fonts
|
* ext/tk/lib/tkfont.rb: TkFont.new() accepts compound fonts
|
||||||
|
|
||||||
Thu Aug 28 22:07:12 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Thu Aug 28 22:07:12 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
60
io.c
60
io.c
@ -1636,15 +1636,19 @@ static VALUE
|
|||||||
rb_io_getline_fast(OpenFile *fptr, unsigned char delim, long limit)
|
rb_io_getline_fast(OpenFile *fptr, unsigned char delim, long limit)
|
||||||
{
|
{
|
||||||
VALUE str = Qnil;
|
VALUE str = Qnil;
|
||||||
int c;
|
int c, nolimit = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = appendline(fptr, delim, &str, &limit);
|
c = appendline(fptr, delim, &str, &limit);
|
||||||
if (c == EOF || c == delim || limit == 0) break;
|
if (c == EOF || c == delim) break;
|
||||||
|
if (limit == 0) {
|
||||||
|
nolimit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NIL_P(str)) {
|
if (!NIL_P(str)) {
|
||||||
if (limit != 0) {
|
if (!nolimit) {
|
||||||
fptr->lineno++;
|
fptr->lineno++;
|
||||||
lineno = INT2FIX(fptr->lineno);
|
lineno = INT2FIX(fptr->lineno);
|
||||||
}
|
}
|
||||||
@ -1662,12 +1666,10 @@ rscheck(const char *rsptr, long rslen, VALUE rs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static void
|
||||||
rb_io_getline(int argc, VALUE *argv, VALUE io)
|
prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit)
|
||||||
{
|
{
|
||||||
VALUE rs, lim, str = Qnil;
|
VALUE lim, rs;
|
||||||
OpenFile *fptr;
|
|
||||||
long limit;
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
rs = rb_rs;
|
rs = rb_rs;
|
||||||
@ -1687,7 +1689,16 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
limit = NIL_P(lim) ? 0 : NUM2LONG(lim);
|
*rsp = rs;
|
||||||
|
*limit = NIL_P(lim) ? -1L : NUM2LONG(lim);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
||||||
|
{
|
||||||
|
VALUE str = Qnil;
|
||||||
|
OpenFile *fptr;
|
||||||
|
int nolimit = 0;
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
@ -1695,7 +1706,7 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|||||||
str = read_all(fptr, 0, Qnil);
|
str = read_all(fptr, 0, Qnil);
|
||||||
if (RSTRING_LEN(str) == 0) return Qnil;
|
if (RSTRING_LEN(str) == 0) return Qnil;
|
||||||
}
|
}
|
||||||
else if (!NIL_P(lim) && limit == 0) {
|
else if (limit == 0) {
|
||||||
return rb_str_new(0,0);
|
return rb_str_new(0,0);
|
||||||
}
|
}
|
||||||
else if (rs == rb_default_rs) {
|
else if (rs == rb_default_rs) {
|
||||||
@ -1729,7 +1740,10 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|||||||
if (memcmp(RSTRING_PTR(str) + RSTRING_LEN(str) - rslen,
|
if (memcmp(RSTRING_PTR(str) + RSTRING_LEN(str) - rslen,
|
||||||
rsptr, rslen) == 0) break;
|
rsptr, rslen) == 0) break;
|
||||||
}
|
}
|
||||||
if (limit == 0) break;
|
if (limit == 0) {
|
||||||
|
nolimit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rspara) {
|
if (rspara) {
|
||||||
@ -1740,7 +1754,7 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!NIL_P(str)) {
|
if (!NIL_P(str)) {
|
||||||
if (limit != 0) {
|
if (!nolimit) {
|
||||||
fptr->lineno++;
|
fptr->lineno++;
|
||||||
lineno = INT2FIX(fptr->lineno);
|
lineno = INT2FIX(fptr->lineno);
|
||||||
}
|
}
|
||||||
@ -1750,6 +1764,16 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_io_getline(int argc, VALUE *argv, VALUE io)
|
||||||
|
{
|
||||||
|
VALUE rs;
|
||||||
|
long limit;
|
||||||
|
|
||||||
|
prepare_getline_args(argc, argv, &rs, &limit);
|
||||||
|
return rb_io_getline_1(rs, limit, io);
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_io_gets(VALUE io)
|
rb_io_gets(VALUE io)
|
||||||
{
|
{
|
||||||
@ -1912,10 +1936,12 @@ rb_io_readline(int argc, VALUE *argv, VALUE io)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_io_readlines(int argc, VALUE *argv, VALUE io)
|
rb_io_readlines(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
VALUE line, ary;
|
VALUE line, ary, rs;
|
||||||
|
long limit;
|
||||||
|
|
||||||
|
prepare_getline_args(argc, argv, &rs, &limit);
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new();
|
||||||
while (!NIL_P(line = rb_io_getline(argc, argv, io))) {
|
while (!NIL_P(line = rb_io_getline_1(rs, limit, io))) {
|
||||||
rb_ary_push(ary, line);
|
rb_ary_push(ary, line);
|
||||||
}
|
}
|
||||||
return ary;
|
return ary;
|
||||||
@ -1948,10 +1974,12 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_io_each_line(int argc, VALUE *argv, VALUE io)
|
rb_io_each_line(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str, rs;
|
||||||
|
long limit;
|
||||||
|
|
||||||
RETURN_ENUMERATOR(io, argc, argv);
|
RETURN_ENUMERATOR(io, argc, argv);
|
||||||
while (!NIL_P(str = rb_io_getline(argc, argv, io))) {
|
prepare_getline_args(argc, argv, &rs, &limit);
|
||||||
|
while (!NIL_P(str = rb_io_getline_1(rs, limit, io))) {
|
||||||
rb_yield(str);
|
rb_yield(str);
|
||||||
}
|
}
|
||||||
return io;
|
return io;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user