]> granicus.if.org Git - icu/commitdiff
ICU-13696 Parse local currency ISO codes as case-insensitive. (#62)
authorShane <sffc@sffc1.com>
Tue, 21 Aug 2018 00:41:36 +0000 (17:41 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:38 +0000 (14:27 -0700)
icu4c/source/i18n/numparse_currency.cpp
icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/testdata/numberformattestspecification.txt
icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/CombinedCurrencyMatcher.java
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 ae8196ec483799f0ec1fd328bab1110e60d0d30d..598ace56533c36ab8ee64934bc470d98b4e3414d 100644 (file)
@@ -111,7 +111,9 @@ bool CombinedCurrencyMatcher::matchCurrency(StringSegment& segment, ParsedNumber
 
     int32_t overlap2;
     if (!fCurrency2.isEmpty()) {
-        overlap2 = segment.getCaseSensitivePrefixLength(fCurrency2);
+        // ISO codes should be accepted case-insensitive.
+        // https://unicode-org.atlassian.net/browse/ICU-13696
+        overlap2 = segment.getCommonPrefixLength(fCurrency2);
     } else {
         overlap2 = -1;
     }
index ffc1e83794d1a08790e3fdd681fb93bac2be64c7..d28b94046144330c3bca28abf0ecb9949c35b0a5 100644 (file)
@@ -3861,6 +3861,7 @@ NumberFormatTest::TestParseCurrencyInUCurr() {
         "1.00 US DOLLAR",  // case in-sensitive
         "$1.00",
         "USD1.00",
+        "usd1.00", // case in-sensitive: #13696
         "US dollar1.00",
         "US dollars1.00",
         "$1.00",
@@ -5876,7 +5877,6 @@ NumberFormatTest::TestParseCurrencyInUCurr() {
 
     const char* WRONG_DATA[] = {
         // Following are missing one last char in the currency name
-        "usd1.00", // case sensitive
         "1.00 Nicaraguan Cordob",
         "1.00 Namibian Dolla",
         "1.00 Namibian dolla",
index a953ce04679d7f98e66e053a9ac8b62d6c283a18..860763703937a8261b19029c1dfeb2cf04830da4 100644 (file)
@@ -1668,7 +1668,32 @@ pattern  lenient parse   output  breaks
 0E0'.'x        1       5E3.x   5000
 0E0'.'x        0       5E3.x   5000
 
-test parse lowercase currency
+test parse() lowercase currency
+set locale en
+set pattern ¤¤0
+set currency USD
+begin
+parse  output  breaks
+USD123 123
+USD 123        123     HK
+usd123 123     K
+usd 123        123     HK
+Usd123 123     K
+Usd 123        123     HK
+// US$ is not used for US dollars in en-US
+US$123 fail    H
+us$123 fail
+Us$123 fail
+123 US dollars 123     K
+123 US DOLLARS 123     K
+123 us dollars 123     K
+// Foreign currencies are not accepted in .parse()
+GBP123 fail
+gbp123 fail
+British pounds 123     fail
+british POUNDS 123     fail
+
+test parseCurrency() lowercase currency
 set locale en
 set pattern ¤¤0
 set currency USD
@@ -1676,17 +1701,20 @@ begin
 parse  output  outputCurrency  breaks
 USD123 123     USD
 USD 123        123     USD     H
-// C does not currently accept case-insensitive ISO codes
-usd123 123     USD     C
-usd 123        123     USD     CH
-Usd123 123     USD     C
-Usd 123        123     USD     CH
+usd123 123     USD
+usd 123        123     USD     H
+Usd123 123     USD
+Usd 123        123     USD     H
 US$123 123     USD     C
 us$123 fail    fail
 Us$123 fail    fail
 123 US dollars 123     USD
 123 US DOLLARS 123     USD
 123 us dollars 123     USD
+GBP123 123     GBP
+gbp123 123     GBP     C
+British pounds 123     123     GBP     H
+british POUNDS 123     123     GBP     H
 
 
 
index c46db004603c9f982687fb10ac776d2a85c96766..0cb3cb2edbc33730448f3de1a453b9db99020a1a 100644 (file)
@@ -146,7 +146,9 @@ public class CombinedCurrencyMatcher implements NumberParseMatcher {
 
         int overlap2;
         if (!currency2.isEmpty()) {
-            overlap2 = segment.getCaseSensitivePrefixLength(currency2);
+            // ISO codes should be accepted case-insensitive.
+            // https://unicode-org.atlassian.net/browse/ICU-13696
+            overlap2 = segment.getCommonPrefixLength(currency2);
         } else {
             overlap2 = -1;
         }
index a953ce04679d7f98e66e053a9ac8b62d6c283a18..860763703937a8261b19029c1dfeb2cf04830da4 100644 (file)
@@ -1668,7 +1668,32 @@ pattern  lenient parse   output  breaks
 0E0'.'x        1       5E3.x   5000
 0E0'.'x        0       5E3.x   5000
 
-test parse lowercase currency
+test parse() lowercase currency
+set locale en
+set pattern ¤¤0
+set currency USD
+begin
+parse  output  breaks
+USD123 123
+USD 123        123     HK
+usd123 123     K
+usd 123        123     HK
+Usd123 123     K
+Usd 123        123     HK
+// US$ is not used for US dollars in en-US
+US$123 fail    H
+us$123 fail
+Us$123 fail
+123 US dollars 123     K
+123 US DOLLARS 123     K
+123 us dollars 123     K
+// Foreign currencies are not accepted in .parse()
+GBP123 fail
+gbp123 fail
+British pounds 123     fail
+british POUNDS 123     fail
+
+test parseCurrency() lowercase currency
 set locale en
 set pattern ¤¤0
 set currency USD
@@ -1676,17 +1701,20 @@ begin
 parse  output  outputCurrency  breaks
 USD123 123     USD
 USD 123        123     USD     H
-// C does not currently accept case-insensitive ISO codes
-usd123 123     USD     C
-usd 123        123     USD     CH
-Usd123 123     USD     C
-Usd 123        123     USD     CH
+usd123 123     USD
+usd 123        123     USD     H
+Usd123 123     USD
+Usd 123        123     USD     H
 US$123 123     USD     C
 us$123 fail    fail
 Us$123 fail    fail
 123 US dollars 123     USD
 123 US DOLLARS 123     USD
 123 us dollars 123     USD
+GBP123 123     GBP
+gbp123 123     GBP     C
+British pounds 123     123     GBP     H
+british POUNDS 123     123     GBP     H
 
 
 
index effd33f3d0d48bd124080232404e333abe418d5e..246c8aa975d79b7838a9692a5133211379350409 100644 (file)
@@ -817,7 +817,7 @@ public class NumberFormatTest extends TestFmwk {
                 {"1.00 UAE dirha", "4", "-1", "0", "4"},
                 {"1.00 us dollar", "14", "-1", "14", "-1"},
                 {"1.00 US DOLLAR", "14", "-1", "14", "-1"},
-                {"1.00 usd", "4", "-1", "8", "-1"},
+                {"1.00 usd", "8", "-1", "8", "-1"},
                 {"1.00 USD", "8", "-1", "8", "-1"},
         };
         ULocale locale = new ULocale("en_US");
@@ -6092,8 +6092,8 @@ public class NumberFormatTest extends TestFmwk {
         df.setCurrency(Currency.getInstance("ICU"));
         ParsePosition ppos = new ParsePosition(0);
         df.parseCurrency("icu123", ppos);
-        assertEquals("Should fail to parse", 0, ppos.getIndex());
-        assertEquals("Should fail to parse", 0, ppos.getErrorIndex());
+        assertEquals("Should succeed", 6, ppos.getIndex());
+        assertEquals("Should succeed", -1, ppos.getErrorIndex());
     }
 
     @Test