1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2008-08-31 09:08:31 +00:00
parent 6e37ddcfbd
commit 69610b07c3
3 changed files with 41 additions and 6 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
}
@ -2854,12 +2860,24 @@ ecerr_source_encoding_name(VALUE self)
return rb_attr_get(self, rb_intern("source_encoding_name"));
}
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)
{
@ -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);