string.c: preserve coderange in String#setbyte
Fix a wrong jump so replacing a byte in an ASCII-only string with an ASCII character won't clear the coderange. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2c8cec96cc
commit
06a3a10acf
4
string.c
4
string.c
@ -5279,13 +5279,13 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
|
|||||||
enc = STR_ENC_GET(str);
|
enc = STR_ENC_GET(str);
|
||||||
head = RSTRING_PTR(str);
|
head = RSTRING_PTR(str);
|
||||||
ptr = &head[pos];
|
ptr = &head[pos];
|
||||||
if (!STR_EMBEDDABLE_P(len, rb_enc_mbminlen(enc))) {
|
if (!STR_EMBED_P(str)) {
|
||||||
cr = ENC_CODERANGE(str);
|
cr = ENC_CODERANGE(str);
|
||||||
switch (cr) {
|
switch (cr) {
|
||||||
case ENC_CODERANGE_7BIT:
|
case ENC_CODERANGE_7BIT:
|
||||||
left = ptr;
|
left = ptr;
|
||||||
*ptr = byte;
|
*ptr = byte;
|
||||||
if (ISASCII(byte)) break;
|
if (ISASCII(byte)) goto end;
|
||||||
nlen = rb_enc_precise_mbclen(left, head+len, enc);
|
nlen = rb_enc_precise_mbclen(left, head+len, enc);
|
||||||
if (!MBCLEN_CHARFOUND_P(nlen))
|
if (!MBCLEN_CHARFOUND_P(nlen))
|
||||||
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
|
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user