]> granicus.if.org Git - icu/commitdiff
ICU-11903 Always propagate zero digit in DecimalFormatSymbols#setZeroDigit().
authorShane Carr <shane@unicode.org>
Wed, 12 Jul 2017 10:17:57 +0000 (10:17 +0000)
committerShane Carr <shane@unicode.org>
Wed, 12 Jul 2017 10:17:57 +0000 (10:17 +0000)
X-SVN-Rev: 40255

icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java

index 07e812bcd2a8555aa5aa337826f9802ae3e5a31b..8daac03210482e879f3f985de447199e99048b51 100644 (file)
@@ -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;
         }
     }
 
index 56688a236b9d414d557e8dd6ae9dcc405802efb1..2180a789c6f4238364d44231994f924252733204 100644 (file)
@@ -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';