]> granicus.if.org Git - icu/commitdiff
ICU-13230 Fixing DecimalFormat parser to ignore grouping separators when there is...
authorShane Carr <shane@unicode.org>
Mon, 19 Jun 2017 21:03:07 +0000 (21:03 +0000)
committerShane Carr <shane@unicode.org>
Mon, 19 Jun 2017 21:03:07 +0000 (21:03 +0000)
X-SVN-Rev: 40181

icu4c/source/test/testdata/numberformattestspecification.txt
icu4j/main/classes/core/src/com/ibm/icu/impl/number/Parse.java
icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatDataDrivenTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index 9858ffe6995c537ee9bd9a22eda51a45210fe86b..69478e4b07290200c43ef360471542d8662ed3dd 100644 (file)
@@ -456,6 +456,29 @@ output     useGrouping
 12,345 1
 12345  0
 
+test grouping used setters in parsing
+set pattern #,##0
+begin
+locale useGrouping     parse   output  breaks
+en_US  1       123,456 123456
+en_US  0       123,456 123
+en_US  1       123.456 123.456
+en_US  0       123.456 123.456
+fr_FR  1       123,456 123.456
+fr_FR  0       123,456 123.456
+// JDK returns 123 here; not sure why.
+fr_FR  1       123.456 123456  K
+fr_FR  0       123.456 123
+
+test no grouping in pattern with parsing
+set pattern 0
+begin
+locale parse   output  breaks
+en_US  123,456 123
+en_US  123.456 123.456
+fr_FR  123,456 123.456
+fr_FR  123.456 123
+
 test grouping setters
 set locale en_US
 set pattern 0
index 7477089f5a8929ed72d34736449a38bb430d19b7..b4be09621d13c1d7d0692c4be4dd64162fc97f6b 100644 (file)
@@ -1095,6 +1095,7 @@ public class Parse {
     if (mode == null) mode = ParseMode.LENIENT;
     boolean integerOnly = properties.getParseIntegerOnly();
     boolean ignoreExponent = properties.getParseNoExponent();
+    boolean ignoreGrouping = properties.getGroupingSize() < 0;
 
     // Set up the initial state
     ParserState state = threadLocalParseState.get().clear();
@@ -1175,8 +1176,10 @@ public class Parse {
               acceptPrefix(cp, StateName.AFTER_PREFIX, state, item);
             }
             if (mode == ParseMode.LENIENT || mode == ParseMode.FAST) {
-              acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
-              if (state.length > 0 && mode == ParseMode.FAST) break;
+              if (!ignoreGrouping) {
+                acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
+                if (state.length > 0 && mode == ParseMode.FAST) break;
+              }
               if (parseCurrency) {
                 acceptCurrency(cp, StateName.BEFORE_PREFIX, state, item);
               }
@@ -1195,7 +1198,9 @@ public class Parse {
             }
             if (mode == ParseMode.LENIENT || mode == ParseMode.FAST) {
               acceptWhitespace(cp, StateName.AFTER_PREFIX, state, item);
-              acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
+              if (!ignoreGrouping) {
+                acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
+              }
               if (parseCurrency) {
                 acceptCurrency(cp, StateName.AFTER_PREFIX, state, item);
               }
@@ -1210,8 +1215,10 @@ public class Parse {
               acceptDecimalPoint(cp, StateName.AFTER_FRACTION_DIGIT, state, item);
               if (state.length > 0 && mode == ParseMode.FAST) break;
             }
-            acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
-            if (state.length > 0 && mode == ParseMode.FAST) break;
+            if (!ignoreGrouping) {
+              acceptGrouping(cp, StateName.AFTER_INTEGER_DIGIT, state, item);
+              if (state.length > 0 && mode == ParseMode.FAST) break;
+            }
             acceptBidi(cp, StateName.BEFORE_SUFFIX, state, item);
             if (state.length > 0 && mode == ParseMode.FAST) break;
             acceptPadding(cp, StateName.BEFORE_SUFFIX, state, item);
index 9858ffe6995c537ee9bd9a22eda51a45210fe86b..69478e4b07290200c43ef360471542d8662ed3dd 100644 (file)
@@ -456,6 +456,29 @@ output     useGrouping
 12,345 1
 12345  0
 
+test grouping used setters in parsing
+set pattern #,##0
+begin
+locale useGrouping     parse   output  breaks
+en_US  1       123,456 123456
+en_US  0       123,456 123
+en_US  1       123.456 123.456
+en_US  0       123.456 123.456
+fr_FR  1       123,456 123.456
+fr_FR  0       123,456 123.456
+// JDK returns 123 here; not sure why.
+fr_FR  1       123.456 123456  K
+fr_FR  0       123.456 123
+
+test no grouping in pattern with parsing
+set pattern 0
+begin
+locale parse   output  breaks
+en_US  123,456 123
+en_US  123.456 123.456
+fr_FR  123,456 123.456
+fr_FR  123.456 123
+
 test grouping setters
 set locale en_US
 set pattern 0
index 2e5d639c4353a42215e3326e2e6307faf260c66e..58fb5f8b38c1991e85a9d656116476642360d7dc 100644 (file)
@@ -697,8 +697,8 @@ public class NumberFormatDataDrivenTest {
             properties.setMaximumSignificantDigits(tuple.maxSigDigits);
           }
           if (tuple.useGrouping != null && tuple.useGrouping == 0) {
-            properties.setGroupingSize(Integer.MAX_VALUE);
-            properties.setSecondaryGroupingSize(Integer.MAX_VALUE);
+            properties.setGroupingSize(-1);
+            properties.setSecondaryGroupingSize(-1);
           }
           if (tuple.multiplier != null) {
             properties.setMultiplier(new BigDecimal(tuple.multiplier));
index 8390a0e3526ddf01538811b5a2c85533666cc3bc..312e70c3da11a13daa38966b5436b28f3885232e 100644 (file)
@@ -4952,7 +4952,7 @@ public class NumberFormatTest extends TestFmwk {
     @Test
     public void Test11739() {
         NumberFormat nf = NumberFormat.getCurrencyInstance(new ULocale("sr_BA"));
-        ((DecimalFormat) nf).applyPattern("0.0 ¤¤¤");
+        ((DecimalFormat) nf).applyPattern("#,##0.0 ¤¤¤");
         ParsePosition ppos = new ParsePosition(0);
         CurrencyAmount result = nf.parseCurrency("1.500 амерички долар", ppos);
         assertEquals("Should parse to 1500 USD", new CurrencyAmount(1500, Currency.getInstance("USD")), result);