From 8eda80ff2cde551e22e9a9803e932184aafdbf38 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 14 Aug 2008 16:06:33 +0000 Subject: [PATCH] * transcode.c (econv_primitive_convert): set destination_buffer encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_econv.rb | 8 ++++++++ transcode.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 94bd6e9ca2..1c96edada3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Aug 15 01:05:39 2008 Tanaka Akira + + * transcode.c (econv_primitive_convert): set destination_buffer + encoding. + Fri Aug 15 00:52:40 2008 Tanaka Akira * include/ruby/encoding.h (rb_econv_output): declared. diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 98ed310504..af846ad45b 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -31,6 +31,14 @@ class TestEncodingConverter < Test::Unit::TestCase assert_equal(Encoding::EUC_JP, ec.destination_encoding) end + def test_result_encoding + ec = Encoding::Converter.new("UTF-8", "EUC-JP") + dst = "".force_encoding("ASCII-8BIT") + assert_equal(Encoding::ASCII_8BIT, dst.encoding) + ec.primitive_convert("\u{3042}", dst, nil, 10) + assert_equal(Encoding::EUC_JP, dst.encoding) + end + def test_output_region ec = Encoding::Converter.new("UTF-8", "EUC-JP") ec.primitive_convert(src="a", dst="b", nil, 1, Encoding::Converter::PARTIAL_INPUT) diff --git a/transcode.c b/transcode.c index b8c8d1a1ae..2e189b935b 100644 --- a/transcode.c +++ b/transcode.c @@ -1676,6 +1676,10 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self) rb_str_set_len(output, op-(unsigned char *)RSTRING_PTR(output)); rb_str_drop_bytes(input, ip - (unsigned char *)RSTRING_PTR(input)); + if (ec->destination_encoding) { + rb_enc_associate(output, ec->destination_encoding); + } + switch (res) { case econv_invalid_byte_sequence: return ID2SYM(rb_intern("invalid_byte_sequence")); case econv_undefined_conversion: return ID2SYM(rb_intern("undefined_conversion"));