if (isStrict) {
parser->addMatcher(parser->fLocalValidators.affix = {});
}
- if (isStrict && properties.minimumExponentDigits > 0) {
- parser->addMatcher(parser->fLocalValidators.exponent = {});
- }
if (parseCurrency) {
parser->addMatcher(parser->fLocalValidators.currency = {});
}
RequireAffixValidator affix;
RequireCurrencyValidator currency;
RequireDecimalSeparatorValidator decimalSeparator;
- RequireExponentValidator exponent;
RequireNumberValidator number;
MultiplierParseHandler multiplier;
} fLocalValidators;
}
-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()) {
};
-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;
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);
}
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;
}
}
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);
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};
void Test11868();
void Test11739_ParseLongCurrency();
void Test13035_MultiCodePointPaddingInPattern();
+ void Test13737_ParseScientificStrict();
void Test10727_RoundingZero();
void Test11376_getAndSetPositivePrefix();
void Test11475_signRecognition();
(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
if (isStrict) {
parser.addMatcher(new RequireAffixValidator());
}
- if (isStrict && properties.getMinimumExponentDigits() > 0) {
- parser.addMatcher(new RequireExponentValidator());
- }
if (parseCurrency) {
parser.addMatcher(new RequireCurrencyValidator());
}
+++ /dev/null
-// © 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>";
- }
-
-}
(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
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
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