// ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
// and to maintain regressive behavior, divide by 100 even if no percent sign is present.
- if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
+ if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
}
- if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
+ if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
}
TESTCASE_AUTO(Test11645_ApplyPatternEquality);
TESTCASE_AUTO(Test12567);
TESTCASE_AUTO(Test11626_CustomizeCurrencyPluralInfo);
+ TESTCASE_AUTO(Test20073_StrictPercentParseErrorIndex);
TESTCASE_AUTO(Test13056_GroupingSize);
TESTCASE_AUTO(Test11025_CurrencyPadding);
TESTCASE_AUTO(Test11648_ExpDecFormatMalPattern);
assertEquals("Plural other", u"99 америчких долара", df.format(99, result.remove(), errorCode));
}
+void NumberFormatTest::Test20073_StrictPercentParseErrorIndex() {
+ IcuTestErrorCode status(*this, "Test20073_StrictPercentParseErrorIndex");
+ ParsePosition parsePosition(0);
+ DecimalFormat df(u"0%", {"en-us", status}, status);
+ df.setLenient(FALSE);
+ Formattable result;
+ df.parse(u"%2%", result, parsePosition);
+ assertEquals("", 0, parsePosition.getIndex());
+ assertEquals("", 0, parsePosition.getErrorIndex());
+}
+
void NumberFormatTest::Test13056_GroupingSize() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat df(u"#,##0", status);
void Test11645_ApplyPatternEquality();
void Test12567();
void Test11626_CustomizeCurrencyPluralInfo();
+ void Test20073_StrictPercentParseErrorIndex();
void Test13056_GroupingSize();
void Test11025_CurrencyPadding();
void Test11648_ExpDecFormatMalPattern();
// ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
// and to maintain regressive behavior, divide by 100 even if no percent sign is present.
- if (affixProvider.containsSymbolType(AffixUtils.TYPE_PERCENT)) {
+ if (!isStrict && affixProvider.containsSymbolType(AffixUtils.TYPE_PERCENT)) {
parser.addMatcher(PercentMatcher.getInstance(symbols));
}
- if (affixProvider.containsSymbolType(AffixUtils.TYPE_PERMILLE)) {
+ if (!isStrict && affixProvider.containsSymbolType(AffixUtils.TYPE_PERMILLE)) {
parser.addMatcher(PermilleMatcher.getInstance(symbols));
}
* The parser settings defined in the PARSE_FLAG_* fields.
*/
public NumberParserImpl(int parseFlags) {
- matchers = new ArrayList<NumberParseMatcher>();
+ matchers = new ArrayList<>();
this.parseFlags = parseFlags;
frozen = false;
}
}
}
+ @Test
+ public void Test20073_StrictPercentParseErrorIndex() {
+ ParsePosition parsePosition = new ParsePosition(0);
+ DecimalFormat df = new DecimalFormat("0%", DecimalFormatSymbols.getInstance(Locale.US));
+ df.setParseStrict(true);
+ Number number = df.parse("%2%", parsePosition);
+ assertNull("", number);
+ assertEquals("", 0, parsePosition.getIndex());
+ assertEquals("", 0, parsePosition.getErrorIndex());
+ }
+
@Test
public void Test11626_CustomizeCurrencyPluralInfo() throws ParseException {
// Use locale sr because it has interesting plural rules.