mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9d014dc254
commit
4dd9fd71b3
4 changed files with 75 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
Wed Feb 27 22:55:42 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_coderange_scan_restartable): coderange scaning
|
||||
for partial read.
|
||||
|
||||
* io.c (read_all): set coderange when not convert encoding.
|
||||
|
||||
Wed Feb 27 03:55:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/extmk.rb, enc/make_encmake.rb: load current mkmf.rb even if
|
||||
|
|
11
io.c
11
io.c
|
@ -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)) {
|
||||
|
@ -1373,12 +1376,18 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
|
|||
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
|
||||
|
|
55
string.c
55
string.c
|
@ -201,6 +201,61 @@ coderange_scan(const char *p, long len, rb_encoding *enc)
|
|||
return ENC_CODERANGE_VALID;
|
||||
}
|
||||
|
||||
long
|
||||
rb_str_coderange_scan_restartable(const char *s, const char *e, rb_encoding *enc, int *cr)
|
||||
{
|
||||
long c;
|
||||
const char *p;
|
||||
int ret;
|
||||
p = s;
|
||||
|
||||
if (*cr == ENC_CODERANGE_BROKEN)
|
||||
return e - s;
|
||||
|
||||
if (rb_enc_to_index(enc) == 0) {
|
||||
/* enc is ASCII-8BIT. ASCII-8BIT string never be broken. */
|
||||
p = search_nonascii(p, e);
|
||||
*cr = (!p && *cr != ENC_CODERANGE_VALID) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
|
||||
return e - s;
|
||||
}
|
||||
else if (rb_enc_asciicompat(enc)) {
|
||||
p = search_nonascii(p, e);
|
||||
if (!p) {
|
||||
if (*cr != ENC_CODERANGE_VALID) *cr = ENC_CODERANGE_7BIT;
|
||||
return e - s;
|
||||
}
|
||||
while (p < e) {
|
||||
int ret = rb_enc_precise_mbclen(p, e, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(ret)) {
|
||||
*cr = MBCLEN_INVALID_P(ret) ? ENC_CODERANGE_BROKEN: ret;
|
||||
return e - s;
|
||||
}
|
||||
p += MBCLEN_CHARFOUND_LEN(ret);
|
||||
if (p < e) {
|
||||
p = search_nonascii(p, e);
|
||||
if (!p) {
|
||||
*cr = ENC_CODERANGE_VALID;
|
||||
return e - s;
|
||||
}
|
||||
}
|
||||
}
|
||||
*cr = e < p ? ENC_CODERANGE_BROKEN: ENC_CODERANGE_VALID;
|
||||
return p - s;
|
||||
}
|
||||
else {
|
||||
while (p < e) {
|
||||
int ret = rb_enc_precise_mbclen(p, e, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(ret)) {
|
||||
*cr = MBCLEN_INVALID_P(ret) ? ENC_CODERANGE_BROKEN: ret;
|
||||
return p - s;
|
||||
}
|
||||
p += MBCLEN_CHARFOUND_LEN(ret);
|
||||
}
|
||||
*cr = e < p ? ENC_CODERANGE_BROKEN: ENC_CODERANGE_VALID;
|
||||
return p - s;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rb_enc_str_copy(VALUE dest, VALUE src)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#define RUBY_VERSION "1.9.0"
|
||||
#define RUBY_RELEASE_DATE "2008-02-27"
|
||||
#define RUBY_RELEASE_DATE "2008-02-28"
|
||||
#define RUBY_VERSION_CODE 190
|
||||
#define RUBY_RELEASE_CODE 20080227
|
||||
#define RUBY_RELEASE_CODE 20080228
|
||||
#define RUBY_PATCHLEVEL 0
|
||||
|
||||
#define RUBY_VERSION_MAJOR 1
|
||||
|
|
Loading…
Add table
Reference in a new issue