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

ruby-changes:7732

From: akr <ko1@a...>
Date: Tue, 9 Sep 2008 00:21:30 +0900 (JST)
Subject: [ruby-changes:7732] Ruby:r19253 (trunk): * transcode.c (rb_econv_asciicompat_encoding): check decoder.

akr	2008-09-09 00:21:05 +0900 (Tue, 09 Sep 2008)

  New Revision: 19253

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

  Log:
    * transcode.c (rb_econv_asciicompat_encoding): check decoder.

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19252)
+++ ChangeLog	(revision 19253)
@@ -1,3 +1,7 @@
+Tue Sep  9 00:20:10 2008  Tanaka Akira  <akr@f...>
+
+	* transcode.c (rb_econv_asciicompat_encoding): check decoder.
+
 Tue Sep  9 00:00:47 2008  Tanaka Akira  <akr@f...>
 
 	* transcode.c (rb_econv_t): last_error.partial_input removed.
Index: transcode.c
===================================================================
--- transcode.c	(revision 19252)
+++ transcode.c	(revision 19253)
@@ -1639,24 +1639,15 @@
 asciicompat_encoding_i(st_data_t key, st_data_t val, st_data_t arg)
 {
     struct asciicompat_encoding_t *data = (struct asciicompat_encoding_t *)arg;
-    st_table *table2 = (st_table *)val;
-    st_data_t v;
+    transcoder_entry_t *entry = (transcoder_entry_t *)val;
+    const rb_transcoder *tr;
 
-    if (st_lookup(table2, (st_data_t)data->ascii_incompat_name, &v)) {
-        transcoder_entry_t *entry = (transcoder_entry_t *)v;
-        const rb_transcoder *tr;
-        if (SUPPLEMENTAL_CONVERSION(entry->sname, entry->dname))
-            return ST_CONTINUE;
-        tr = load_transcoder_entry(entry);
-        if (tr && tr->asciicompat_type == asciicompat_encoder) {
-            /*
-             * Assumption:
-             * There is only one transcoder for
-             * converting to ASCII incompatible encoding.
-             */
-            data->ascii_compat_name = tr->src_encoding;
-            return ST_STOP;
-        }
+    if (SUPPLEMENTAL_CONVERSION(entry->sname, entry->dname))
+        return ST_CONTINUE;
+    tr = load_transcoder_entry(entry);
+    if (tr && tr->asciicompat_type == asciicompat_decoder) {
+        data->ascii_compat_name = tr->dst_encoding;
+        return ST_STOP;
     }
     return ST_CONTINUE;
 }
@@ -1664,13 +1655,28 @@
 const char *
 rb_econv_asciicompat_encoding(const char *ascii_incompat_name)
 {
+    st_data_t v;
+    st_table *table2;
     struct asciicompat_encoding_t data;
+
+    if (!st_lookup(transcoder_table, (st_data_t)ascii_incompat_name, &v))
+        return NULL;
+    table2 = (st_table *)v;
+
+    /*
+     * Assumption:
+     * There are at most one transcoder for
+     * converting from ASCII incompatible encoding.
+     *
+     * For ISO-2022-JP, there is ISO-2022-JP -> stateless-ISO-2022-JP and no others.
+     */
+    if (table2->num_entries != 1)
+        return NULL;
+
     data.ascii_incompat_name = ascii_incompat_name;
     data.ascii_compat_name = NULL;
-    st_foreach(transcoder_table, asciicompat_encoding_i, (st_data_t)&data);
-    if (data.ascii_compat_name)
-        return data.ascii_compat_name;
-    return NULL;
+    st_foreach(table2, asciicompat_encoding_i, (st_data_t)&data);
+    return data.ascii_compat_name;
 }
 
 VALUE

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

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