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 | |
parent | 6e37ddcfbddd5053655d38bf8dc827d8c2ea3379 (diff) | |
download | ruby-69610b07c304e6ef61c108afaa525fa84cd80451.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | test/ruby/test_econv.rb | 6 | ||||
-rw-r--r-- | transcode.c | 34 |
3 files changed, 41 insertions, 6 deletions
@@ -1,3 +1,10 @@ +Sun Aug 31 18:06:49 2008 Tanaka Akira <akr@fsij.org> + + * transcode.c (transcode.c): set source_encoding and + destination_encoding as encoding object. + (ecerr_source_encoding): new method. + (ecerr_destination_encoding): ditto. + Sun Aug 31 17:58:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/mkmf.rb (Logging.log_open): opens in binary mode to get rid of diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index c18d7a8e65..3e2814bff0 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -457,6 +457,8 @@ class TestEncodingConverter < Test::Unit::TestCase } assert_equal("EUC-JP", err.source_encoding_name) assert_equal("UTF-8", err.destination_encoding_name) + assert_equal(Encoding::EUC_JP, err.source_encoding) + assert_equal(Encoding::UTF_8, err.destination_encoding) assert_equal("\xA4".force_encoding("ASCII-8BIT"), err.error_bytes) assert_equal("d", err.readagain_bytes) assert_equal(false, err.incomplete_input?) @@ -468,6 +470,8 @@ class TestEncodingConverter < Test::Unit::TestCase } assert_equal("EUC-JP", err.source_encoding_name) assert_equal("UTF-8", err.destination_encoding_name) + assert_equal(Encoding::EUC_JP, err.source_encoding) + assert_equal(Encoding::UTF_8, err.destination_encoding) assert_equal("\xA4".force_encoding("ASCII-8BIT"), err.error_bytes) assert_equal(nil, err.readagain_bytes) assert_equal(true, err.incomplete_input?) @@ -479,6 +483,8 @@ class TestEncodingConverter < Test::Unit::TestCase } assert_equal("UTF-8", err.source_encoding_name) assert_equal("ISO-8859-1", err.destination_encoding_name) + assert_equal(Encoding::UTF_8, err.source_encoding) + assert_equal(Encoding::ISO_8859_1, err.destination_encoding) assert_equal("\u{3042}", err.error_char) end 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); |