* transcode.c (rb_econv_putback): putback from last byte.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-30 19:36:38 +00:00
Родитель 998a4ec5af
Коммит 97a5808a14
3 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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