From: Michael Ow Date: Wed, 6 Jul 2011 17:42:56 +0000 (+0000) Subject: ICU-8664 Use the custom CharsetDecoder's replacement character if one is specified X-Git-Tag: milestone-59-0-1~4676 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d71f5096b102345e57ad0866bd526079e93c6cef;p=icu ICU-8664 Use the custom CharsetDecoder's replacement character if one is specified X-SVN-Rev: 30284 --- diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetCallback.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetCallback.java index d9cc0c2e673..463c8f3fe67 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetCallback.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetCallback.java @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 2006-2010, International Business Machines Corporation and * +* Copyright (C) 2006-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -186,11 +186,18 @@ public class CharsetCallback { char[] buffer, int length, CoderResult cr){ CharsetICU cs = (CharsetICU) decoder.charset(); + /* Use the specified replacement character if it is different than the default one. */ + boolean useReplacement = true; + char [] replacementChar = decoder.replacement().toCharArray(); + if (replacementChar.length == 1 && (replacementChar[0] == kSubstituteChar1[0] || replacementChar[0] == kSubstituteChar[0])) { + useReplacement = false; + } + /* could optimize this case, just one uchar */ if(decoder.invalidCharLength == 1 && cs.subChar1 != 0) { - return CharsetDecoderICU.toUWriteUChars(decoder, kSubstituteChar1, 0, 1, target, offsets, source.position()); + return CharsetDecoderICU.toUWriteUChars(decoder, useReplacement ? replacementChar : kSubstituteChar1, 0, useReplacement ? replacementChar.length : 1, target, offsets, source.position()); } else { - return CharsetDecoderICU.toUWriteUChars(decoder, kSubstituteChar, 0, 1, target, offsets, source.position()); + return CharsetDecoderICU.toUWriteUChars(decoder, useReplacement ? replacementChar : kSubstituteChar, 0, useReplacement ? replacementChar.length : 1, target, offsets, source.position()); } } };