ICU-13737 Backpedaling on strict mode scientific parsing behavior change (do NOT require an exponent when parsing).

X-SVN-Rev: 41378
This commit is contained in:
Shane Carr 2018-05-15 21:14:09 +00:00
parent b347a140ec
commit cb34c90168
12 changed files with 29 additions and 63 deletions

View File

@ -195,9 +195,6 @@ NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
if (isStrict) {
parser->addMatcher(parser->fLocalValidators.affix = {});
}
if (isStrict && properties.minimumExponentDigits > 0) {
parser->addMatcher(parser->fLocalValidators.exponent = {});
}
if (parseCurrency) {
parser->addMatcher(parser->fLocalValidators.currency = {});
}

View File

@ -87,7 +87,6 @@ class U_I18N_API NumberParserImpl : public MutableMatcherCollection {
RequireAffixValidator affix;
RequireCurrencyValidator currency;
RequireDecimalSeparatorValidator decimalSeparator;
RequireExponentValidator exponent;
RequireNumberValidator number;
MultiplierParseHandler multiplier;
} fLocalValidators;

View File

@ -57,17 +57,6 @@ UnicodeString RequireDecimalSeparatorValidator::toString() const {
}
void RequireExponentValidator::postProcess(ParsedNumber& result) const {
if (0 == (result.flags & FLAG_HAS_EXPONENT)) {
result.flags |= FLAG_FAIL;
}
}
UnicodeString RequireExponentValidator::toString() const {
return u"<ReqExponent>";
}
void RequireNumberValidator::postProcess(ParsedNumber& result) const {
// Require that a number is matched.
if (!result.seenNumber()) {

View File

@ -61,14 +61,6 @@ class RequireDecimalSeparatorValidator : public ValidationMatcher, public UMemor
};
class RequireExponentValidator : public ValidationMatcher, public UMemory {
public:
void postProcess(ParsedNumber& result) const U_OVERRIDE;
UnicodeString toString() const U_OVERRIDE;
};
class RequireNumberValidator : public ValidationMatcher, public UMemory {
public:
void postProcess(ParsedNumber& result) const U_OVERRIDE;

View File

@ -54,10 +54,6 @@ static inline UNumberFormat * copyInvariantFormatter(ULocaleBundle *result, UNum
UErrorCode status = U_ZERO_ERROR;
UNumberFormat *formatAlias = unum_open(style, NULL, 0, "en_US_POSIX", NULL, &status);
if (U_SUCCESS(status)) {
// ICU 62 requires exponent on strict scientific parser, but we don't want that here
if (style == UNUM_SCIENTIFIC) {
unum_setAttribute(formatAlias, UNUM_LENIENT_PARSE, TRUE);
}
gPosixNumberFormat[style-1] = formatAlias;
ucln_io_registerCleanup(UCLN_IO_LOCBUND, locbund_cleanup);
}
@ -178,10 +174,6 @@ u_locbund_getNumberFormat(ULocaleBundle *bundle, UNumberFormatStyle style)
formatAlias = NULL;
}
else {
// ICU 62 requires exponent on strict scientific parser, but we don't want that here
if (style == UNUM_SCIENTIFIC) {
unum_setAttribute(formatAlias, UNUM_LENIENT_PARSE, TRUE);
}
bundle->fNumberFormat[style-1] = formatAlias;
}
}

View File

@ -652,6 +652,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
TESTCASE_AUTO(Test11868);
TESTCASE_AUTO(Test11739_ParseLongCurrency);
TESTCASE_AUTO(Test13035_MultiCodePointPaddingInPattern);
TESTCASE_AUTO(Test13737_ParseScientificStrict);
TESTCASE_AUTO(Test10727_RoundingZero);
TESTCASE_AUTO(Test11376_getAndSetPositivePrefix);
TESTCASE_AUTO(Test11475_signRecognition);
@ -8845,6 +8846,14 @@ void NumberFormatTest::Test13035_MultiCodePointPaddingInPattern() {
assertEquals("Quote should be escapable in padding syntax", "a''12b", result);
}
void NumberFormatTest::Test13737_ParseScientificStrict() {
IcuTestErrorCode status(*this, "Test13737_ParseScientificStrict");
LocalPointer<NumberFormat> df(NumberFormat::createScientificInstance("en", status));
df->setLenient(FALSE);
// Parse Test
expect(*df, u"1.2", 1.2);
}
void NumberFormatTest::Test11376_getAndSetPositivePrefix() {
{
const UChar USD[] = {0x55, 0x53, 0x44, 0x0};

View File

@ -214,6 +214,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
void Test11868();
void Test11739_ParseLongCurrency();
void Test13035_MultiCodePointPaddingInPattern();
void Test13737_ParseScientificStrict();
void Test10727_RoundingZero();
void Test11376_getAndSetPositivePrefix();
void Test11475_signRecognition();

View File

@ -877,15 +877,16 @@ parse output breaks
(1,945d1) fail K
test parse strict scientific
// See #13737: Old behavior should be retained in this case
set locale en
set pattern #E0
set lenient 0
begin
parse output breaks
123 fail JK
123 123
123E1 1230
123E0 123
123E fail JK
123E 123
test parse strict without prefix/suffix
set locale en

View File

@ -242,9 +242,6 @@ public class NumberParserImpl {
if (isStrict) {
parser.addMatcher(new RequireAffixValidator());
}
if (isStrict && properties.getMinimumExponentDigits() > 0) {
parser.addMatcher(new RequireExponentValidator());
}
if (parseCurrency) {
parser.addMatcher(new RequireCurrencyValidator());
}

View File

@ -1,23 +0,0 @@
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html#License
package com.ibm.icu.impl.number.parse;
/**
* @author sffc
*
*/
public class RequireExponentValidator extends ValidationMatcher {
@Override
public void postProcess(ParsedNumber result) {
if (0 == (result.flags & ParsedNumber.FLAG_HAS_EXPONENT)) {
result.flags |= ParsedNumber.FLAG_FAIL;
}
}
@Override
public String toString() {
return "<RequireExponent>";
}
}

View File

@ -870,15 +870,16 @@ parse output breaks
(1,945d1) fail K
test parse strict scientific
// See #13737: Old behavior should be retained in this case
set locale en
set pattern #E0
set lenient 0
begin
parse output breaks
123 fail CJK
123 123
123E1 1230
123E0 123
123E fail CJK
123E 123
test parse strict without prefix/suffix
set locale en

View File

@ -5502,10 +5502,13 @@ public class NumberFormatTest extends TestFmwk {
assertEquals("Should consume the whole number", 5, ppos.getIndex());
ppos.setIndex(0);
result0 = df.parse("123", ppos);
assertNull("Should reject number without exponent", result0);
// #13737: For backwards compatibility, do NOT require the exponent.
assertEquals("Should NOT reject number without exponent", 123L, result0);
ppos.setIndex(0);
CurrencyAmount result1 = df.parseCurrency("USD123", ppos);
assertNull("Should reject currency without exponent", result1);
assertEquals("Should NOT reject currency without exponent",
new CurrencyAmount(123L, Currency.getInstance("USD")),
result1);
}
@Test
@ -5573,6 +5576,14 @@ public class NumberFormatTest extends TestFmwk {
assertEquals("Quote should be escapable in padding syntax", "a''12b", result);
}
@Test
public void Test13737_ParseScientificStrict() {
NumberFormat df = NumberFormat.getScientificInstance(ULocale.ENGLISH);
df.setParseStrict(true);
// Parse Test: exponent is not required, even in strict mode
expect(df, "1.2", 1.2);
}
// TODO: Investigate this test and re-enable if appropriate.
@Test
@Ignore