mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 10:03:59 +02:00
merge revision(s) 49402,49403,49414:
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/branches/ruby_2_2@49650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b888aeded
commit
964a1b683a
2 changed files with 20 additions and 3 deletions
|
@ -28,8 +28,24 @@ 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);
|
||||
return c ? rb_enc_uint_chr((unsigned int)c, enc) : Qnil;
|
||||
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);
|
||||
if (!c) return Qnil;
|
||||
}
|
||||
return rb_enc_uint_chr((unsigned int)c, enc);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
bug_str_s_cstr_term_char(VALUE self, VALUE str)
|
||||
{
|
||||
Check_Type(str, T_STRING);
|
||||
return bug_str_cstr_term_char(str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -37,4 +53,5 @@ Init_cstr(VALUE klass)
|
|||
{
|
||||
rb_define_method(klass, "cstr_term", bug_str_cstr_term, 0);
|
||||
rb_define_method(klass, "cstr_term_char", bug_str_cstr_term_char, 0);
|
||||
rb_define_singleton_method(klass, "cstr_term_char", bug_str_s_cstr_term_char, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue