[前][次][番号順一覧][スレッド一覧]

ruby-changes:37321

From: nobu <ko1@a...>
Date: Mon, 26 Jan 2015 11:01:02 +0900 (JST)
Subject: [ruby-changes:37321] nobu:r49402 (trunk): cstr.c: get rid of exception

nobu	2015-01-26 11:00:43 +0900 (Mon, 26 Jan 2015)

  New Revision: 49402

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49402

  Log:
    cstr.c: get rid of exception
    
    * ext/-test-/string/cstr.c (bug_str_cstr_term_char): get rid of
      invalid byte sequence exception.

  Modified files:
    trunk/ext/-test-/string/cstr.c
Index: ext/-test-/string/cstr.c
===================================================================
--- ext/-test-/string/cstr.c	(revision 49401)
+++ ext/-test-/string/cstr.c	(revision 49402)
@@ -28,7 +28,15 @@ bug_str_cstr_term_char(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/cstr.c#L28
     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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]