diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-11 21:49:38 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-11 21:49:38 +0000 |
| commit | 93a873eca85a3c80cd19d3de3ad70285bef709b3 (patch) | |
| tree | 968425bf1e5da02ad58faf2997ff2df9381793fc | |
| parent | bc805eab0383cab42abd746879ccf567c24e4c8d (diff) | |
| download | ruby-93a873eca85a3c80cd19d3de3ad70285bef709b3.tar.gz ruby-93a873eca85a3c80cd19d3de3ad70285bef709b3.tar.xz ruby-93a873eca85a3c80cd19d3de3ad70285bef709b3.zip | |
* transcode.c (rb_trans_conv): find second last error.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | test/ruby/test_transcode.rb | 5 | ||||
| -rw-r--r-- | transcode.c | 16 |
3 files changed, 21 insertions, 4 deletions
@@ -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> * transcode_data.h (rb_trans_result_t): new type. diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index deffee58f..8664f443a 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -298,6 +298,11 @@ class TestTranscode < Test::Unit::TestCase "\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace)) assert_equal("\uFFFD!", "\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 def test_undef_replace diff --git a/transcode.c b/transcode.c index b01903cdb..a733a054a 100644 --- a/transcode.c +++ b/transcode.c @@ -736,7 +736,7 @@ rb_trans_conv(rb_trans_t *ts, int flags) { int i; - int start, err_index; + int start, err_index, no_error; unsigned char empty_buf; unsigned char *empty_ptr = &empty_buf; @@ -751,12 +751,20 @@ rb_trans_conv(rb_trans_t *ts, output_stop = empty_ptr; } + no_error = 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 || ts->elems[i].last_result == transcode_undefined_conversion) { - err_index = i; - break; + if (no_error) { + /* last error */ + no_error = 0; + } + else { + /* second last error */ + err_index = i; + break; + } } } |
