]> granicus.if.org Git - icu/commitdiff
ICU-8664 Use the custom CharsetDecoder's replacement character if one is specified
authorMichael Ow <mow@svn.icu-project.org>
Wed, 6 Jul 2011 17:42:56 +0000 (17:42 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Wed, 6 Jul 2011 17:42:56 +0000 (17:42 +0000)
X-SVN-Rev: 30284

icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetCallback.java

index d9cc0c2e673cc69b9dfa2f88821927cbd587cb58..463c8f3fe670737a8aff88e25c91d234c1ace031 100644 (file)
@@ -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());
             }
         }
     };