ICU-865 conformance to the coding style guidlines

X-SVN-Rev: 4110
This commit is contained in:
George Rhoten 2001-03-15 22:12:51 +00:00
parent de52820864
commit b025489c99

View File

@ -296,7 +296,9 @@ Locale& Locale::init(const char* localeID)
int k,l; int k,l;
UErrorCode err = U_ZERO_ERROR; UErrorCode err = U_ZERO_ERROR;
if (localeID == NULL) localeID = uloc_getDefault(); if (localeID == NULL)
localeID = uloc_getDefault();
l = uloc_getLanguage(localeID, l = uloc_getLanguage(localeID,
this->language, this->language,
ULOC_LANG_CAPACITY, ULOC_LANG_CAPACITY,
@ -315,7 +317,9 @@ Locale& Locale::init(const char* localeID)
{ {
this->fullName = new char[j+1]; this->fullName = new char[j+1];
} }
else this->fullName = this->fullNameBuffer; else {
this->fullName = this->fullNameBuffer;
}
uprv_strcpy(this->fullName, localeID); uprv_strcpy(this->fullName, localeID);
@ -323,29 +327,33 @@ Locale& Locale::init(const char* localeID)
-point to the zero terminator of fullName if there is none -point to the zero terminator of fullName if there is none
-point to the first character of the variant if ther is one -point to the first character of the variant if ther is one
*/ */
if (k > 1) if (k > 1)
{ {
if (this->fullName[l] == '\0') this->variant = this->fullName + l; if (this->fullName[l] == '\0')
{
this->variant = this->fullName + l;
}
else else
{ {
int32_t varLength; int32_t varLength;
UErrorCode intErr = U_ZERO_ERROR; UErrorCode intErr = U_ZERO_ERROR;
varLength = uloc_getVariant(this->fullName, NULL, 0, &intErr); varLength = uloc_getVariant(this->fullName, NULL, 0, &intErr);
if(U_FAILURE(intErr) && (intErr != U_BUFFER_OVERFLOW_ERROR)) if(U_FAILURE(intErr) && (intErr != U_BUFFER_OVERFLOW_ERROR))
{ {
this->variant = (char*)u_errorName(intErr); this->variant = (char*)u_errorName(intErr);
} else if(varLength <= 0) }
{ /* bail - point at teh null*/ else if(varLength <= 0)
// this->variant = this->fullName + j; { /* bail - point at the null*/
this->variant = "Len<=0"; // this->variant = this->fullName + j;
} this->variant = "Len<=0";
else }
{ else
/* variant is at the end. We just don't know where exactly it might be. */ {
this->variant = this->fullName + j - varLength + 1 ; /* variant is at the end. We just don't know where exactly it might be. */
} this->variant = this->fullName + j - varLength + 1 ;
} }
}
} }
else else
this->variant = this->fullName + l - 1; this->variant = this->fullName + l - 1;
@ -355,48 +363,51 @@ Locale& Locale::init(const char* localeID)
Locale& Locale::operator=(const Locale& other) Locale& Locale::operator=(const Locale& other)
{ {
uprv_strcpy(language, other.language); uprv_strcpy(language, other.language);
uprv_strcpy(country, other.country); uprv_strcpy(country, other.country);
if (other.fullName == other.fullNameBuffer) fullName = fullNameBuffer; if (other.fullName == other.fullNameBuffer)
else {
{ fullName = fullNameBuffer;
}
else
{
/*In case the assigner has some of its data on the heap /*In case the assigner has some of its data on the heap
* we need to do the same*/ * we need to do the same*/
if (fullName != fullNameBuffer) delete []fullName; if (fullName != fullNameBuffer) delete []fullName;
fullName = new char[(uprv_strlen(other.fullName)+1)]; fullName = new char[(uprv_strlen(other.fullName)+1)];
} }
uprv_strcpy(fullName, other.fullName); uprv_strcpy(fullName, other.fullName);
/*Make the variant point to the same offset as the assigner*/ /*Make the variant point to the same offset as the assigner*/
variant = fullName + (other.variant - other.fullName) ; variant = fullName + (other.variant - other.fullName) ;
return *this; return *this;
} }
int32_t int32_t
Locale::hashCode() const Locale::hashCode() const
{ {
UnicodeString fullNameUString(language, ""); UnicodeString fullNameUString(language, "");
return fullNameUString.append(UnicodeString(country, "")).append(UnicodeString(variant, "")).hashCode(); return fullNameUString.append(UnicodeString(country, "")).append(UnicodeString(variant, "")).hashCode();
} }
Locale& Locale&
Locale::getDefault() Locale::getDefault()
{ {
return fgDefaultLocale; return fgDefaultLocale;
} }
void locale_set_default_internal(const char *id) void locale_set_default_internal(const char *id)
{ {
Locale::getDefault().init(id); Locale::getDefault().init(id);
} }
/* sfb 07/21/99 */ /* sfb 07/21/99 */
U_CFUNC void U_CFUNC void
locale_set_default(const char *id) locale_set_default(const char *id)
{ {
locale_set_default_internal(id); locale_set_default_internal(id);
} }
/* end */ /* end */
@ -409,7 +420,7 @@ Locale::setDefault( const Locale& newLocale,
return; return;
uloc_setDefault(newLocale.fullName, &status); uloc_setDefault(newLocale.fullName, &status);
fgDefaultLocale = newLocale; fgDefaultLocale = newLocale;
} }