mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 14:31:31 +00:00
ICU-20347 In ICU4J, parsing emoty string should set PARSE_ERROR as before; check ICU4J behavior
This commit is contained in:
parent
57d07d3ec3
commit
e8bcc60d6f
3 changed files with 21 additions and 0 deletions
|
@ -715,6 +715,10 @@ void DecimalFormat::parse(const UnicodeString& text, Formattable& output,
|
|||
return;
|
||||
}
|
||||
if (parsePosition.getIndex() < 0 || parsePosition.getIndex() >= text.length()) {
|
||||
if (parsePosition.getIndex() == text.length()) {
|
||||
// If there is nothing to parse, it is an error
|
||||
parsePosition.setErrorIndex(parsePosition.getIndex());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3106,6 +3106,8 @@ static const ParseCaseItem parseCaseItems[] = {
|
|||
{ "en", u"0,000", TRUE, FALSE, U_ZERO_ERROR, 5, 0, U_ZERO_ERROR, 5, 0.0, U_ZERO_ERROR, 5, "0" },
|
||||
{ "en", u"1000,000", FALSE, FALSE, U_PARSE_ERROR, 0, 0, U_PARSE_ERROR, 0, 0.0, U_PARSE_ERROR, 0, "" },
|
||||
{ "en", u"1000,000", TRUE, FALSE, U_ZERO_ERROR, 8, 1000000, U_ZERO_ERROR, 8, 1000000.0, U_ZERO_ERROR, 8, "1000000" },
|
||||
{ "en", u"", FALSE, FALSE, U_PARSE_ERROR, 0, 0, U_PARSE_ERROR, 0, 0.0, U_PARSE_ERROR, 0, "" },
|
||||
{ "en", u"", TRUE, FALSE, U_PARSE_ERROR, 0, 0, U_PARSE_ERROR, 0, 0.0, U_PARSE_ERROR, 0, "" },
|
||||
{ "en", u"9999990000503021", FALSE, FALSE, U_INVALID_FORMAT_ERROR, 16, 2147483647, U_ZERO_ERROR, 16, 9999990000503020.0, U_ZERO_ERROR, 16, "9999990000503021" },
|
||||
{ "en", u"9999990000503021", FALSE, TRUE, U_INVALID_FORMAT_ERROR, 16, 2147483647, U_ZERO_ERROR, 16, 9999990000503020.0, U_ZERO_ERROR, 16, "9999990000503021" },
|
||||
{ "en", u"1000000.5", FALSE, FALSE, U_ZERO_ERROR, 9, 1000000, U_ZERO_ERROR, 9, 1000000.5, U_ZERO_ERROR, 9, "1.0000005E+6"},
|
||||
|
|
|
@ -1730,6 +1730,21 @@ public class NumberFormatTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestParseEmpty(){
|
||||
String parsetxt = "";
|
||||
NumberFormat numfmt = NumberFormat.getInstance(new ULocale("en_US"), NumberFormat.NUMBERSTYLE);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
Number value = null;
|
||||
try {
|
||||
value = numfmt.parse(parsetxt, ppos);
|
||||
// Currently this succeeds (no exception) but returns null (for value).
|
||||
logln("NumberFormat.parse empty string succeeds, ppos " + ppos.getIndex() + ", value " + value);
|
||||
} catch (IllegalArgumentException e){
|
||||
logln("NumberFormat.parse empty string sets IllegalArgumentException, ppos " + ppos.getIndex() + ", value " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestParseNull() throws ParseException {
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
|
|
Loading…
Add table
Reference in a new issue