ICU-2984 Use fewer magic numbers, and fix the U_BUFFER_OVERFLOW_ERROR error for some locales

X-SVN-Rev: 12334
This commit is contained in:
George Rhoten 2003-06-05 23:49:53 +00:00
parent 2ef06e4b28
commit cb24fda3d8

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2003, International Business Machines
* Copyright (c) 2002, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -129,10 +129,12 @@ _findMetaData(const UChar* currency) {
// don't use ICUService since we don't need fallback
struct CReg : public UMemory {
static UMTX gCRegLock;
static CReg* gCRegHead;
struct CReg;
static UMTX gCRegLock = 0;
static CReg* gCRegHead = 0;
struct CReg : public UMemory {
CReg *next;
UChar iso[4];
char id[12];
@ -209,24 +211,22 @@ struct CReg : public UMemory {
}
umtx_destroy(&gCRegLock);
}
};
UMTX CReg::gCRegLock = 0;
CReg* CReg:: gCRegHead = 0;
// -------------------------------------
static void
idForLocale(const char* locale, char* buffer, int capacity, UErrorCode* ec) {
idForLocale(const char* locale, char* buffer, int capacity, UErrorCode* ec)
{
// !!! this is internal only, assumes buffer is not null and capacity is sufficient
// Extract the country name and variant name. We only
// recognize two variant names, EURO and PREEURO.
char variant[8];
char variant[ULOC_FULLNAME_CAPACITY];
uloc_getCountry(locale, buffer, capacity, ec);
uloc_getVariant(locale, variant, sizeof(variant), ec);
if (0 == uprv_strcmp(variant, VAR_PRE_EURO) ||
0 == uprv_strcmp(variant, VAR_EURO)) {
0 == uprv_strcmp(variant, VAR_EURO))
{
uprv_strcat(buffer, VAR_DELIM);
uprv_strcat(buffer, variant);
}
@ -238,7 +238,7 @@ U_CAPI UCurrRegistryKey U_EXPORT2
ucurr_register(const UChar* isoCode, const char* locale, UErrorCode *status)
{
if (status && U_SUCCESS(*status)) {
char id[12];
char id[ULOC_FULLNAME_CAPACITY];
idForLocale(locale, id, sizeof(id), status);
return CReg::reg(isoCode, id, status);
}
@ -261,7 +261,7 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status)
U_CAPI const UChar* U_EXPORT2
ucurr_forLocale(const char* locale, UErrorCode* ec) {
if (ec != NULL && U_SUCCESS(*ec)) {
char id[12];
char id[ULOC_FULLNAME_CAPACITY];
idForLocale(locale, id, sizeof(id), ec);
if (U_FAILURE(*ec)) {
return NULL;
@ -350,7 +350,7 @@ ucurr_getName(const UChar* currency,
// this function.
UErrorCode ec2 = U_ZERO_ERROR;
char loc[100];
char loc[ULOC_FULLNAME_CAPACITY];
uloc_getName(locale, loc, sizeof(loc), &ec2);
if (U_FAILURE(ec2) || ec2 == U_STRING_NOT_TERMINATED_WARNING) {
*ec = U_ILLEGAL_ARGUMENT_ERROR;