ICU-7913 Allow leading zeroes in strict parse in J per PMC agreement

X-SVN-Rev: 29772
This commit is contained in:
John Emmons 2011-04-11 18:56:34 +00:00
parent 68a2af94ca
commit 86004a8f8b
3 changed files with 7 additions and 28 deletions

View File

@ -2136,12 +2136,6 @@ public class DecimalFormat extends NumberFormat {
int lastGroup = -1; // where did we last see a grouping separator?
int gs2 = groupingSize2 == 0 ? groupingSize : groupingSize2;
// Strict parsing leading zeroes. If a leading zero would be forced by the
// pattern, then don't fail strict parsing.
boolean strictLeadingZero = false;
int leadingZeroPos = 0;
int leadingZeroCount = 0;
// equivalent grouping and decimal support
boolean skipExtendedSeparatorParsing = ICUConfig.get(
"com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "false")
@ -2202,14 +2196,6 @@ public class DecimalFormat extends NumberFormat {
// Handle leading zeros
if (digits.count == 0) {
if (!sawDecimal) {
if (strictParse) {
// Allow leading zeros in exponents
// Count leading zeros for checking later
if (!strictLeadingZero)
leadingZeroPos = position + 1;
strictLeadingZero = true;
++leadingZeroCount;
}
// Ignore leading zeros in integer part of number.
continue;
}
@ -2385,13 +2371,6 @@ public class DecimalFormat extends NumberFormat {
digits.decimalAt = digitCount; // Not digits.count!
// check for strict parse errors
if (strictParse && strictLeadingZero) {
if ((leadingZeroCount + digits.decimalAt) > this.getMinimumIntegerDigits()) {
parsePosition.setIndex(oldStart);
parsePosition.setErrorIndex(leadingZeroPos);
return false;
}
}
if (strictParse && !sawDecimal) {
if (lastGroup != -1 && position - lastGroup != groupingSize + 1) {
strictFail = true;

View File

@ -390,9 +390,9 @@ public class IntlTestDecimalFormatAPI extends com.ibm.icu.dev.test.TestFmwk
numstr = "005";
try {
Number n = df.parse(numstr);
errln("ERROR: Expected round trip failure not encountered: numstr -> " + n);
logln("INFO: Successful parse for " + numstr + " with strict parse enabled. Number is " + n);
} catch (ParseException pe) {
logln("INFO: Expected ParseExpection for " + numstr + " with strick parse enabled");
errln("ERROR: Parse Exception encountered in strict mode: numstr -> " + numstr);
}
}

View File

@ -1965,12 +1965,12 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"12345, ", // comma not followed by digit is not a group separator, but end of number
"1,234, ", // if group separator is present, group sizes must be appropriate
"1,234,567", // ...secondary too
"0E", // an exponnent not followed by zero or digits is not an exponent
"0E", // an exponent not followed by zero or digits is not an exponent
"00", // leading zero before zero - used to be error - see ticket #7913
"012", // leading zero before digit - used to be error - see ticket #7913
"0,456", // leading zero before group separator - used to be error - see ticket #7913
};
String[] fail = {
"00", // leading zero before zero
"012", // leading zero before digit
"0,456", // leading zero before group separator
"1,2", // wrong number of digits after group separator
",0", // leading group separator before zero
",1", // leading group separator before digit
@ -1992,9 +1992,9 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"0E2", // single zero before exponent is ok
"1234E2", // any number of digits before exponent is ok
"1,234E", // an exponent string not followed by zero or digits is not an exponent
"00E2", // leading zeroes now allowed in strict mode - see ticket #
};
String[] scientificFail = {
"00E2", // double zeros fail
"1,234E2", // group separators with exponent fail
};