ruby-changes:6982
From: akr <ko1@a...>
Date: Tue, 12 Aug 2008 06:49:54 +0900 (JST)
Subject: [ruby-changes:6982] Ruby:r18500 (trunk): * transcode.c (rb_trans_conv): find second last error.
akr 2008-08-12 06:49:38 +0900 (Tue, 12 Aug 2008) New Revision: 18500 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18500 Log: * transcode.c (rb_trans_conv): find second last error. Modified files: trunk/ChangeLog trunk/test/ruby/test_transcode.rb trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18499) +++ ChangeLog (revision 18500) @@ -1,3 +1,7 @@ +Tue Aug 12 06:48:35 2008 Tanaka Akira <akr@f...> + + * transcode.c (rb_trans_conv): find second last error. + Tue Aug 12 00:43:44 2008 Tanaka Akira <akr@f...> * transcode_data.h (rb_trans_result_t): new type. Index: test/ruby/test_transcode.rb =================================================================== --- test/ruby/test_transcode.rb (revision 18499) +++ test/ruby/test_transcode.rb (revision 18500) @@ -298,6 +298,11 @@ "\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 Index: transcode.c =================================================================== --- transcode.c (revision 18499) +++ transcode.c (revision 18500) @@ -736,7 +736,7 @@ 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 @@ 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; + } } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/