diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in index 16ed8e314ed..53d481a08ac 100644 --- a/icu4c/source/common/Makefile.in +++ b/icu4c/source/common/Makefile.in @@ -73,7 +73,7 @@ brkiter.o brkdict.o ubrk.o dbbi.o dbbi_tbl.o \ rbbi.o rbbidata.o rbbinode.o rbbirb.o rbbiscan.o rbbisetb.o rbbistbl.o rbbitblb.o \ icuserv.o iculserv.o icunotif.o uenum.o ustrenum.o \ uidna.o usprep.o punycode.o \ -cwchar.o filestrm.o umemstrm.o util.o parsepos.o utrace.o +cwchar.o filestrm.o umemstrm.o util.o parsepos.o utrace.o locbased.o STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O)) diff --git a/icu4c/source/common/brkiter.cpp b/icu4c/source/common/brkiter.cpp index 20eb8254894..25d01b16b43 100644 --- a/icu4c/source/common/brkiter.cpp +++ b/icu4c/source/common/brkiter.cpp @@ -29,6 +29,7 @@ #include "cstring.h" #include "mutex.h" #include "iculserv.h" +#include "locbased.h" // ***************************************************************************** // class BreakIterator @@ -306,6 +307,7 @@ BreakIterator::getDisplayName(const Locale& objectLocale, BreakIterator::BreakIterator() { fBufferClone = FALSE; + *validLocale = *actualLocale = 0; } BreakIterator::~BreakIterator() @@ -402,7 +404,8 @@ BreakIterator::createInstance(const Locale& loc, UBreakIteratorType kind, UError if (hasService()) { Locale validLoc; BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &validLoc, status); - uprv_strcpy(result->validLocale, validLoc.getName()); + U_LOCALE_BASED(locBased, *result); + locBased.setLocaleIDs(validLoc.getName(), 0); return result; } else { return makeInstance(loc, kind, status); @@ -477,47 +480,23 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status) // this is more of a placeholder. All the break iterators have the same actual locale: root // except the Thai one ResourceBundle res(NULL, loc, status); - uprv_strcpy(result->validLocale, res.getLocale(ULOC_VALID_LOCALE, status).getName()); - if(uprv_strcmp(loc.getLanguage(), "th") == 0) { - uprv_strcpy(result->actualLocale, "th"); - } else { - uprv_strcpy(result->actualLocale, "root"); - } + U_LOCALE_BASED(locBased, *result); + locBased.setLocaleIDs(res.getLocale(ULOC_VALID_LOCALE, status).getName(), + (uprv_strcmp(loc.getLanguage(), "th") == 0) ? + "th" : "root"); return result; } Locale -BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - // TODO: need bufferClone problems fixed before this code can work. - return Locale(validLocale); - break; - case ULOC_ACTUAL_LOCALE: - return Locale(actualLocale); - break; - default: - status = U_UNSUPPORTED_ERROR; - return Locale(""); - } +BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); } const char * -BreakIterator::getLocaleInternal(ULocDataLocaleType type, UErrorCode& status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - // TODO: need bufferClone problems fixed before this code can work. - return validLocale; - break; - case ULOC_ACTUAL_LOCALE: - return actualLocale; - break; - default: - status = U_UNSUPPORTED_ERROR; - return NULL; - } +BreakIterator::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocaleID(type, status); } U_NAMESPACE_END diff --git a/icu4c/source/common/ubrk.cpp b/icu4c/source/common/ubrk.cpp index 56db7045487..9a5215cbecc 100644 --- a/icu4c/source/common/ubrk.cpp +++ b/icu4c/source/common/ubrk.cpp @@ -270,7 +270,13 @@ ubrk_getLocaleByType(const UBreakIterator *bi, ULocDataLocaleType type, UErrorCode* status) { - return ((BreakIterator *)bi)->getLocaleInternal(type, *status); + if (bi == NULL) { + if (U_SUCCESS(*status)) { + *status = U_ILLEGAL_ARGUMENT_ERROR; + } + return NULL; + } + return ((BreakIterator*)bi)->getLocaleID(type, *status); } diff --git a/icu4c/source/common/unicode/brkiter.h b/icu4c/source/common/unicode/brkiter.h index 2d60e7abd24..ab1dbb76dea 100644 --- a/icu4c/source/common/unicode/brkiter.h +++ b/icu4c/source/common/unicode/brkiter.h @@ -567,7 +567,7 @@ public: * actual locale. * @draft ICU 2.8 */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; + Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; /** Get the locale for this break iterator object. You can choose between valid and actual locale. * @param type type of the locale we're looking for (valid or actual) @@ -575,7 +575,8 @@ public: * @return the locale * @internal */ - virtual const char *getLocaleInternal(ULocDataLocaleType type, UErrorCode& status) const; + const char *getLocaleID(ULocDataLocaleType type, UErrorCode& status) const; + private: static BreakIterator* makeCharacterInstance(const Locale& loc, UErrorCode& status); static BreakIterator* makeWordInstance(const Locale& loc, UErrorCode& status); @@ -597,10 +598,12 @@ protected: /** @internal */ BreakIterator (const BreakIterator &other) : UObject(other), fBufferClone(FALSE) {} +private: + /** @internal */ char actualLocale[ULOC_FULLNAME_CAPACITY]; char validLocale[ULOC_FULLNAME_CAPACITY]; -private: + /** * The assignment operator has no real implementation. * It's provided to make the compiler happy. Do not call. diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 32019e6c42d..9956e5e04ab 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -41,6 +41,7 @@ #include "iculserv.h" #include "ucln_in.h" #include "cstring.h" +#include "locbased.h" U_NAMESPACE_BEGIN @@ -599,8 +600,8 @@ Calendar::createInstance(const Locale& aLocale, UErrorCode& success) Calendar* Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success) { - Locale validLoc; - UObject* u = getService()->get(aLocale, LocaleKey::KIND_ANY, &validLoc, success); + Locale actualLoc; + UObject* u = getService()->get(aLocale, LocaleKey::KIND_ANY, &actualLoc, success); Calendar* c = NULL; if(U_FAILURE(success) || !u) { @@ -634,7 +635,7 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ delete u; u = NULL; - c = (Calendar*)getService()->get(l, LocaleKey::KIND_ANY, &validLoc, success); + c = (Calendar*)getService()->get(l, LocaleKey::KIND_ANY, &actualLoc, success); if(U_FAILURE(success) || !c) { delete zone; @@ -667,8 +668,9 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ // Now, reset calendar to default state: c->adoptTimeZone(zone); // Set the correct time zone c->setTimeInMillis(getNow(), success); // let the new calendar have the current time. - // pull up valid locale from registration - uprv_strcpy(c->validLocale, validLoc.getName()); + // pull up actual locale from registration + U_LOCALE_BASED(locBased, *c); + locBased.setLocaleIDs(0, actualLoc.getName()); return c; } @@ -2907,8 +2909,9 @@ Calendar::setWeekCountData(const Locale& desiredLocale, UErrorCode& status) //dateTimeElements = resource.getStringArray(kDateTimeElements, count, status); UResourceBundle *dateTimeElements = ures_getByKey(resource, kDateTimeElements, NULL, &status); // TODO: should be per calendar?! - uprv_strcpy(validLocale, ures_getLocaleByType(resource, ULOC_VALID_LOCALE, &status)); - uprv_strcpy(actualLocale, ures_getLocaleByType(resource, ULOC_ACTUAL_LOCALE, &status)); + U_LOCALE_BASED(locBased, *this); + locBased.setLocaleIDs(ures_getLocaleByType(resource, ULOC_VALID_LOCALE, &status), + ures_getLocaleByType(resource, ULOC_ACTUAL_LOCALE, &status)); if (U_SUCCESS(status)) { int32_t arrLen; const int32_t *dateTimeElementsArr = ures_getIntVector(dateTimeElements, &arrLen, &status); @@ -2950,39 +2953,16 @@ Calendar::updateTime(UErrorCode& status) fIsTimeSet = TRUE; } - Locale -Calendar::getLocale(ULocDataLocaleType type, UErrorCode &status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return Locale(validLocale); - break; - case ULOC_ACTUAL_LOCALE: - return Locale(actualLocale); - break; - default: - status = U_UNSUPPORTED_ERROR; - return Locale(""); - break; - } +Calendar::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); } -const char* -Calendar::getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return validLocale; - break; - case ULOC_ACTUAL_LOCALE: - return actualLocale; - break; - default: - status = U_UNSUPPORTED_ERROR; - return NULL; - break; - } +const char * +Calendar::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocaleID(type, status); } U_NAMESPACE_END diff --git a/icu4c/source/i18n/dcfmtsym.cpp b/icu4c/source/i18n/dcfmtsym.cpp index 2074c8f2326..f470334f0b5 100644 --- a/icu4c/source/i18n/dcfmtsym.cpp +++ b/icu4c/source/i18n/dcfmtsym.cpp @@ -27,6 +27,8 @@ #include "unicode/ucurr.h" #include "unicode/choicfmt.h" #include "ucurrimp.h" +#include "cstring.h" +#include "locbased.h" // ***************************************************************************** // class DecimalFormatSymbols @@ -77,6 +79,8 @@ DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source) // fastCopyFrom is safe, see docs on fSymbols fSymbols[(ENumberFormatSymbol)i].fastCopyFrom(source.fSymbols[(ENumberFormatSymbol)i]); } + uprv_strcpy(validLocale, source.validLocale); + uprv_strcpy(actualLocale, source.actualLocale); } // ------------------------------------- @@ -120,6 +124,8 @@ void DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool useLastResortData) { + *validLocale = *actualLocale = 0; + if (U_FAILURE(status)) return; @@ -171,6 +177,12 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, } /* else use the default values. */ } + + U_LOCALE_BASED(locBased, *this); + locBased.setLocaleIDs(ures_getLocaleByType(numberElementsRes, + ULOC_VALID_LOCALE, &status), + ures_getLocaleByType(numberElementsRes, + ULOC_ACTUAL_LOCALE, &status)); } ures_close(numberElementsRes); } @@ -237,6 +249,12 @@ DecimalFormatSymbols::initialize() { fSymbols[kNaNSymbol] = (UChar)0xfffd; // SUB NaN } +Locale +DecimalFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); +} + U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/dtfmtsym.cpp b/icu4c/source/i18n/dtfmtsym.cpp index 5d74e9c2a0b..d717d393c85 100644 --- a/icu4c/source/i18n/dtfmtsym.cpp +++ b/icu4c/source/i18n/dtfmtsym.cpp @@ -29,6 +29,7 @@ #include "mutex.h" #include "cmemory.h" #include "cstring.h" +#include "locbased.h" // ***************************************************************************** // class DateFormatSymbols @@ -643,10 +644,11 @@ DateFormatSymbols::initializeData(const Locale& locale, const char *type, UError // if we make it to here, the resource data is cool, and we can get everything out // of it that we need except for the time-zone and localized-pattern data, which - // are stoerd in a separate file + // are stored in a separate file ResourceBundle data = getData(resource, gErasTag, type, status); - uprv_strcpy(validLocale, data.getLocale(ULOC_VALID_LOCALE, status).getName()); - uprv_strcpy(actualLocale, data.getLocale(ULOC_ACTUAL_LOCALE, status).getName()); + U_LOCALE_BASED(locBased, *this); + locBased.setLocaleIDs(data.getLocale(ULOC_VALID_LOCALE, status).getName(), + data.getLocale(ULOC_ACTUAL_LOCALE, status).getName()); initField(&fEras, fErasCount, data, status); initField(&fMonths, fMonthsCount, getData(resource, gMonthNamesTag, type, status), status); initField(&fShortMonths, fShortMonthsCount, getData(resource, gMonthAbbreviationsTag, type, status), status); @@ -765,6 +767,12 @@ int32_t DateFormatSymbols::_getZoneIndex(const UnicodeString& ID) const return -1; } +Locale +DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); +} + U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/format.cpp b/icu4c/source/i18n/format.cpp index 266c0a7ab7f..5e1615f5286 100644 --- a/icu4c/source/i18n/format.cpp +++ b/icu4c/source/i18n/format.cpp @@ -39,6 +39,9 @@ uprv_icuin_lib_dummy(int32_t i) { #if !UCONFIG_NO_FORMATTING #include "unicode/format.h" +#include "unicode/resbund.h" +#include "cstring.h" +#include "locbased.h" // ***************************************************************************** // class Format @@ -61,6 +64,7 @@ FieldPosition::clone() const { Format::Format() : UObject() { + *validLocale = *actualLocale = 0; } // ------------------------------------- @@ -75,14 +79,17 @@ Format::~Format() Format::Format(const Format &that) : UObject(that) { + *this = that; } // ------------------------------------- // assignment operator Format& -Format::operator=(const Format& /*that*/) +Format::operator=(const Format& that) { + uprv_strcpy(validLocale, that.validLocale); + uprv_strcpy(actualLocale, that.actualLocale); return *this; } @@ -163,6 +170,31 @@ void Format::syntaxError(const UnicodeString& pattern, parseError.postContext[stop-start]= 0; } +Locale +Format::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); +} + +const char * +Format::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocaleID(type, status); +} + +void +Format::setLocales(const ResourceBundle& res) { + UErrorCode status = U_ZERO_ERROR; + setLocaleIDs(res.getLocale(ULOC_VALID_LOCALE, status).getName(), + res.getLocale(ULOC_ACTUAL_LOCALE, status).getName()); +} + +void +Format::setLocaleIDs(const char* valid, const char* actual) { + U_LOCALE_BASED(locBased, *this); + locBased.setLocaleIDs(valid, actual); +} + U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index c665c410871..55db1808911 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -187,6 +187,7 @@ MessageFormat::MessageFormat(const UnicodeString& pattern, return; } applyPattern(pattern, success); + setLocaleIDs(fLocale.getName(), fLocale.getName()); } MessageFormat::MessageFormat(const UnicodeString& pattern, @@ -210,6 +211,7 @@ MessageFormat::MessageFormat(const UnicodeString& pattern, return; } applyPattern(pattern, success); + setLocaleIDs(fLocale.getName(), fLocale.getName()); } MessageFormat::MessageFormat(const UnicodeString& pattern, @@ -234,6 +236,7 @@ MessageFormat::MessageFormat(const UnicodeString& pattern, return; } applyPattern(pattern, parseError, success); + setLocaleIDs(fLocale.getName(), fLocale.getName()); } MessageFormat::MessageFormat(const MessageFormat& that) @@ -427,6 +430,7 @@ MessageFormat::setLocale(const Locale& theLocale) defaultDateFormat = NULL; } fLocale = theLocale; + setLocaleIDs(fLocale.getName(), fLocale.getName()); } // ------------------------------------- @@ -1393,40 +1397,6 @@ const DateFormat* MessageFormat::getDefaultDateFormat(UErrorCode& ec) const { return defaultDateFormat; } -Locale -MessageFormat::getLocale(ULocDataLocaleType type, UErrorCode& status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return fLocale; - break; - case ULOC_ACTUAL_LOCALE: - return fLocale; - break; - default: - status = U_UNSUPPORTED_ERROR; - return Locale(""); - break; - } -} - -const char* -MessageFormat::getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return fLocale.getName(); - break; - case ULOC_ACTUAL_LOCALE: - return fLocale.getName(); - break; - default: - status = U_UNSUPPORTED_ERROR; - return NULL; - break; - } -} - U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp index 83294584c93..3feb5cb998e 100644 --- a/icu4c/source/i18n/numfmt.cpp +++ b/icu4c/source/i18n/numfmt.cpp @@ -736,47 +736,10 @@ NumberFormat::makeInstance(const Locale& desiredLocale, f = NULL; return NULL; } - uprv_strcpy(f->validLocale, numberPatterns.getLocale(ULOC_VALID_LOCALE, status).getName()); - uprv_strcpy(f->actualLocale, numberPatterns.getLocale(ULOC_ACTUAL_LOCALE, status).getName()); + f->setLocales(numberPatterns); return f; } -Locale -NumberFormat::getLocale(ULocDataLocaleType type, UErrorCode& status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return Locale(validLocale); - break; - case ULOC_ACTUAL_LOCALE: - return Locale(actualLocale); - break; - default: - status = U_UNSUPPORTED_ERROR; - return Locale(""); - break; - } -} - - -const char* -NumberFormat::getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return validLocale; - break; - case ULOC_ACTUAL_LOCALE: - return actualLocale; - break; - default: - status = U_UNSUPPORTED_ERROR; - return NULL; - break; - } -} - - U_NAMESPACE_END // defined in ucln_cmn.h diff --git a/icu4c/source/i18n/rbnf.cpp b/icu4c/source/i18n/rbnf.cpp index 2060c88bdbe..fde2fbf21a8 100644 --- a/icu4c/source/i18n/rbnf.cpp +++ b/icu4c/source/i18n/rbnf.cpp @@ -89,9 +89,9 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& // UResourceBundle* yuck = ures_getByKey(nfrb, fmt_tag, NULL, &status); // const UChar* description = ures_getString(yuck, &len, &status); if (U_SUCCESS(status)) { - uprv_strcpy(validLocale, ures_getLocaleByType(nfrb, ULOC_VALID_LOCALE, &status)); - uprv_strcpy(actualLocale, ures_getLocaleByType(nfrb, ULOC_ACTUAL_LOCALE, &status)); - const UChar* description = ures_getStringByKey(nfrb, fmt_tag, &len, &status); + setLocaleIDs(ures_getLocaleByType(nfrb, ULOC_VALID_LOCALE, &status), + ures_getLocaleByType(nfrb, ULOC_ACTUAL_LOCALE, &status)); + const UChar* description = ures_getStringByKey(nfrb, fmt_tag, &len, &status); UnicodeString desc(description, len); UParseError perror; init (desc, perror, status); @@ -454,9 +454,6 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& /* pErr */, return; } - validLocale[0] = 0; - actualLocale[0] = 0; - UnicodeString description(rules); if (!description.length()) { status = U_MEMORY_ALLOCATION_ERROR; diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index d467577819b..bbaeb72dba3 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -292,6 +292,8 @@ void SimpleDateFormat::construct(EStyle timeStyle, return; } + setLocales(dateTimePatterns); + // create a symbols object from the locale initializeSymbols(locale,fCalendar, status); if (U_FAILURE(status)) return; @@ -1562,40 +1564,6 @@ void SimpleDateFormat::adoptCalendar(Calendar* calendarToAdopt) initializeDefaultCentury(); // we need a new century (possibly) } -Locale -SimpleDateFormat::getLocale(ULocDataLocaleType type, UErrorCode& status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return Locale(fSymbols->validLocale); - break; - case ULOC_ACTUAL_LOCALE: - return Locale(fSymbols->actualLocale); - break; - default: - status = U_UNSUPPORTED_ERROR; - return Locale(""); - } -} - -const char* -SimpleDateFormat::getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const -{ - switch(type) { - case ULOC_VALID_LOCALE: - return fSymbols->validLocale; - break; - case ULOC_ACTUAL_LOCALE: - return fSymbols->actualLocale; - break; - default: - status = U_UNSUPPORTED_ERROR; - return NULL; - break; - } -} - - U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/ucal.cpp b/icu4c/source/i18n/ucal.cpp index fb973e44191..55f43a94962 100644 --- a/icu4c/source/i18n/ucal.cpp +++ b/icu4c/source/i18n/ucal.cpp @@ -473,10 +473,13 @@ ucal_getLimit( const UCalendar* cal, U_CAPI const char * U_EXPORT2 ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status) { - if(cal == NULL) { - return NULL; - } - return ((Calendar*)cal)->getLocaleInternal(type, *status); + if (cal == NULL) { + if (U_SUCCESS(*status)) { + *status = U_ILLEGAL_ARGUMENT_ERROR; + } + return NULL; + } + return ((Calendar*)cal)->getLocaleID(type, *status); } #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp index b69922c4a1b..5762f60b8e9 100644 --- a/icu4c/source/i18n/udat.cpp +++ b/icu4c/source/i18n/udat.cpp @@ -578,9 +578,12 @@ udat_getLocaleByType(const UDateFormat *fmt, ULocDataLocaleType type, UErrorCode* status) { - if(fmt==NULL){ - return NULL; - } - return ((Format *)fmt)->getLocaleInternal(type, *status); + if (fmt == NULL) { + if (U_SUCCESS(*status)) { + *status = U_ILLEGAL_ARGUMENT_ERROR; + } + return NULL; + } + return ((Format*)fmt)->getLocaleID(type, *status); } #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index 6003cc7bd33..16184427be5 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -590,10 +590,13 @@ umsg_getLocaleByType(const UMessageFormat *fmt, ULocDataLocaleType type, UErrorCode* status) { - if(fmt==NULL){ - return NULL; - } - return ((Format *)fmt)->getLocaleInternal(type, *status); + if (fmt == NULL) { + if (U_SUCCESS(*status)) { + *status = U_ILLEGAL_ARGUMENT_ERROR; + } + return NULL; + } + return ((Format*)fmt)->getLocaleID(type, *status); } #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h index 1f3af293598..dcdf499c96a 100644 --- a/icu4c/source/i18n/unicode/calendar.h +++ b/icu4c/source/i18n/unicode/calendar.h @@ -1998,6 +1998,7 @@ private: */ static uint8_t julianDayToDayOfWeek(double julian); + private: char validLocale[ULOC_FULLNAME_CAPACITY]; char actualLocale[ULOC_FULLNAME_CAPACITY]; @@ -2085,7 +2086,7 @@ private: * @return the locale * @internal */ - virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const; + virtual const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const; }; diff --git a/icu4c/source/i18n/unicode/datefmt.h b/icu4c/source/i18n/unicode/datefmt.h index b611763358b..22b82eebff7 100644 --- a/icu4c/source/i18n/unicode/datefmt.h +++ b/icu4c/source/i18n/unicode/datefmt.h @@ -602,15 +602,6 @@ public: */ virtual void setTimeZone(const TimeZone& zone); - - /** Get the locale for this date format object. You can choose between valid and actual locale. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @draft ICU 2.8 - */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0; - protected: /** * Default constructor. Creates a DateFormat with no Calendar or NumberFormat diff --git a/icu4c/source/i18n/unicode/dcfmtsym.h b/icu4c/source/i18n/unicode/dcfmtsym.h index d2ac614ea6e..35d2d4b9cbb 100644 --- a/icu4c/source/i18n/unicode/dcfmtsym.h +++ b/icu4c/source/i18n/unicode/dcfmtsym.h @@ -202,6 +202,13 @@ public: */ inline Locale getLocale() const; + /** + * Returns the locale for this object. Two flavors are available: + * valid and actual locale. + * @draft ICU 2.8 + */ + Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; + /** * ICU "poor man's RTTI", returns a UClassID for the actual class. * @@ -287,6 +294,8 @@ private: Locale locale; + char actualLocale[ULOC_FULLNAME_CAPACITY]; + char validLocale[ULOC_FULLNAME_CAPACITY]; }; // ------------------------------------- diff --git a/icu4c/source/i18n/unicode/dtfmtsym.h b/icu4c/source/i18n/unicode/dtfmtsym.h index 578776960d1..378c8ca9578 100644 --- a/icu4c/source/i18n/unicode/dtfmtsym.h +++ b/icu4c/source/i18n/unicode/dtfmtsym.h @@ -310,6 +310,13 @@ public: */ void setLocalPatternChars(const UnicodeString& newLocalPatternChars); + /** + * Returns the locale for this object. Two flavors are available: + * valid and actual locale. + * @draft ICU 2.8 + */ + Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; + /** * ICU "poor man's RTTI", returns a UClassID for the actual class. * diff --git a/icu4c/source/i18n/unicode/format.h b/icu4c/source/i18n/unicode/format.h index c12bcd635e0..7ebc30326b9 100644 --- a/icu4c/source/i18n/unicode/format.h +++ b/icu4c/source/i18n/unicode/format.h @@ -34,6 +34,9 @@ #include "unicode/locid.h" U_NAMESPACE_BEGIN + +class ResourceBundle; + /** * Base class for all formats. This is an abstract base class which * specifies the protocol for classes which convert other objects or @@ -239,7 +242,7 @@ public: * @return the locale * @draft ICU 2.8 */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0; + Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; /** Get the locale for this format object. You can choose between valid and actual locale. * @param type type of the locale we're looking for (valid or actual) @@ -247,7 +250,13 @@ public: * @return the locale * @internal */ - virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const = 0; + const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const; + + protected: + + void setLocales(const ResourceBundle& res); + + void setLocaleIDs(const char* valid, const char* actual); protected: /** @@ -278,6 +287,10 @@ protected: static void syntaxError(const UnicodeString& pattern, int32_t pos, UParseError& parseError); + + private: + char actualLocale[ULOC_FULLNAME_CAPACITY]; + char validLocale[ULOC_FULLNAME_CAPACITY]; }; U_NAMESPACE_END diff --git a/icu4c/source/i18n/unicode/msgfmt.h b/icu4c/source/i18n/unicode/msgfmt.h index a86ea4beab2..0415cd4890b 100644 --- a/icu4c/source/i18n/unicode/msgfmt.h +++ b/icu4c/source/i18n/unicode/msgfmt.h @@ -595,26 +595,6 @@ public: */ static UClassID getStaticClassID(void); - /** Get the locale for this message format object. You can choose between valid and actual locale. - * In the case of message format, both locales are the same as the locale passed during the - * construction. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @draft ICU 2.8 - */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; - - /** Get the locale for this message format object. You can choose between valid and actual locale. - * In the case of message format, both locales are the same as the locale passed during the - * construction. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @internal - */ - virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const; - private: Locale fLocale; diff --git a/icu4c/source/i18n/unicode/numfmt.h b/icu4c/source/i18n/unicode/numfmt.h index f43a92c03ef..d410dca97ec 100644 --- a/icu4c/source/i18n/unicode/numfmt.h +++ b/icu4c/source/i18n/unicode/numfmt.h @@ -616,22 +616,6 @@ public: */ const UChar* getCurrency() const; - /** Get the locale for this numeric format object. You can choose between valid and actual locale. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @draft ICU 2.8 - */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; - - /** Get the locale for this numeric format object. You can choose between valid and actual locale. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @internal - */ - virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const; - public: /** @@ -671,10 +655,6 @@ private: static const int32_t fgMaxIntegerDigits; static const int32_t fgMinIntegerDigits; -protected: - char validLocale[ULOC_FULLNAME_CAPACITY]; - char actualLocale[ULOC_FULLNAME_CAPACITY]; - private: enum EStyles { diff --git a/icu4c/source/i18n/unicode/smpdtfmt.h b/icu4c/source/i18n/unicode/smpdtfmt.h index da3c39b08f7..96314a86c62 100644 --- a/icu4c/source/i18n/unicode/smpdtfmt.h +++ b/icu4c/source/i18n/unicode/smpdtfmt.h @@ -583,22 +583,6 @@ public: */ virtual void adoptCalendar(Calendar* calendarToAdopt); - /** Get the locale for this date format object. You can choose between valid and actual locale. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @draft ICU 2.8 - */ - virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; - - /** Get the locale for this date format object. You can choose between valid and actual locale. - * @param type type of the locale we're looking for (valid or actual) - * @param status error code for the operation - * @return the locale - * @internal - */ - virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const; - private: friend class DateFormat; diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 060625b3375..bac114dc134 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -661,10 +661,13 @@ unum_getLocaleByType(const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode* status) { - if(fmt==NULL){ - return NULL; - } - return ((Format *)fmt)->getLocaleInternal(type, *status); + if (fmt == NULL) { + if (U_SUCCESS(*status)) { + *status = U_ILLEGAL_ARGUMENT_ERROR; + } + return NULL; + } + return ((Format*)fmt)->getLocaleID(type, *status); } #endif /* #if !UCONFIG_NO_FORMATTING */