]> granicus.if.org Git - icu/commitdiff
ICU-13684 Making DecimalMatcher no longer consume trailing grouping separators, which...
authorShane Carr <shane@unicode.org>
Fri, 6 Apr 2018 21:46:18 +0000 (21:46 +0000)
committerShane Carr <shane@unicode.org>
Fri, 6 Apr 2018 21:46:18 +0000 (21:46 +0000)
X-SVN-Rev: 41207

icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/DecimalMatcher.java
icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index 5a622611daa5f78b5f6deeb6727881ba75dc06c8..6d97d3dea9c1e6fa8813389fef5e0183b5c03b14 100644 (file)
@@ -278,6 +278,12 @@ public class DecimalMatcher implements NumberParseMatcher {
             break;
         }
 
+        // Back up if there was a trailing grouping separator
+        if (backupOffset != -1) {
+            segment.setOffset(backupOffset);
+            hasPartialPrefix = true; // redundant with `groupingOverlap == segment.length()`
+        }
+
         // Check the final grouping for validity
         if (requireGroupingMatch
                 && !seenDecimal
index 1f11f8da7c12ac94540726f813402956f90f4604..b38a420f2c7d142a54b113a0266c16b61bc6005f 100644 (file)
@@ -743,7 +743,7 @@ parse       output  breaks
 (34  25E-1)    -342.5  K
 (34,,25E-1)    -342.5
 // J doesn't allow trailing separators before E but C does
-(34,,25,E-1)   -342.5  J
+(34,,25,E-1)   -342.5  JP
 (34  25 E-1)   -342.5  JK
 (34,,25 E-1)   -342.5  CJK
 // Spaces are not allowed after exponent symbol
@@ -807,8 +807,8 @@ parse       output  breaks
 // C parses until trailing separators, but sees -1234
 1,234,,,+      1234    JKC
 1,234- -1234
-// J bails because of trailing separators
-1,234,-        -1234   J
+// J and P bail because of trailing separators
+1,234,-        -1234   JP
 // J bails here too
 1234  -        -1234   J
 
index 06ece4721106b764da6d4699a89cefb81029bdd7..679031eea236424052c259abdcabaa27dfff7ee2 100644 (file)
@@ -5984,4 +5984,14 @@ public class NumberFormatTest extends TestFmwk {
         expect2(df, 45, "USD 45.00");
         expect2(df, -45, "-45.00 USD");
     }
+
+    @Test
+    public void test13684_FrenchPercentParsing() {
+        NumberFormat numberFormat = NumberFormat.getPercentInstance(ULocale.FRENCH);
+        numberFormat.setParseStrict(true);
+        ParsePosition ppos = new ParsePosition(0);
+        Number percentage = numberFormat.parse("8\u00A0%", ppos);
+        assertEquals("Should parse successfully", 0.08, percentage.doubleValue());
+        assertEquals("Should consume whole string", 3, ppos.getIndex());
+    }
 }