diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-31 09:08:31 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-31 09:08:31 +0000 |
commit | 69610b07c304e6ef61c108afaa525fa84cd80451 (patch) | |
tree | dbc9801ad6b54bab6477aaaff9682ae36c445fcc /transcode.c | |
parent | 6e37ddcfbddd5053655d38bf8dc827d8c2ea3379 (diff) |
* transcode.c (transcode.c): set source_encoding and
destination_encoding as encoding object.
(ecerr_source_encoding): new method.
(ecerr_destination_encoding): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/transcode.c b/transcode.c index a036c8f807..b8f154cdee 100644 --- a/transcode.c +++ b/transcode.c @@ -1647,6 +1647,7 @@ make_econv_exception(rb_econv_t *ec) size_t readagain_len = ec->last_error.readagain_len; VALUE bytes2 = Qnil; VALUE dumped2; + int idx; if (ec->last_error.result == econv_incomplete_input) { mesg = rb_sprintf("incomplete %s on %s", StringValueCStr(dumped), @@ -1667,11 +1668,19 @@ make_econv_exception(rb_econv_t *ec) } exc = rb_exc_new3(rb_eInvalidByteSequence, mesg); - rb_ivar_set(exc, rb_intern("source_encoding_name"), rb_str_new2(ec->last_error.source_encoding)); - rb_ivar_set(exc, rb_intern("destination_encoding_name"), rb_str_new2(ec->last_error.destination_encoding)); rb_ivar_set(exc, rb_intern("error_bytes"), bytes); rb_ivar_set(exc, rb_intern("readagain_bytes"), bytes2); rb_ivar_set(exc, rb_intern("incomplete_input"), ec->last_error.result == econv_incomplete_input ? Qtrue : Qfalse); + + set_encs: + rb_ivar_set(exc, rb_intern("source_encoding_name"), rb_str_new2(ec->last_error.source_encoding)); + rb_ivar_set(exc, rb_intern("destination_encoding_name"), rb_str_new2(ec->last_error.destination_encoding)); + idx = rb_enc_find_index(ec->last_error.source_encoding); + if (0 <= idx) + rb_ivar_set(exc, rb_intern("source_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx))); + idx = rb_enc_find_index(ec->last_error.destination_encoding); + if (0 <= idx) + rb_ivar_set(exc, rb_intern("destination_encoding"), rb_enc_from_encoding(rb_enc_from_index(idx))); return exc; } if (ec->last_error.result == econv_undefined_conversion) { @@ -1686,13 +1695,10 @@ make_econv_exception(rb_econv_t *ec) ec->last_error.destination_encoding); exc = rb_exc_new3(rb_eConversionUndefined, mesg); idx = rb_enc_find_index(ec->last_error.source_encoding); - rb_ivar_set(exc, rb_intern("source_encoding_name"), rb_str_new2(ec->last_error.source_encoding)); - rb_ivar_set(exc, rb_intern("destination_encoding_name"), rb_str_new2(ec->last_error.destination_encoding)); - idx = rb_enc_find_index(ec->last_error.source_encoding); if (0 <= idx) rb_enc_associate_index(bytes, idx); rb_ivar_set(exc, rb_intern("error_char"), bytes); - return exc; + goto set_encs; } return Qnil; } @@ -2855,12 +2861,24 @@ ecerr_source_encoding_name(VALUE self) } static VALUE +ecerr_source_encoding(VALUE self) +{ + return rb_attr_get(self, rb_intern("source_encoding")); +} + +static VALUE ecerr_destination_encoding_name(VALUE self) { return rb_attr_get(self, rb_intern("destination_encoding_name")); } static VALUE +ecerr_destination_encoding(VALUE self) +{ + return rb_attr_get(self, rb_intern("destination_encoding")); +} + +static VALUE ecerr_error_char(VALUE self) { return rb_attr_get(self, rb_intern("error_char")); @@ -2938,10 +2956,14 @@ Init_transcode(void) rb_define_method(rb_eConversionUndefined, "source_encoding_name", ecerr_source_encoding_name, 0); rb_define_method(rb_eConversionUndefined, "destination_encoding_name", ecerr_destination_encoding_name, 0); + rb_define_method(rb_eConversionUndefined, "source_encoding", ecerr_source_encoding, 0); + rb_define_method(rb_eConversionUndefined, "destination_encoding", ecerr_destination_encoding, 0); rb_define_method(rb_eConversionUndefined, "error_char", ecerr_error_char, 0); rb_define_method(rb_eInvalidByteSequence, "source_encoding_name", ecerr_source_encoding_name, 0); rb_define_method(rb_eInvalidByteSequence, "destination_encoding_name", ecerr_destination_encoding_name, 0); + rb_define_method(rb_eInvalidByteSequence, "source_encoding", ecerr_source_encoding, 0); + rb_define_method(rb_eInvalidByteSequence, "destination_encoding", ecerr_destination_encoding, 0); rb_define_method(rb_eInvalidByteSequence, "error_bytes", ecerr_error_bytes, 0); rb_define_method(rb_eInvalidByteSequence, "readagain_bytes", ecerr_readagain_bytes, 0); rb_define_method(rb_eInvalidByteSequence, "incomplete_input?", ecerr_incomplete_input, 0); |