mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-9109 Fixed missing digit issue with DecimalFormat in lenient mode.
X-SVN-Rev: 31391
This commit is contained in:
parent
65fa708be4
commit
535e2f80d5
3 changed files with 34 additions and 5 deletions
|
@ -1617,8 +1617,8 @@ void DecimalFormat::parse(const UnicodeString& text,
|
|||
Formattable& result,
|
||||
ParsePosition& parsePosition,
|
||||
UBool parseCurrency) const {
|
||||
int32_t backup;
|
||||
int32_t i = backup = parsePosition.getIndex();
|
||||
int32_t startIdx, backup;
|
||||
int32_t i = startIdx = backup = parsePosition.getIndex();
|
||||
|
||||
// clear any old contents in the result. In particular, clears any DigitList
|
||||
// that it may be holding.
|
||||
|
@ -1677,7 +1677,7 @@ void DecimalFormat::parse(const UnicodeString& text,
|
|||
fPosPrefixPattern, fPosSuffixPattern,
|
||||
FALSE, UCURR_SYMBOL_NAME,
|
||||
parsePosition, *digits, status, currency)) {
|
||||
parsePosition.setIndex(backup);
|
||||
parsePosition.setIndex(startIdx);
|
||||
delete digits;
|
||||
return;
|
||||
}
|
||||
|
@ -1899,6 +1899,9 @@ UBool DecimalFormat::subparse(const UnicodeString& text,
|
|||
} else if (strictParse){
|
||||
parsePosition.setErrorIndex(position);
|
||||
return FALSE;
|
||||
} else {
|
||||
// Temporary set positive. This might be changed after checking suffix
|
||||
parsedNum.append('+', err);
|
||||
}
|
||||
|
||||
// Match padding before prefix
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***********************************************************************
|
||||
* Copyright (c) 1997-2011, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
***********************************************************************/
|
||||
|
||||
|
@ -169,6 +169,7 @@ NumberFormatRegressionTest::runIndexedTest( int32_t index, UBool exec, const cha
|
|||
CASE(59,Test4243108);
|
||||
CASE(60,TestJ691);
|
||||
CASE(61,Test8199);
|
||||
CASE(62,Test9109);
|
||||
|
||||
default: name = ""; break;
|
||||
}
|
||||
|
@ -2826,5 +2827,29 @@ void NumberFormatRegressionTest::Test8199(void) {
|
|||
delete nf;
|
||||
}
|
||||
|
||||
void NumberFormatRegressionTest::Test9109(void) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Formattable val;
|
||||
ParsePosition pos;
|
||||
DecimalFormat fmt("+##", status);
|
||||
fmt.setLenient(TRUE);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failed to create DecimalFormat with pattern '+##'");
|
||||
}
|
||||
|
||||
UnicodeString text("123");
|
||||
int32_t expected = 123;
|
||||
int32_t expos = 3;
|
||||
|
||||
fmt.parse(text, val, pos);
|
||||
if (pos.getErrorIndex() >= 0) {
|
||||
errln(UnicodeString("Parse failure at ") + pos.getErrorIndex());
|
||||
} else if (val.getLong() != 123) {
|
||||
errln(UnicodeString("Incorrect parse result: ") + val.getLong() + " expected: " + expected);
|
||||
} else if (pos.getIndex() != 3) {
|
||||
errln(UnicodeString("Incorrect parse position: ") + pos.getIndex() + " expected: " + expos);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2011, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
***********************************************************************/
|
||||
|
||||
|
@ -91,6 +91,7 @@ public:
|
|||
void Test4243108(void);
|
||||
void TestJ691(void);
|
||||
void Test8199(void);
|
||||
void Test9109(void);
|
||||
|
||||
protected:
|
||||
UBool failure(UErrorCode status, const UnicodeString& msg, UBool possibleDataError=FALSE);
|
||||
|
|
Loading…
Add table
Reference in a new issue