mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
cstr.c: get rid of exception
* ext/-test-/string/cstr.c (bug_str_cstr_term_char): get rid of invalid byte sequence exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9f92684791
commit
5fb4f81eec
1 changed files with 9 additions and 1 deletions
|
@ -28,7 +28,15 @@ bug_str_cstr_term_char(VALUE str)
|
|||
rb_encoding *enc = rb_enc_get(str);
|
||||
|
||||
RSTRING_GETMEM(str, s, len);
|
||||
c = rb_enc_codepoint(&s[len], &s[len+rb_enc_mbminlen(enc)], enc);
|
||||
s += len;
|
||||
len = rb_enc_mbminlen(enc);
|
||||
c = rb_enc_precise_mbclen(s, s + len, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(c)) {
|
||||
c = (unsigned char)*s;
|
||||
}
|
||||
else {
|
||||
c = rb_enc_mbc_to_codepoint(s, s + len, enc);
|
||||
}
|
||||
return c ? rb_enc_uint_chr((unsigned int)c, enc) : Qnil;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue