зеркало из https://github.com/github/ruby.git
string.c: separate resetting code range
* string.c (rb_str_setbyte): separate resetting code range by each code range, and remove unnecessary branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9bc67e1efa
Коммит
6177abcbf0
38
string.c
38
string.c
|
@ -4721,38 +4721,30 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
|
|||
switch (cr) {
|
||||
case ENC_CODERANGE_7BIT:
|
||||
left = ptr;
|
||||
width = 1;
|
||||
break;
|
||||
case ENC_CODERANGE_VALID:
|
||||
left = rb_enc_left_char_head(head, ptr, head+len, enc);
|
||||
width = rb_enc_precise_mbclen(left, head+len, enc);
|
||||
break;
|
||||
default:
|
||||
ENC_CODERANGE_CLEAR(str);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ENC_CODERANGE_CLEAR(str);
|
||||
}
|
||||
|
||||
*ptr = byte;
|
||||
|
||||
switch (cr) {
|
||||
case ENC_CODERANGE_7BIT:
|
||||
if (ISASCII(byte)) break;
|
||||
case ENC_CODERANGE_VALID:
|
||||
nlen = rb_enc_precise_mbclen(left, head+len, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(nlen))
|
||||
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
|
||||
else if (cr == ENC_CODERANGE_7BIT)
|
||||
else
|
||||
ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID);
|
||||
else if (MBCLEN_CHARFOUND_LEN(nlen) != width)
|
||||
goto end;
|
||||
case ENC_CODERANGE_VALID:
|
||||
left = rb_enc_left_char_head(head, ptr, head+len, enc);
|
||||
width = rb_enc_precise_mbclen(left, head+len, enc);
|
||||
*ptr = byte;
|
||||
nlen = rb_enc_precise_mbclen(left, head+len, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(nlen))
|
||||
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
|
||||
else if (MBCLEN_CHARFOUND_LEN(nlen) != width || ISASCII(byte))
|
||||
ENC_CODERANGE_CLEAR(str);
|
||||
else if (ISASCII(byte)) /* may become 7BIT */
|
||||
ENC_CODERANGE_CLEAR(str);
|
||||
break;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
ENC_CODERANGE_CLEAR(str);
|
||||
*ptr = byte;
|
||||
|
||||
end:
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче