ICU-13737 Backpedaling on strict mode scientific parsing behavior change (do NOT...
authorShane Carr <shane@unicode.org>
Tue, 15 May 2018 21:14:09 +0000 (21:14 +0000)
committerShane Carr <shane@unicode.org>
Tue, 15 May 2018 21:14:09 +0000 (21:14 +0000)
X-SVN-Rev: 41378

12 files changed:
icu4c/source/i18n/numparse_impl.cpp
icu4c/source/i18n/numparse_impl.h
icu4c/source/i18n/numparse_validators.cpp
icu4c/source/i18n/numparse_validators.h
icu4c/source/io/locbund.cpp
icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/intltest/numfmtst.h
icu4c/source/test/testdata/numberformattestspecification.txt
icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/NumberParserImpl.java
icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/RequireExponentValidator.java [deleted file]
icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index ecb878fbe7d419999ae612601b5d54bb76699761..79f02cdfa8c6f0c008c805bfe3ce288cb709551b 100644 (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 = {});
     }
index 63c04802441197fbffa63cfbf79aa1b3a0844b70..0fd58e549254de634ed3cda533cb376bd9d5cf07 100644 (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;
index 6e9632588bb7cfe29eb8a15d3b82890e62aed56d..4fbe07e087cda81daae92245d7931409412794d6 100644 (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()) {
index 1479d897bb9739f83129eb76be784d0068956475..cf989d57579502dea91a819b66472b8be88c1780 100644 (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;
index 1b9999854e50b1fd571f08a7ea539f7619b59aa6..8e880b17cf2af11054478958dd9fc969f92d9ada 100644 (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;
                 }
             }
index 2d22e20a0b8987c6ed396c8dab7ad07583b07744..982b261ab0727bbb579e690166e7eca97630d29a 100644 (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};
index 57afe131e75300643bc384e05f48c7eaf3e34980..79d55043b111fdfab771ed6894ab3616eaa0233e 100644 (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();
index 3dfe7f73302c2dfa57caee13263192649eaadedd..23be52502a94cdfd45b5d80d0663ea8614a28a82 100644 (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
index 274cd8847a192cb91f14bc7a1e3329a2bfa4f6cb..9b0cb96d1e1a64364cb7d3c8856d01e5f951af77 100644 (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());
         }
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/RequireExponentValidator.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/RequireExponentValidator.java
deleted file mode 100644 (file)
index a9fd72d..0000000
+++ /dev/null
@@ -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>";
-    }
-
-}
index d1e71388d3e1e1bb02112827a7c100634e4eeb56..549550742d251cbbd978047b5ec98185931e2e3f 100644 (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
index feaf41821b9ba60ef12e52546ac28c090a221fd4..a5d2aea11c6c6496fe6f46472b41c8e614592da8 100644 (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