ICU-2119 add ISO 4217 code validation

X-SVN-Rev: 11919
This commit is contained in:
Alan Liu 2003-05-14 02:30:15 +00:00
parent 16b16e3acb
commit 1337b6bc43

View File

@ -1143,6 +1143,72 @@ static void TestObsoleteNames(void)
}
/**
* List of all valid ISO 4217 codes. Include historical as well as
* current codes. This list must be updated to include any new
* currencies added to ICU. We check locale data against this list to
* ensure that invalid currency codes are not added.
*/
static const char* ISO_4217[] = {
/* Modern currencies */
"ADP", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG",
"AZM", "BAM", "BBD", "BDT", "BGL", "BGN", "BHD", "BIF", "BMD", "BND",
"BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF",
"CHF", "CLF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CYP", "CZK",
"DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ETB",
"EUR", "FJD", "FKP", "GBP", "GEL", "GHC", "GIP", "GMD", "GNF", "GTQ",
"GWP", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR",
"IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF",
"KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL",
"LTL", "LVL", "LYD", "MAD", "MDL", "MGF", "MKD", "MMK", "MNT", "MOP",
"MRO", "MTL", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZM", "NAD",
"NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP",
"PKR", "PLN", "PYG", "QAR", "ROL", "RUB", "RUR", "RWF", "SAR", "SBD",
"SCR", "SDD", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRG",
"STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMM", "TND", "TOP", "TRL",
"TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "USS", "UYU", "UZS",
"VEB", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "YUM",
"ZAR", "ZMK", "ZWD",
/* From ISO 4217:1981 */
"AFA", "AOK", "AON", "ARP", "ATS", "BEC", "BEF", "BEL", "BOP", "BRC",
"BRR", "BUK", "CSK", "DDM", "DEM", "ESA", "ESB", "ESP", "FIM", "FRF",
"GEK", "GNS", "GQE", "GRD", "IEP", "ITL", "LSM", "LUF", "MLF", "MTP",
"MXP", "NIC", "NLG", "PES", "PLZ", "PTE", "SDP", "SUR", "TPE", "UAK",
"UGS", "UYP", "XAU", "XBA", "XBB", "XBC", "XBD", "XDR", "XEU", "XXX",
"YDD", "YUD", "ZAL", "ZRZ",
/* Obsolete currencies, less well-documented */
"AOR", /* ANGOLA Kwanza Readjustado */
"ARA", /* ARGENTINA Austral */
"BAD", /* BOSNIA Bosnian Dinar */
"BYB", /* BELARUS Belarussian Ruble */
"HRD", /* CROATIA Croatian Dinar */
"PEI", /* PERU Inti */
"TJR", /* TAJIKISTAN Tajik Ruble */
"YUN" /* YUGOSLAVIA Yugoslavian Dinar */
/* Invalid codes that are sometimes seen:
"DRP",
"ECU",
"KIS",
"NIS",
"RMB",
*/
};
static const int32_t ISO_4217_COUNT = sizeof(ISO_4217)/sizeof(ISO_4217[0]);
static UBool isValidISO4217(const char* curr) {
int32_t i;
for (i=0; i<ISO_4217_COUNT; ++i) {
if (strcmp(curr, ISO_4217[i]) == 0) {
return TRUE;
}
}
return FALSE;
}
static void
TestKeyInRootRecursive(UResourceBundle *root, UResourceBundle *currentBundle, const char *locale) {
UErrorCode errorCode = U_ZERO_ERROR;
@ -1172,10 +1238,18 @@ TestKeyInRootRecursive(UResourceBundle *root, UResourceBundle *currentBundle, co
break;
}
else {*/
if (subBundleKey == NULL
const char* bundleKey = ures_getKey(currentBundle);
if (bundleKey != NULL &&
strcmp(bundleKey, "Currencies") == 0) {
if (!isValidISO4217(subBundleKey)) {
log_data_err("Unknown ISO 4217 code \"%s\" in locale \"%s\"; see cloctst.c/ISO_4217[]\n",
subBundleKey,
locale);
}
} else if (subBundleKey == NULL
|| (strcmp(subBundleKey, "TransliterateLATIN") != 0 /* Ignore these special cases */
&& strcmp(subBundleKey, "BreakDictionaryData") != 0
&& strcmp(ures_getKey(currentBundle), "Currencies") != 0))
&& strcmp(subBundleKey, "BreakDictionaryData") != 0))
{
log_data_err("Can't open a resource with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
subBundleKey,