From: Shane Date: Tue, 21 Aug 2018 00:41:36 +0000 (-0700) Subject: ICU-13696 Parse local currency ISO codes as case-insensitive. (#62) X-Git-Tag: release-63-rc~112 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cad57b56c110b2c6fb750e469e58669c198a5f1;p=icu ICU-13696 Parse local currency ISO codes as case-insensitive. (#62) --- diff --git a/icu4c/source/i18n/numparse_currency.cpp b/icu4c/source/i18n/numparse_currency.cpp index ae8196ec483..598ace56533 100644 --- a/icu4c/source/i18n/numparse_currency.cpp +++ b/icu4c/source/i18n/numparse_currency.cpp @@ -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; } diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index ffc1e83794d..d28b9404614 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -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", diff --git a/icu4c/source/test/testdata/numberformattestspecification.txt b/icu4c/source/test/testdata/numberformattestspecification.txt index a953ce04679..86076370393 100644 --- a/icu4c/source/test/testdata/numberformattestspecification.txt +++ b/icu4c/source/test/testdata/numberformattestspecification.txt @@ -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 diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/CombinedCurrencyMatcher.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/CombinedCurrencyMatcher.java index c46db004603..0cb3cb2edbc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/CombinedCurrencyMatcher.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/CombinedCurrencyMatcher.java @@ -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; } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt b/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt index a953ce04679..86076370393 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt @@ -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 diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java index effd33f3d0d..246c8aa975d 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java @@ -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