diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 19:36:38 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 19:36:38 +0000 |
| commit | 2da16f3411fe343a441ceacf4a0cc2d321dfc77b (patch) | |
| tree | c0064cabac2e2595631b77f19953928265138f6e | |
| parent | 741eb7843f231d006fc3a9298b22e734936f5927 (diff) | |
| download | ruby-2da16f3411fe343a441ceacf4a0cc2d321dfc77b.tar.gz ruby-2da16f3411fe343a441ceacf4a0cc2d321dfc77b.tar.xz ruby-2da16f3411fe343a441ceacf4a0cc2d321dfc77b.zip | |
* transcode.c (rb_econv_putback): putback from last byte.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | test/ruby/test_econv.rb | 9 | ||||
| -rw-r--r-- | transcode.c | 2 |
3 files changed, 14 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Sun Aug 31 04:35:21 2008 Tanaka Akira <akr@fsij.org> + + * transcode.c (rb_econv_putback): putback from last byte. + Sun Aug 31 04:27:04 2008 Tanaka Akira <akr@fsij.org> * transcode.c (econv_putback): renamed from econv_primitive_putback. diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 48b22fc27..db7243076 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -485,6 +485,15 @@ class TestEncodingConverter < Test::Unit::TestCase assert_equal(["abcdef", ""], [dst, src]) end + def test_putback2 + ec = Encoding::Converter.new("utf-16le", "euc-jp") + ret = ec.primitive_convert(src="\x00\xd8\x21\x00", dst="", nil, nil) + assert_equal(:invalid_byte_sequence, ret) + assert_equal("\x00", ec.putback(1)) + assert_equal("\x21", ec.putback(1)) + assert_equal("", ec.putback(1)) + end + def test_invalid_replace ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::INVALID_REPLACE) ret = ec.primitive_convert(src="abc\x80def", dst="", nil, 100) diff --git a/transcode.c b/transcode.c index 88ccc9b04..6885bb554 100644 --- a/transcode.c +++ b/transcode.c @@ -1452,7 +1452,7 @@ rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n) if (ec->num_trans == 0 || n == 0) return; tc = ec->elems[0].tc; - memcpy(p, TRANSCODING_READBUF(tc) + tc->recognized_len, n); + memcpy(p, TRANSCODING_READBUF(tc) + tc->recognized_len + tc->readagain_len - n, n); tc->readagain_len -= n; } |
