mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-16 10:17:23 +00:00
ICU-8664 Use the custom CharsetDecoder's replacement character if one is specified
X-SVN-Rev: 30284
This commit is contained in:
parent
aac270e4ba
commit
d71f5096b1
1 changed files with 10 additions and 3 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue