From e74395dce9be7b5a2b484f9d47fa71a9ce30f2fc Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Fri, 6 Apr 2018 21:46:18 +0000 Subject: [PATCH] ICU-13684 Making DecimalMatcher no longer consume trailing grouping separators, which is consistent with previous behavior. X-SVN-Rev: 41207 --- .../com/ibm/icu/impl/number/parse/DecimalMatcher.java | 6 ++++++ .../ibm/icu/dev/data/numberformattestspecification.txt | 6 +++--- .../com/ibm/icu/dev/test/format/NumberFormatTest.java | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/DecimalMatcher.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/DecimalMatcher.java index 5a622611daa..6d97d3dea9c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/DecimalMatcher.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/DecimalMatcher.java @@ -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 diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt b/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt index 1f11f8da7c1..b38a420f2c7 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt @@ -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 diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java index 06ece472110..679031eea23 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java @@ -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()); + } } -- 2.40.0