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;
}
"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",
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",
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
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
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;
}
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
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
{"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");
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