boolean strictParse = isParseStrict();
boolean strictFail = false; // did we exit with a strict parse failure?
int lastGroup = -1; // where did we last see a grouping separator?
+ int digitStart = position; // where did the digit start?
int gs2 = groupingSize2 == 0 ? groupingSize : groupingSize2;
// equivalent grouping and decimal support
// group. If there was a group separator before that, the group
// must == the secondary group length, else it can be <= the the
// secondary group length.
- if ((lastGroup != -1 && countCodePoints(text,lastGroup,backup) - 1 != gs2)
- || (lastGroup == -1 && countCodePoints(text,oldStart,position) - 1 > gs2)) {
+ if ((lastGroup != -1 && countCodePoints(text, lastGroup, backup) - 1 != gs2)
+ || (lastGroup == -1 && countCodePoints(text, digitStart, position) - 1 > gs2)) {
strictFail = true;
break;
}
{
if (strictParse) {
if (backup != -1) {
- if ((lastGroup != -1 && countCodePoints(text,lastGroup,backup) - 1 != gs2)
- || (lastGroup == -1 && countCodePoints(text,oldStart,position) - 1 > gs2)) {
+ if ((lastGroup != -1 && countCodePoints(text, lastGroup, backup) - 1 != gs2)
+ || (lastGroup == -1 && countCodePoints(text, digitStart, position) - 1 > gs2)) {
strictFail = true;
break;
}
/*
*******************************************************************************
- * Copyright (C) 2001-2011, International Business Machines Corporation and *
+ * Copyright (C) 2001-2012, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import java.io.IOException;
import java.io.ObjectInputStream;
import java.text.ParseException;
+import java.text.ParsePosition;
import java.util.Date;
import java.util.Locale;
checkNBSPPatternRT(testcase, nf);
}
-
+
+ /*
+ * Test case for #9293
+ * Parsing currency in strict mode
+ */
+ public void TestT9293() {
+ NumberFormat fmt = NumberFormat.getCurrencyInstance();
+ fmt.setParseStrict(true);
+
+ final int val = 123456;
+ String txt = fmt.format(123456);
+
+ ParsePosition pos = new ParsePosition(0);
+ Number num = fmt.parse(txt, pos);
+
+ if (pos.getErrorIndex() >= 0) {
+ errln("FAIL: Parsing " + txt + " - error index: " + pos.getErrorIndex());
+ } else if (val != num.intValue()) {
+ errln("FAIL: Parsed result: " + num + " - expected: " + val);
+ }
+ }
}