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

* transcode.c (rb_trans_conv): find second last error.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-11 21:49:38 +00:00
parent 53fddace54
commit 425098de96
3 changed files with 21 additions and 4 deletions

View file

@ -1,3 +1,7 @@
Tue Aug 12 06:48:35 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (rb_trans_conv): find second last error.
Tue Aug 12 00:43:44 2008 Tanaka Akira <akr@fsij.org> Tue Aug 12 00:43:44 2008 Tanaka Akira <akr@fsij.org>
* transcode_data.h (rb_trans_result_t): new type. * transcode_data.h (rb_trans_result_t): new type.

View file

@ -298,6 +298,11 @@ class TestTranscode < Test::Unit::TestCase
"\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace)) "\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace))
assert_equal("\uFFFD!", assert_equal("\uFFFD!",
"\x8f\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace)) "\x8f\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace))
assert_equal("?",
"\xdc\x00".encode("EUC-JP", "UTF-16BE", :invalid=>:replace), "[ruby-dev:35776]")
assert_equal("ab?cd?ef",
"\0a\0b\xdc\x00\0c\0d\xdf\x00\0e\0f".encode("EUC-JP", "UTF-16BE", :invalid=>:replace))
end end
def test_undef_replace def test_undef_replace

View file

@ -736,7 +736,7 @@ rb_trans_conv(rb_trans_t *ts,
int flags) int flags)
{ {
int i; int i;
int start, err_index; int start, err_index, no_error;
unsigned char empty_buf; unsigned char empty_buf;
unsigned char *empty_ptr = &empty_buf; unsigned char *empty_ptr = &empty_buf;
@ -751,14 +751,22 @@ rb_trans_conv(rb_trans_t *ts,
output_stop = empty_ptr; output_stop = empty_ptr;
} }
no_error = 1;
err_index = -1; err_index = -1;
for (i = ts->num_trans-2; 0 <= i; i--) { for (i = ts->num_trans-1; 0 <= i; i--) {
if (ts->elems[i].last_result == transcode_invalid_input || if (ts->elems[i].last_result == transcode_invalid_input ||
ts->elems[i].last_result == transcode_undefined_conversion) { ts->elems[i].last_result == transcode_undefined_conversion) {
if (no_error) {
/* last error */
no_error = 0;
}
else {
/* second last error */
err_index = i; err_index = i;
break; break;
} }
} }
}
do { do {
start = err_index + 1; start = err_index + 1;