1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (prepare_getline_args): convert RS to external encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-12-23 18:12:44 +00:00
parent 7ea8ec5483
commit 459ca7f3f0
2 changed files with 13 additions and 4 deletions

View file

@ -5,6 +5,8 @@ Mon Dec 24 02:59:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_read_encoding): retrieve reading encoding.
* io.c (prepare_getline_args): convert RS to external encoding.
Mon Dec 24 02:06:35 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_f_open): documentation update.

15
io.c
View file

@ -1769,9 +1769,10 @@ rscheck(const char *rsptr, long rslen, VALUE rs)
}
static void
prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit)
prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
{
VALUE lim, rs;
rb_io_t *fptr;
if (argc == 0) {
rs = rb_rs;
@ -1791,6 +1792,12 @@ prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit)
}
}
}
GetOpenFile(io, fptr);
if (fptr->enc2) {
rs = rb_funcall(rs, id_encode, 2,
rb_enc_from_encoding(fptr->enc2),
rb_enc_from_encoding(fptr->enc));
}
*rsp = rs;
*limit = NIL_P(lim) ? -1L : NUM2LONG(lim);
}
@ -1872,7 +1879,7 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
VALUE rs;
long limit;
prepare_getline_args(argc, argv, &rs, &limit);
prepare_getline_args(argc, argv, &rs, &limit, io);
return rb_io_getline_1(rs, limit, io);
}
@ -2041,7 +2048,7 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
VALUE line, ary, rs;
long limit;
prepare_getline_args(argc, argv, &rs, &limit);
prepare_getline_args(argc, argv, &rs, &limit, io);
ary = rb_ary_new();
while (!NIL_P(line = rb_io_getline_1(rs, limit, io))) {
rb_ary_push(ary, line);
@ -2080,7 +2087,7 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
long limit;
RETURN_ENUMERATOR(io, argc, argv);
prepare_getline_args(argc, argv, &rs, &limit);
prepare_getline_args(argc, argv, &rs, &limit, io);
while (!NIL_P(str = rb_io_getline_1(rs, limit, io))) {
rb_yield(str);
}