diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 18:12:44 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 18:12:44 +0000 |
commit | 459ca7f3f01c72f001e9da484e8883ded0beeacc (patch) | |
tree | 27d9d67517c8da9fc091568ef49f5ca75d9c3217 /io.c | |
parent | 7ea8ec5483f4a79e411b9813fc6347040bb4c55d (diff) | |
download | ruby-459ca7f3f01c72f001e9da484e8883ded0beeacc.tar.gz |
* 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
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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); } |