aboutsummaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-16 06:25:38 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-16 06:25:38 +0000
commit4dff8b24286e84c1c2a2bd7e422d490327470d26 (patch)
treea9a36e7ad59ec87957b15802d107d3fd844ee3fa /transcode.c
parent7a0bea4fd327ec0f572f25a24adc7f0b2f9821e8 (diff)
downloadruby-4dff8b24286e84c1c2a2bd7e422d490327470d26.tar.gz
* include/ruby/encoding.h (rb_econv_elem_t): fields removed: from and
to. (rb_econv_t): new fields: source_encoding_name and destination_encoding_name. * transcode.c (rb_econv_open_by_transcoder_entries): initialize the new fields. (rb_econv_open): set up the new fields. (econv_inspect): use the new fields. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/transcode.c b/transcode.c
index 9753e88c33..7e6e2ff2b4 100644
--- a/transcode.c
+++ b/transcode.c
@@ -677,6 +677,8 @@ rb_econv_open_by_transcoder_entries(int n, transcoder_entry_t **entries)
}
ec = ALLOC(rb_econv_t);
+ ec->source_encoding_name = NULL;
+ ec->destination_encoding_name = NULL;
ec->in_buf_start = NULL;
ec->in_data_start = NULL;
ec->in_data_end = NULL;
@@ -690,8 +692,6 @@ rb_econv_open_by_transcoder_entries(int n, transcoder_entry_t **entries)
ec->destination_encoding = NULL;
for (i = 0; i < ec->num_trans; i++) {
const rb_transcoder *tr = load_transcoder_entry(entries[i]);
- ec->elems[i].from = tr->from_encoding;
- ec->elems[i].to = tr->to_encoding;
ec->elems[i].tc = rb_transcoding_open_by_transcoder(tr, 0);
ec->elems[i].out_buf_start = NULL;
ec->elems[i].out_data_start = NULL;
@@ -761,6 +761,11 @@ rb_econv_open(const char *from, const char *to, int flags)
}
ec = rb_econv_open_by_transcoder_entries(num_trans, entries);
+ if (!ec)
+ rb_raise(rb_eArgError, "encoding conversion not supported (from %s to %s)", from, to);
+
+ ec->source_encoding_name = from;
+ ec->destination_encoding_name = to;
if (flags & ECONV_UNIVERSAL_NEWLINE_DECODER) {
ec->last_tc = ec->elems[ec->num_trans-2].tc;
@@ -1687,6 +1692,9 @@ econv_init(int argc, VALUE *argv, VALUE self)
ec->source_encoding = senc;
ec->destination_encoding = denc;
+ ec->source_encoding_name = ec->elems[0].tc->transcoder->from_encoding;
+ ec->destination_encoding_name = ec->last_tc->transcoder->to_encoding;
+
DATA_PTR(self) = ec;
return self;
@@ -1702,8 +1710,8 @@ econv_inspect(VALUE self)
return rb_sprintf("#<%s: uninitialized>", cname);
else
return rb_sprintf("#<%s: %s to %s>", cname,
- ec->elems[0].from,
- ec->last_tc->transcoder->to_encoding);
+ ec->source_encoding_name,
+ ec->destination_encoding_name);
}
#define IS_ECONV(obj) (RDATA(obj)->dfree == (RUBY_DATA_FUNC)econv_free)