diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-27 15:19:22 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-27 15:19:22 +0000 |
commit | 4dd9fd71b34cd21613404a2900085868dfac5cd4 (patch) | |
tree | a47739c65aba4e2205cedbfc7c412d2c72fd171a /io.c | |
parent | 9d014dc2546bdcc9bf899e734e7df73ae5735a2b (diff) | |
download | ruby-4dd9fd71b34cd21613404a2900085868dfac5cd4.tar.gz |
* string.c (rb_str_coderange_scan_restartable): coderange scaning
for partial read.
* io.c (read_all): set coderange when not convert encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1358,6 +1358,9 @@ read_all(rb_io_t *fptr, long siz, VALUE str) { long bytes = 0; long n; + long pos = 0; + rb_encoding *enc = io_read_encoding(fptr); + int cr = 0; if (siz == 0) siz = BUFSIZ; if (NIL_P(str)) { @@ -1370,15 +1373,21 @@ read_all(rb_io_t *fptr, long siz, VALUE str) READ_CHECK(fptr); n = io_fread(str, bytes, fptr); if (n == 0 && bytes == 0) { - break; + break; } bytes += n; + if (cr != ENC_CODERANGE_BROKEN) + pos = rb_str_coderange_scan_restartable(RSTRING_PTR(str) + pos, RSTRING_PTR(str) + bytes, enc, &cr); if (bytes < siz) break; siz += BUFSIZ; rb_str_resize(str, siz); } if (bytes != siz) rb_str_resize(str, bytes); - return io_enc_str(str, fptr); + str = io_enc_str(str, fptr); + if (fptr->enc2) { + ENC_CODERANGE_SET(str, cr); + } + return str; } void |