From c620dc4e1e778f7837ed9aeebd1fee12d039f4d3 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Thu, 6 Mar 2008 05:07:12 +0000 Subject: [PATCH] ICU-6137 Fixing flushing of CharsetISO2022. Check for errorbuffer when encoding. X-SVN-Rev: 23532 --- icu4j/src/com/ibm/icu/charset/CharsetEncoderICU.java | 2 +- icu4j/src/com/ibm/icu/charset/CharsetISO2022.java | 6 +++--- .../src/com/ibm/icu/dev/test/charset/TestConversion.java | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/icu4j/src/com/ibm/icu/charset/CharsetEncoderICU.java b/icu4j/src/com/ibm/icu/charset/CharsetEncoderICU.java index 79bdef6d11..a9375ccf1d 100644 --- a/icu4j/src/com/ibm/icu/charset/CharsetEncoderICU.java +++ b/icu4j/src/com/ibm/icu/charset/CharsetEncoderICU.java @@ -254,7 +254,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder { * @stable ICU 3.6 */ protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) { - if (!in.hasRemaining()) { + if (!in.hasRemaining() && this.errorBufferLength == 0) { // make sure the errorBuffer is empty // The Java framework should have already substituted what was left. fromUChar32 = 0; //fromUnicodeReset(); diff --git a/icu4j/src/com/ibm/icu/charset/CharsetISO2022.java b/icu4j/src/com/ibm/icu/charset/CharsetISO2022.java index 65f94cc218..6c58a79ab9 100644 --- a/icu4j/src/com/ibm/icu/charset/CharsetISO2022.java +++ b/icu4j/src/com/ibm/icu/charset/CharsetISO2022.java @@ -2203,7 +2203,7 @@ class CharsetISO2022 extends CharsetICU { */ if (!err.isError() && (myConverterData.fromU2022State.g != 0 || myConverterData.fromU2022State.cs[0] != ASCII) && - flush && !source.hasRemaining() && target.hasRemaining() && fromUChar32 == 0) { + flush && !source.hasRemaining() && fromUChar32 == 0) { int sourceIndex; outLen = 0; @@ -2656,7 +2656,7 @@ class CharsetISO2022 extends CharsetICU { * not in ASCII mode * end of input and no truncated input */ - if (!err.isError() && myConverterData.fromU2022State.g != 0 && flush && !source.hasRemaining() && target.hasRemaining() && fromUChar32 == 0) { + if (!err.isError() && myConverterData.fromU2022State.g != 0 && flush && !source.hasRemaining() && fromUChar32 == 0) { int sourceIndex; /* we are switching to ASCII */ @@ -2932,7 +2932,7 @@ class CharsetISO2022 extends CharsetICU { * not in ASCII mode * end of input and no truncated input */ - if (!err.isError() && isTargetByteDBCS && flush && !source.hasRemaining() && target.hasRemaining() && fromUChar32 == 0) { + if (!err.isError() && isTargetByteDBCS && flush && !source.hasRemaining() && fromUChar32 == 0) { int sourceIndex; /* we are switching to ASCII */ diff --git a/icu4j/src/com/ibm/icu/dev/test/charset/TestConversion.java b/icu4j/src/com/ibm/icu/dev/test/charset/TestConversion.java index 90c1dd6c0b..55cd6489fd 100644 --- a/icu4j/src/com/ibm/icu/dev/test/charset/TestConversion.java +++ b/icu4j/src/com/ibm/icu/dev/test/charset/TestConversion.java @@ -359,14 +359,15 @@ public class TestConversion extends ModuleTest { cr = encoder.encode(source, target, currentSourceLimit == sourceLen); if (cr.isUnderflow()) { - if (target.position() == cc.bytes.limit()) { - break; - } if (currentSourceLimit == sourceLen) { + if (target.position() == cc.bytes.limit()) { + // target contains the correct number of bytes + break; + } // Do a final flush for cleanup, then break out // Encode loop, exits with cr==underflow in normal operation. //target.limit(targetLen); - target.limit(cc.bytes.limit()); + target.limit(targetLen); cr = encoder.flush(target); if (cr.isUnderflow()) { // good