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

ruby-changes:20768

From: naruse <ko1@a...>
Date: Tue, 2 Aug 2011 23:28:06 +0900 (JST)
Subject: [ruby-changes:20768] naruse:r32816 (trunk): Fix r32811: add UNSPECIFIED_ENCODING case.

naruse	2011-08-02 23:27:56 +0900 (Tue, 02 Aug 2011)

  New Revision: 32816

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

  Log:
    Fix r32811: add UNSPECIFIED_ENCODING case.

  Modified files:
    trunk/encoding.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 32815)
+++ encoding.c	(revision 32816)
@@ -159,6 +159,7 @@
     return rb_enc_find_index(StringValueCStr(enc));
 }
 
+/* Returns encoding index or UNSPECIFIED_ENCODING */
 static int
 str_to_encindex(VALUE enc)
 {
@@ -596,6 +597,7 @@
     return i;
 }
 
+/* Return encoding index or UNSPECIFIED_ENCODING from encoding name */
 int
 rb_enc_find_index(const char *name)
 {
@@ -1051,9 +1053,12 @@
 static VALUE
 enc_find(VALUE klass, VALUE enc)
 {
+    int idx;
     if (!SPECIAL_CONST_P(enc) && BUILTIN_TYPE(enc) == T_DATA && is_data_encoding(enc))
 	return enc;
-    return rb_enc_from_encoding_index(str_to_encindex(enc));
+    idx = str_to_encindex(enc);
+    if (idx == UNSPECIFIED_ENCODING) return Qnil;
+    return rb_enc_from_encoding_index(idx);
 }
 
 /*

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

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