> With this "else", the parsing breaks at the character ',' which is
> used in the format such as "#,##0.00".
>
> But without this "else", the parsing goes on ignoring any invalid
> characters.
So this is my revised patch. It passes the Mauve test
gnu.testlet.java.text.DecimalFormat.parse and
gnu.testlet.java.text.NumberFormat.position.
Still remains a question: what if ',' appears after '.' or in the exponential
part?
--- java/text/DecimalFormat.java.cp 2007-01-19 09:01:12.000000000 +0900
+++ java/text/DecimalFormat.java 2007-01-19 10:49:51.000000000 +0900
@@ -659,6 +659,7 @@
// correct the size of the end parsing flag
int len = str.length();
if (len < stop) stop = len;
+ char groupingSeparator = symbols.getGroupingSeparator();
int i = start;
while (i < stop)
@@ -672,6 +673,7 @@
}
else if (this.parseIntegerOnly)
{
+ i--;
break;
}
else if (ch == decimalSeparator)
@@ -688,8 +690,19 @@
if (inExponent)
number.append(ch);
else
- break;
- }
+ {
+ i--;
+ break;
+ }
+ }
+ else
+ {
+ if (!groupingUsed || ch != groupingSeparator)
+ {
+ i--;
+ break;
+ }
+ }
}
// 2nd special case: infinity
@@ -749,7 +762,7 @@
if (isNegative) number.insert(0, '-');
- pos.setIndex(i - 1);
+ pos.setIndex(i);
// now we handle the return type
BigDecimal bigDecimal = new BigDecimal(number.toString());