diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-08 15:21:05 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-08 15:21:05 +0000 |
commit | 4106a7c067bb6dbadc8055a7e575180479bb08c0 (patch) | |
tree | 01061fae6a39333a3202ef76829d73b593f52113 | |
parent | 870a8b3903622a42e2d84c95a754c7f23797761b (diff) | |
download | ruby-4106a7c067bb6dbadc8055a7e575180479bb08c0.tar.gz |
* transcode.c (rb_econv_asciicompat_encoding): check decoder.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | transcode.c | 48 |
2 files changed, 31 insertions, 21 deletions
@@ -1,3 +1,7 @@ +Tue Sep 9 00:20:10 2008 Tanaka Akira <akr@fsij.org> + + * transcode.c (rb_econv_asciicompat_encoding): check decoder. + Tue Sep 9 00:00:47 2008 Tanaka Akira <akr@fsij.org> * transcode.c (rb_econv_t): last_error.partial_input removed. diff --git a/transcode.c b/transcode.c index a2f804a818..c35a53af9e 100644 --- a/transcode.c +++ b/transcode.c @@ -1639,24 +1639,15 @@ static int 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 @@ asciicompat_encoding_i(st_data_t key, st_data_t val, st_data_t arg) 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 |