ICU-6433 remove fake ISO code parsing in currency parsing

X-SVN-Rev: 25495
This commit is contained in:
Xiaomei Ji 2009-02-27 23:25:55 +00:00
parent 109b0472a5
commit 35cc6003d1
3 changed files with 36 additions and 24 deletions

View File

@ -478,8 +478,8 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
{"en_US", "-1234.56", "USD", "($1,234.56)", "(USD1,234.56)", "-1,234.56 US dollars"},
{"zh_CN", "1", "USD", "US$1.00", "USD1.00", "1.00 \u7F8E\u5143"},
{"zh_CN", "1234.56", "USD", "US$1,234.56", "USD1,234.56", "1,234.56 \u7F8E\u5143"},
{"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY"},
{"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.56", "1,234.56 CHY"},
//{"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY"},
//{"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.56", "1,234.56 CHY"},
{"zh_CN", "1", "CNY", "\uFFE51.00", "CNY1.00", "1.00 \u4EBA\u6C11\u5E01"},
{"zh_CN", "1234.56", "CNY", "\uFFE51,234.56", "CNY1,234.56", "1,234.56 \u4EBA\u6C11\u5E01"},
{"ru_RU", "1", "RUB", "1,00\u00A0\u0440\u0443\u0431.", "1,00\u00A0RUB", "1,00 \u0420\u043E\u0441\u0441\u0438\u0439\u0441\u043A\u0438\u0439 \u0440\u0443\u0431\u043B\u044C"},
@ -542,6 +542,37 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
}
public void TestMiscCurrencyParsing() {
String[][] DATA = {
// each has: string to be parsed, parsed position, error position
{"1.00 ", "0", "4"},
{"1.00 UAE dirha", "0", "4"},
{"1.00 us dollar", "14", "-1"},
{"1.00 US DOLLAR", "14", "-1"},
{"1.00 usd", "8", "-1"},
};
ULocale locale = new ULocale("en_US");
for (int i=0; i<DATA.length; ++i) {
String stringToBeParsed = DATA[i][0];
int parsedPosition = Integer.parseInt(DATA[i][1]);
int errorIndex = Integer.parseInt(DATA[i][2]);
NumberFormat numFmt = NumberFormat.getInstance(locale, NumberFormat.CURRENCYSTYLE);
ParsePosition parsePosition = new ParsePosition(0);
Number val = numFmt.parse(stringToBeParsed, parsePosition);
if (parsePosition.getIndex() != parsedPosition ||
parsePosition.getErrorIndex() != errorIndex) {
errln("FAIL: parse failed. expected position: " + parsedPosition +"; actual: " + parsePosition.getIndex());
errln("FAIL: parse failed. expected error position: " + errorIndex + "; actual: " + parsePosition.getErrorIndex());
}
if (parsePosition.getErrorIndex() == -1 &&
val.doubleValue() != 1.00) {
errln("FAIL: parse failed. expected 1.00, actual:" + val);
}
}
}
/**
* Test the Currency object handling, new as of ICU 2.2.
*/

View File

@ -1,5 +1,5 @@
######################################################################
# Copyright (c) 2004, 2008 International Business Machines
# Copyright (c) 2004, 2009 International Business Machines
# Corporation and others. All Rights Reserved.
######################################################################
# Author: Alan Liu
@ -75,7 +75,8 @@ rt: "" -123.456 "-123.456"
fpc: "en_US" 1234.56/USD "$1,234.56" 1234.56/USD
fpc: - 1234.56/JPY "¥1,235" 1235/JPY
# ISO codes that overlap display names (QQQ vs. Q)
fpc: - 123/QQQ "QQQ123.00" 123/QQQ # QQQ is fake
# fake ISO code is not longer supported
# fpc: - 123/QQQ "QQQ123.00" 123/QQQ # QQQ is fake
fpc: - 123/GTQ "Q123.00" 123/GTQ
# ChoiceFormat-based display names
fpc: - 1/INR "₨1.00" 1/INR

View File

@ -758,26 +758,6 @@ public class Currency extends MeasureUnit implements Serializable {
}
int start = pos.getIndex();
if (isoResult == null ||
maxLength < 3 && (text.length() - start) >= 3) {
// If display name parse fails or if it matches fewer than 3
// characters, try to parse 3-letter ISO. Do this after the
// display name processing so 3-letter display names are
// preferred. Consider /[A-Z]{3}/ to be valid ISO, and parse
// it manually--UnicodeSet/regex are too slow and heavy.
boolean valid = true;
for (int k=0; k<3; ++k) {
char ch = text.charAt(start + k); // 16-bit ok
if (ch < 'A' || ch > 'Z') {
valid = false;
break;
}
}
if (valid) {
pos.setIndex(pos.getIndex() + 3);
return text.substring(start, start+3);
}
}
pos.setIndex(start + maxLength);
return isoResult;
}