mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 17:56:54 +00:00
ICU-11903 Always propagate zero digit in DecimalFormatSymbols#setZeroDigit().
X-SVN-Rev: 40255
This commit is contained in:
parent
fc823505ae
commit
e9755b9774
2 changed files with 25 additions and 11 deletions
|
@ -185,8 +185,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
/**
|
||||
* Sets the character used for zero.
|
||||
* <p>
|
||||
* <b>Note:</b> When the specified zeroDigit is a Unicode decimal digit character
|
||||
* (category:Nd) and the number value is 0, then this method propagate digit 1 to
|
||||
* <b>Note:</b> This method propagates digit 1 to
|
||||
* digit 9 by incrementing code point one by one.
|
||||
*
|
||||
* @param zeroDigit the zero character.
|
||||
|
@ -205,15 +204,11 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
digitStrings[0] = String.valueOf(zeroDigit);
|
||||
digits[0] = zeroDigit;
|
||||
|
||||
// Propagate digit 1 - 9 only when the input zeroDigit is a
|
||||
// Unicode number and its integer value is 0.
|
||||
|
||||
if (Character.digit(zeroDigit, 10) == 0) {
|
||||
for (int i = 1; i < 10; i++) {
|
||||
char d = (char)(zeroDigit + i);
|
||||
digitStrings[i] = String.valueOf(d);
|
||||
digits[i] = d;
|
||||
}
|
||||
// Always propagate to digits 1-9 for JDK and ICU4C consistency.
|
||||
for (int i = 1; i < 10; i++) {
|
||||
char d = (char)(zeroDigit + i);
|
||||
digitStrings[i] = String.valueOf(d);
|
||||
digits[i] = d;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Locale;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
@ -260,6 +261,24 @@ public class IntlTestDecimalFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropagateZeroDigit() {
|
||||
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
|
||||
dfs.setZeroDigit('\u1040');
|
||||
DecimalFormat df = new DecimalFormat("0");
|
||||
df.setDecimalFormatSymbols(dfs);
|
||||
assertEquals("Should propagate char with number property zero",
|
||||
'\u1041', dfs.getDigits()[1]);
|
||||
assertEquals("Should propagate char with number property zero",
|
||||
"\u1044\u1040\u1041\u1042\u1043", df.format(40123));
|
||||
dfs.setZeroDigit('a');
|
||||
df.setDecimalFormatSymbols(dfs);
|
||||
assertEquals("Should propagate char WITHOUT number property zero",
|
||||
'b', dfs.getDigits()[1]);
|
||||
assertEquals("Should propagate char WITHOUT number property zero",
|
||||
"eabcd", df.format(40123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigitSymbols() {
|
||||
final char defZero = '0';
|
||||
|
|
Loading…
Add table
Reference in a new issue