aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--io.c15
2 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 313403c41b..13cba3a6dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/io.c b/io.c
index e5edbf1f94..3dda55cdc1 100644
--- a/io.c
+++ b/io.c
@@ -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);
}