* io.c (swallow, prepare_getline_args, rb_io_getline_1): fix for
paragraph mode reading in non-ascii-compatible encoding. [ruby-dev:41803] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7ef57c613a
commit
6fb59decd0
@ -1,3 +1,9 @@
|
|||||||
|
Sun Jul 4 17:13:14 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (swallow, prepare_getline_args, rb_io_getline_1): fix for
|
||||||
|
paragraph mode reading in non-ascii-compatible encoding.
|
||||||
|
[ruby-dev:41803]
|
||||||
|
|
||||||
Sat Jul 3 16:14:10 2010 Kenta Murata <mrkn@mrkn.jp>
|
Sat Jul 3 16:14:10 2010 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
* ext/bigdecimal/bigdecimal.c (Init_bigdecimal): add two new constants
|
* ext/bigdecimal/bigdecimal.c (Init_bigdecimal): add two new constants
|
||||||
|
15
io.c
15
io.c
@ -2289,8 +2289,9 @@ swallow(rb_io_t *fptr, int term)
|
|||||||
while ((cnt = READ_CHAR_PENDING_COUNT(fptr)) > 0) {
|
while ((cnt = READ_CHAR_PENDING_COUNT(fptr)) > 0) {
|
||||||
const char *p = READ_CHAR_PENDING_PTR(fptr);
|
const char *p = READ_CHAR_PENDING_PTR(fptr);
|
||||||
int i;
|
int i;
|
||||||
if (needconv) {
|
if (!needconv) {
|
||||||
if (*p != term) return TRUE;
|
if (*p != term) return TRUE;
|
||||||
|
i = (int)cnt;
|
||||||
while (--i && *++p == term);
|
while (--i && *++p == term);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2406,7 +2407,7 @@ prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
|
|||||||
enc_io = io_read_encoding(fptr);
|
enc_io = io_read_encoding(fptr);
|
||||||
if (enc_io != enc_rs &&
|
if (enc_io != enc_rs &&
|
||||||
(rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
|
(rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
|
||||||
!rb_enc_asciicompat(enc_io))) {
|
(RSTRING_LEN(rs) > 0 && !rb_enc_asciicompat(enc_io)))) {
|
||||||
if (rs == rb_default_rs) {
|
if (rs == rb_default_rs) {
|
||||||
rs = rb_enc_str_new(0, 0, enc_io);
|
rs = rb_enc_str_new(0, 0, enc_io);
|
||||||
rb_str_buf_cat_ascii(rs, "\n");
|
rb_str_buf_cat_ascii(rs, "\n");
|
||||||
@ -2450,6 +2451,8 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|||||||
int rspara = 0;
|
int rspara = 0;
|
||||||
int extra_limit = 16;
|
int extra_limit = 16;
|
||||||
|
|
||||||
|
enc = io_read_encoding(fptr);
|
||||||
|
|
||||||
if (!NIL_P(rs)) {
|
if (!NIL_P(rs)) {
|
||||||
rslen = RSTRING_LEN(rs);
|
rslen = RSTRING_LEN(rs);
|
||||||
if (rslen == 0) {
|
if (rslen == 0) {
|
||||||
@ -2458,6 +2461,13 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|||||||
rspara = 1;
|
rspara = 1;
|
||||||
swallow(fptr, '\n');
|
swallow(fptr, '\n');
|
||||||
rs = 0;
|
rs = 0;
|
||||||
|
if (!rb_enc_asciicompat(enc)) {
|
||||||
|
rs = rb_usascii_str_new(rsptr, rslen);
|
||||||
|
rs = rb_str_encode(rs, rb_enc_from_encoding(enc), 0, Qnil);
|
||||||
|
OBJ_FREEZE(rs);
|
||||||
|
rsptr = RSTRING_PTR(rs);
|
||||||
|
rslen = RSTRING_LEN(rs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rsptr = RSTRING_PTR(rs);
|
rsptr = RSTRING_PTR(rs);
|
||||||
@ -2466,7 +2476,6 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* MS - Optimisation */
|
/* MS - Optimisation */
|
||||||
enc = io_read_encoding(fptr);
|
|
||||||
while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
|
while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
|
||||||
const char *s, *p, *pp, *e;
|
const char *s, *p, *pp, *e;
|
||||||
|
|
||||||
|
@ -1806,5 +1806,18 @@ EOT
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_textmode_paragraph_nonasciicompat
|
||||||
|
bug3534 = ['[ruby-dev:41803]', '[Bug #3534]']
|
||||||
|
r, w = IO.pipe
|
||||||
|
r.binmode
|
||||||
|
[Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||||
|
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||||
|
Encoding::UTF_8].each do |e|
|
||||||
|
r.set_encoding(Encoding::US_ASCII, e)
|
||||||
|
w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n")
|
||||||
|
assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
|
||||||
|
assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user