ICU-13088 Fixing number parsing when a minus sign is is preceded by ignorables in a pattern string.

X-SVN-Rev: 39977
This commit is contained in:
Shane Carr 2017-03-31 21:45:46 +00:00
parent 9c4ef57677
commit 773683046a
3 changed files with 17 additions and 6 deletions

View file

@ -2214,7 +2214,9 @@ public class Parse {
: AffixPatternUtils.nextToken(nextOffsetOrTag, str);
if (firstOffsetOrTag == 0L) firstOffsetOrTag = nextOffsetOrTag;
if (isString ? nextOffsetOrTag >= str.length() : nextOffsetOrTag < 0) {
nextTypeOrCp = -1;
// Integer.MIN_VALUE is an invalid value for either a type or a cp;
// use it to indicate the end of the string.
nextTypeOrCp = Integer.MIN_VALUE;
break;
}
nextTypeOrCp =
@ -2224,7 +2226,7 @@ public class Parse {
if (!isIgnorable(nextTypeOrCp, state)) break;
}
if (nextTypeOrCp == -1) {
if (nextTypeOrCp == Integer.MIN_VALUE) {
// Run at end or string that contains only ignorable characters.
if (codePointEquals(cp, typeOrCp, state)) {
// Step forward and also exit the string if not at very end.
@ -2251,6 +2253,9 @@ public class Parse {
} else if (offsetOrTag == 0) {
// Run at beginning. Go to nonignorable cp.
// FALL THROUGH
// TODO: This branch doesn't work on affix patterns since offsetOrTag != 0 for the first
// element. This is harmless except for possible performance implications of evaluating
// the third case instead of the second.
} else {
// Run in middle.
if (isIgnorable(cp, state)) {
@ -2267,7 +2272,7 @@ public class Parse {
}
// Fall through to the nonignorable code point found above.
assert nextTypeOrCp != -1;
assert nextTypeOrCp != Integer.MIN_VALUE;
typeOrCp = nextTypeOrCp;
offsetOrTag = nextOffsetOrTag;
}

View file

@ -46,9 +46,7 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
logln("Percent test " + localeName);
fNumberFormat = NumberFormat.getPercentInstance(locale);
if (!locale.getLanguage().equals("fa") && !logKnownIssue("13088", "Negative number with percent cannot be parsed in Persian locale")) {
_testFormat();
}
_testFormat();
if (locale.toString().compareTo("en_US_POSIX") != 0 ) {
logln("Scientific test " + localeName);

View file

@ -4984,6 +4984,14 @@ public class NumberFormatTest extends TestFmwk {
assertEquals("Locale 'bg' should not use monetary grouping", "987654,32 лв.", result);
}
@Test
public void Test13088() {
ULocale loc = new ULocale("fa");
double num = -12.34;
NumberFormat numfmt = NumberFormat.getPercentInstance(loc);
expect2(numfmt, num, "‎٪ ‎−۱٬۲۳۴");
}
@Test
public void testPercentZero() {
DecimalFormat df = (DecimalFormat) NumberFormat.getPercentInstance();