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

* io.c (rb_io_getline_fast, rb_io_getline_1): set encoding to the

result string, as well as getc.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-09-28 04:20:12 +00:00
parent 225e95fe83
commit 041fbcbf50
2 changed files with 15 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Fri Sep 28 13:20:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_getline_fast, rb_io_getline_1): set encoding to the
result string, as well as getc.
Fri Sep 28 12:51:42 2007 Koichi Sasada <ko1@atdot.net> Fri Sep 28 12:51:42 2007 Koichi Sasada <ko1@atdot.net>
* benchmark/bm_app_erb.rb: added. * benchmark/bm_app_erb.rb: added.

15
io.c
View file

@ -1637,7 +1637,7 @@ swallow(rb_io_t *fptr, int term)
} }
static VALUE static VALUE
rb_io_getline_fast(rb_io_t *fptr, unsigned char delim, long limit) rb_io_getline_fast(rb_io_t *fptr, unsigned char delim, long limit, rb_encoding *enc)
{ {
VALUE str = Qnil; VALUE str = Qnil;
int c, nolimit = 0; int c, nolimit = 0;
@ -1652,6 +1652,7 @@ rb_io_getline_fast(rb_io_t *fptr, unsigned char delim, long limit)
} }
if (!NIL_P(str)) { if (!NIL_P(str)) {
rb_enc_associate(str, enc);
if (!nolimit) { if (!nolimit) {
fptr->lineno++; fptr->lineno++;
lineno = INT2FIX(fptr->lineno); lineno = INT2FIX(fptr->lineno);
@ -1700,21 +1701,23 @@ prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit)
static VALUE static VALUE
rb_io_getline_1(VALUE rs, long limit, VALUE io) rb_io_getline_1(VALUE rs, long limit, VALUE io)
{ {
rb_encoding *enc;
VALUE str = Qnil; VALUE str = Qnil;
rb_io_t *fptr; rb_io_t *fptr;
int nolimit = 0; int nolimit = 0;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
enc = rb_enc_get(io);
if (NIL_P(rs)) { if (NIL_P(rs)) {
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 (limit == 0) { else if (limit == 0) {
return rb_str_new(0,0); return rb_enc_str_new(0, 0, enc);
} }
else if (rs == rb_default_rs) { else if (rs == rb_default_rs) {
return rb_io_getline_fast(fptr, '\n', limit); return rb_io_getline_fast(fptr, '\n', limit, enc);
} }
else { else {
int c, newline; int c, newline;
@ -1730,7 +1733,8 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
swallow(fptr, '\n'); swallow(fptr, '\n');
} }
else if (rslen == 1) { else if (rslen == 1) {
return rb_io_getline_fast(fptr, (unsigned char)RSTRING_PTR(rs)[0], limit); return rb_io_getline_fast(fptr, (unsigned char)RSTRING_PTR(rs)[0],
limit, enc);
} }
else { else {
rsptr = RSTRING_PTR(rs); rsptr = RSTRING_PTR(rs);
@ -1758,6 +1762,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
} }
if (!NIL_P(str)) { if (!NIL_P(str)) {
rb_enc_associate(str, enc);
if (!nolimit) { if (!nolimit) {
fptr->lineno++; fptr->lineno++;
lineno = INT2FIX(fptr->lineno); lineno = INT2FIX(fptr->lineno);
@ -1785,7 +1790,7 @@ rb_io_gets(VALUE io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
return rb_io_getline_fast(fptr, '\n', 0); return rb_io_getline_fast(fptr, '\n', 0, rb_enc_get(io));
} }
/* /*