ICU-3837 Add UCONFIG_NO_SERVICE

X-SVN-Rev: 16034
This commit is contained in:
George Rhoten 2004-07-18 01:37:13 +00:00
parent 8967f503cc
commit e069f28ece
9 changed files with 175 additions and 108 deletions

View file

@ -96,16 +96,55 @@ static const char* fldName(UCalendarDateFields f) {
#endif
static ICULocaleService* gService = NULL;
// -------------------------------------
static const char * const gBasicCalendars[] = { "@calendar=gregorian", "@calendar=japanese",
"@calendar=buddhist", "@calendar=islamic-civil",
"@calendar=islamic", "@calendar=hebrew", "@calendar=chinese",
NULL };
static UBool isStandardSupportedID( const char *id, UErrorCode& status) {
if(U_FAILURE(status)) {
return FALSE;
}
for(int32_t i=0;gBasicCalendars[i] != NULL;i++) {
if(uprv_strcmp(gBasicCalendars[i],id) == 0) {
return TRUE;
}
}
return FALSE;
}
static Calendar *createStandardCalendar(char *calType, const Locale &canLoc, UErrorCode& status) {
#ifdef U_DEBUG_CALSVC
fprintf(stderr, "BasicCalendarFactory %p: creating type for %s\n",
this, (const char*)curLoc.getName());
fflush(stderr);
#endif
if(!calType || !*calType || !uprv_strcmp(calType,"@calendar=gregorian")) { // Gregorian (default)
return new GregorianCalendar(canLoc, status);
} else if(!uprv_strcmp(calType, "@calendar=japanese")) {
return new JapaneseCalendar(canLoc, status);
} else if(!uprv_strcmp(calType, "@calendar=buddhist")) {
return new BuddhistCalendar(canLoc, status);
} else if(!uprv_strcmp(calType, "@calendar=islamic-civil")) {
return new IslamicCalendar(canLoc, status, IslamicCalendar::CIVIL);
} else if(!uprv_strcmp(calType, "@calendar=islamic")) {
return new IslamicCalendar(canLoc, status, IslamicCalendar::ASTRONOMICAL);
} else if(!uprv_strcmp(calType, "@calendar=hebrew")) {
return new HebrewCalendar(canLoc, status);
//} else if(!uprv_strcmp(calType, "@calendar=chinese")) {
//return new ChineseCalendar(canLoc, status);
} else {
status = U_UNSUPPORTED_ERROR;
return NULL;
}
}
#if !UCONFIG_NO_SERVICE
static ICULocaleService* gService = NULL;
// -------------------------------------
/**
* a Calendar Factory which creates the "basic" calendar types, that is, those
* shipped with ICU.
@ -161,21 +200,20 @@ protected:
key.currentID(str);
char tmp[200];
// Extract a char* out of it..
int32_t len = str.length();
int32_t actLen = sizeof(tmp)-1;
if(len > actLen) {
len = actLen;
}
str.extract(0,len,tmp);
tmp[len]=0;
// Extract a char* out of it..
int32_t len = str.length();
int32_t actLen = sizeof(tmp)-1;
if(len > actLen) {
len = actLen;
}
str.extract(0,len,tmp);
tmp[len]=0;
#ifdef U_DEBUG_CALSVC
fprintf(stderr, "BasicCalendarFactory::create() - cur %s, can %s\n", (const char*)curLoc.getName(), (const char*)canLoc.getName());
#endif
if(!isSupportedID(str,status)) { // Do we handle this type?
if(!isStandardSupportedID(tmp,status)) { // Do we handle this type?
#ifdef U_DEBUG_CALSVC
fprintf(stderr, "BasicCalendarFactory - not handling %s.[%s]\n", (const char*) curLoc.getName(), tmp );
@ -183,31 +221,8 @@ protected:
return NULL;
}
#ifdef U_DEBUG_CALSVC
fprintf(stderr, "BasicCalendarFactory %p: creating type for %s\n",
this, (const char*)curLoc.getName());
fflush(stderr);
#endif
if(!tmp || !*tmp || !uprv_strcmp(tmp,"@calendar=gregorian")) { // Gregorian (default)
return new GregorianCalendar(canLoc, status);
} else if(!uprv_strcmp(tmp, "@calendar=japanese")) {
return new JapaneseCalendar(canLoc, status);
} else if(!uprv_strcmp(tmp, "@calendar=buddhist")) {
return new BuddhistCalendar(canLoc, status);
} else if(!uprv_strcmp(tmp, "@calendar=islamic-civil")) {
return new IslamicCalendar(canLoc, status, IslamicCalendar::CIVIL);
} else if(!uprv_strcmp(tmp, "@calendar=islamic")) {
return new IslamicCalendar(canLoc, status, IslamicCalendar::ASTRONOMICAL);
} else if(!uprv_strcmp(tmp, "@calendar=hebrew")) {
return new HebrewCalendar(canLoc, status);
//} else if(!uprv_strcmp(tmp, "@calendar=chinese")) {
//return new ChineseCalendar(canLoc, status);
} else {
status = U_UNSUPPORTED_ERROR;
return NULL;
return createStandardCalendar(tmp, canLoc, status);
}
}
};
@ -366,6 +381,7 @@ URegistryKey Calendar::registerFactory(ICUServiceFactory* toAdopt, UErrorCode& s
UBool Calendar::unregister(URegistryKey key, UErrorCode& status) {
return getCalendarService()->unregister(key, status);
}
#endif /* UCONFIG_NO_SERVICE */
// -------------------------------------
@ -585,7 +601,21 @@ Calendar*
Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
{
Locale actualLoc;
UObject* u = getCalendarService()->get(aLocale, LocaleKey::KIND_ANY, &actualLoc, success);
UObject* u;
#if UCONFIG_NO_SERVICE
{
char calLocaleType[ULOC_FULLNAME_CAPACITY] = {"@calendar="};
int32_t calLocaleTypeLen = uprv_strlen(calLocaleType);
int32_t keywordCapacity = aLocale.getKeywordValue("calendar", calLocaleType+calLocaleTypeLen, sizeof(calLocaleType)-calLocaleTypeLen, success);
if (keywordCapacity == 0) {
// no calendar type. Default to nothing.
calLocaleType[0] = 0;
}
u = createStandardCalendar(calLocaleType, aLocale, success);
}
#else
u = getCalendarService()->get(aLocale, LocaleKey::KIND_ANY, &actualLoc, success);
#endif
Calendar* c = NULL;
if(U_FAILURE(success) || !u) {
@ -596,6 +626,7 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
return NULL;
}
#if !UCONFIG_NO_SERVICE
if(u->getDynamicClassID() == UnicodeString::getStaticClassID()) {
// It's a unicode string telling us what type of calendar to load ("gregorian", etc)
char tmp[200];
@ -663,7 +694,10 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
fprintf(stderr, "%p: setting week count data to locale %s, actual locale %s\n", c, (const char*)aLocale.getName(), (const char *)actualLoc.getName());
#endif
c->setWeekCountData(aLocale, c->getType(), success); // set the correct locale (this was an indirected calendar)
} else {
}
else
#endif /* UCONFIG_NO_SERVICE */
{
// a calendar was returned - we assume the factory did the right thing.
c = (Calendar*)u;
}
@ -2980,10 +3014,12 @@ U_CFUNC UBool calendar_cleanup(void) {
calendar_islamic_cleanup();
calendar_hebrew_cleanup();
calendar_astro_cleanup();
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
gService = NULL;
}
#endif
return TRUE;
}

View file

@ -52,6 +52,7 @@
U_NAMESPACE_BEGIN
#if !UCONFIG_NO_SERVICE
// ------------------------------------------
//
// Registration
@ -222,6 +223,7 @@ Collator::createUCollator(const char *loc,
}
return result;
}
#endif /* UCONFIG_NO_SERVICE */
// Collator public methods -----------------------------------------------
@ -238,6 +240,7 @@ Collator* Collator::createInstance(const Locale& desiredLocale,
if (U_FAILURE(status))
return 0;
#if !UCONFIG_NO_SERVICE
if (hasService()) {
Locale actualLoc;
Collator *result =
@ -253,6 +256,7 @@ Collator* Collator::createInstance(const Locale& desiredLocale,
}
return result;
}
#endif
return makeInstance(desiredLocale, status);
}
@ -384,9 +388,11 @@ UnicodeString& Collator::getDisplayName(const Locale& objectLocale,
const Locale& displayLocale,
UnicodeString& name)
{
#if !UCONFIG_NO_SERVICE
if (hasService()) {
return gService->getDisplayName(objectLocale.getName(), name, displayLocale);
}
#endif
return objectLocale.getDisplayName(displayLocale, name);
}
@ -477,6 +483,7 @@ UnicodeSet *Collator::getTailoredSet(UErrorCode &status) const
// -------------------------------------
#if !UCONFIG_NO_SERVICE
URegistryKey
Collator::registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status)
{
@ -601,6 +608,7 @@ Collator::getAvailableLocales(void)
{
return getService()->getAvailableLocales();
}
#endif /* UCONFIG_NO_SERVICE */
StringEnumeration*
Collator::getKeywords(UErrorCode& status) {
@ -652,10 +660,12 @@ U_NAMESPACE_END
* Release all static memory held by collator.
*/
U_CFUNC UBool collator_cleanup(void) {
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
gService = NULL;
}
#endif
return TRUE;
}

View file

@ -455,6 +455,7 @@ NumberFormat::getAvailableLocales(int32_t& count)
//
//-------------------------------------------
#if !UCONFIG_NO_SERVICE
static ICULocaleService* gService = NULL;
// -------------------------------------
@ -585,22 +586,6 @@ getNumberFormatService(void)
return gService;
}
// -------------------------------------
NumberFormat*
NumberFormat::createInstance(const Locale& loc, EStyles kind, UErrorCode& status)
{
umtx_lock(NULL);
UBool haveService = gService != NULL;
umtx_unlock(NULL);
if (haveService) {
return (NumberFormat*)gService->get(loc, kind, status);
} else {
return makeInstance(loc, kind, status);
}
}
// -------------------------------------
URegistryKey
@ -641,6 +626,26 @@ NumberFormat::getAvailableLocales(void)
}
return NULL; // no way to return error condition
}
#endif /* UCONFIG_NO_SERVICE */
// -------------------------------------
NumberFormat*
NumberFormat::createInstance(const Locale& loc, EStyles kind, UErrorCode& status)
{
#if !UCONFIG_NO_SERVICE
umtx_lock(NULL);
UBool haveService = gService != NULL;
umtx_unlock(NULL);
if (haveService) {
return (NumberFormat*)gService->get(loc, kind, status);
}
else
#endif
{
return makeInstance(loc, kind, status);
}
}
// -------------------------------------
// Checks if the thousand/10 thousand grouping is used in the
@ -915,10 +920,12 @@ U_NAMESPACE_END
* Release all static memory held by numberformat.
*/
U_CFUNC UBool numfmt_cleanup(void) {
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
gService = NULL;
}
#endif
return TRUE;
}

View file

@ -356,8 +356,11 @@ ucol_open(const char *loc,
UCollator *result = NULL;
u_init(status);
#if !UCONFIG_NO_SERVICE
result = Collator::createUCollator(loc, status);
if (result == NULL) {
if (result == NULL)
#endif
{
result = ucol_open_internal(loc, status);
}
UTRACE_EXIT_PTR_STATUS(result, *status);
@ -7541,6 +7544,7 @@ ucol_countAvailable()
return uloc_countAvailable();
}
#if !UCONFIG_NO_SERVICE
U_CAPI UEnumeration* U_EXPORT2
ucol_openAvailableLocales(UErrorCode *status) {
// This is a wrapper over Collator::getAvailableLocales()
@ -7554,6 +7558,7 @@ ucol_openAvailableLocales(UErrorCode *status) {
}
return uenum_openStringEnumeration(s, status);
}
#endif
// Note: KEYWORDS[0] != RESOURCE_NAME - alan

View file

@ -19,7 +19,7 @@
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
#include "iculserv.h"
#include "mutex.h"
#include "ucln_in.h"
//------------------------------------------------------------
@ -142,6 +142,33 @@ _findMetaData(const UChar* currency, UErrorCode& ec) {
return data;
}
// -------------------------------------
/**
* @see VARIANT_IS_EURO
* @see VARIANT_IS_PREEURO
*/
static uint32_t
idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec)
{
uint32_t variantType = 0;
// !!! 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[ULOC_FULLNAME_CAPACITY];
uloc_getCountry(locale, countryAndVariant, capacity, ec);
uloc_getVariant(locale, variant, sizeof(variant), ec);
if (variant[0] != 0) {
variantType = (0 == uprv_strcmp(variant, VAR_EURO))
| ((0 == uprv_strcmp(variant, VAR_PRE_EURO)) << 1);
if (variantType)
{
uprv_strcat(countryAndVariant, VAR_DELIM);
uprv_strcat(countryAndVariant, variant);
}
}
return variantType;
}
// ------------------------------------------
//
@ -151,6 +178,7 @@ _findMetaData(const UChar* currency, UErrorCode& ec) {
// don't use ICUService since we don't need fallback
#if !UCONFIG_NO_SERVICE
struct CReg;
/* Remember to call umtx_init(&gCRegLock) before using it! */
@ -245,34 +273,6 @@ struct CReg : public UMemory {
// -------------------------------------
/**
* @see VARIANT_IS_EURO
* @see VARIANT_IS_PREEURO
*/
static uint32_t
idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec)
{
uint32_t variantType = 0;
// !!! 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[ULOC_FULLNAME_CAPACITY];
uloc_getCountry(locale, countryAndVariant, capacity, ec);
uloc_getVariant(locale, variant, sizeof(variant), ec);
if (variant[0] != 0) {
variantType = (0 == uprv_strcmp(variant, VAR_EURO))
| ((0 == uprv_strcmp(variant, VAR_PRE_EURO)) << 1);
if (variantType)
{
uprv_strcat(countryAndVariant, VAR_DELIM);
uprv_strcat(countryAndVariant, variant);
}
}
return variantType;
}
// -------------------------------------
U_CAPI UCurrRegistryKey U_EXPORT2
ucurr_register(const UChar* isoCode, const char* locale, UErrorCode *status)
{
@ -294,6 +294,7 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status)
}
return FALSE;
}
#endif /* UCONFIG_NO_SERVICE */
// -------------------------------------
@ -322,6 +323,7 @@ ucurr_forLocale(const char* locale,
return 0;
}
#if !UCONFIG_NO_SERVICE
const UChar* result = CReg::get(id);
if (result) {
if(buffCapacity > u_strlen(result)) {
@ -329,6 +331,7 @@ ucurr_forLocale(const char* locale,
}
return u_strlen(result);
}
#endif
// Look up the CurrencyMap element in the root bundle.
UResourceBundle *rb = ures_open(NULL, "", &localStatus);
@ -685,7 +688,9 @@ ucurr_getRoundingIncrement(const UChar* currency, UErrorCode* ec) {
* Release all static memory held by currency.
*/
U_CFUNC UBool currency_cleanup(void) {
#if !UCONFIG_NO_SERVICE
CReg::cleanup();
#endif
return TRUE;
}

View file

@ -58,6 +58,7 @@ U_NAMESPACE_BEGIN
class StringEnumeration;
#if !UCONFIG_NO_SERVICE
/**
* @draft ICU 2.6
*/
@ -67,6 +68,7 @@ typedef const void* URegistryKey;
* @draft ICU 2.6
*/
class CollatorFactory;
#endif
/**
* @stable ICU 2.0
@ -602,6 +604,7 @@ public:
*/
static const Locale* getAvailableLocales(int32_t& count);
#if !UCONFIG_NO_SERVICE
/**
* Return a StringEnumeration over the locales available at the time of the call,
* including registered locales. If a severe error occurs (such as out of memory
@ -611,6 +614,7 @@ public:
* @draft ICU 2.6
*/
static StringEnumeration* getAvailableLocales(void);
#endif
/**
* Create a string enumerator of all possible keywords that are relevant to
@ -666,6 +670,7 @@ public:
static Locale getFunctionalEquivalent(const char* keyword, const Locale& locale,
UBool& isAvailable, UErrorCode& status);
#if !UCONFIG_NO_SERVICE
/**
* Register a new Collator. The collator will be adopted.
* @param toAdopt the Collator instance to be adopted
@ -696,6 +701,7 @@ public:
* @draft ICU 2.6
*/
static UBool unregister(URegistryKey key, UErrorCode& status);
#endif /* UCONFIG_NO_SERVICE */
/**
* Gets the version information for a Collator.
@ -923,12 +929,13 @@ protected:
virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
public:
#if !UCONFIG_NO_SERVICE
/**
* used only by ucol_open, not for public use
* @internal
*/
static UCollator* createUCollator(const char* loc, UErrorCode* status);
#endif
private:
/**
* Assignment operator. Private for now.
@ -954,6 +961,7 @@ private:
/* static const UVersionInfo fVersion;*/
};
#if !UCONFIG_NO_SERVICE
/**
* A factory, used with registerFactory, the creates multiple collators and provides
* display names for them. A factory supports some number of locales-- these are the
@ -1022,21 +1030,10 @@ public:
*/
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
};
#endif /* UCONFIG_NO_SERVICE */
// Collator inline methods -----------------------------------------------
/*
synwee : removed since there's no attribute to be retrieved here
inline UCollationStrength Collator::getStrength() const
{
return strength;
}
inline Normalizer::EMode Collator::getDecomposition() const
{
return decmp;
}
*/
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_COLLATION */

View file

@ -488,6 +488,7 @@ public:
*/
static const Locale* getAvailableLocales(int32_t& count);
#if !UCONFIG_NO_SERVICE
/**
* Register a new NumberFormatFactory. The factory will be adopted.
* @param toAdopt the NumberFormatFactory instance to be adopted
@ -515,6 +516,7 @@ public:
* @draft ICU 2.6
*/
static StringEnumeration* getAvailableLocales(void);
#endif /* UCONFIG_NO_SERVICE */
/**
* Returns true if grouping is used in this format. For example,
@ -753,6 +755,7 @@ private:
friend class ICUNumberFormatService;
};
#if !UCONFIG_NO_SERVICE
/**
* A NumberFormatFactory is used to register new number formats. The factory
* should be able to create any of the predefined formats for each locale it
@ -838,7 +841,7 @@ public:
*/
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
};
#endif /* #if !UCONFIG_NO_SERVICE */
// -------------------------------------

View file

@ -537,6 +537,7 @@ ucol_getAvailable(int32_t index);
U_STABLE int32_t U_EXPORT2
ucol_countAvailable(void);
#if !UCONFIG_NO_SERVICE
/**
* Create a string enumerator of all locales for which a valid
* collator may be opened.
@ -547,6 +548,7 @@ ucol_countAvailable(void);
*/
U_DRAFT UEnumeration* U_EXPORT2
ucol_openAvailableLocales(UErrorCode *status);
#endif
/**
* Create a string enumerator of all possible keywords that are relevant to

View file

@ -11,11 +11,6 @@
#if !UCONFIG_NO_FORMATTING
/**
* @internal
*/
typedef const void* UCurrRegistryKey;
/**
* The ucurr API encapsulates information about a currency, as defined by
* ISO 4217. A currency is represented by a 3-character string
@ -76,6 +71,12 @@ typedef enum UCurrNameStyle {
UCURR_LONG_NAME
} UCurrNameStyle;
#if !UCONFIG_NO_SERVICE
/**
* @internal
*/
typedef const void* UCurrRegistryKey;
/**
* Register an (existing) ISO 4217 currency code for the given locale.
* Only the country code and the two variants EURO and PRE_EURO are
@ -88,7 +89,7 @@ typedef enum UCurrNameStyle {
* @draft ICU 2.6
*/
U_DRAFT UCurrRegistryKey U_EXPORT2
ucurr_register(const UChar* isoCode,
ucurr_register(const UChar* isoCode,
const char* locale,
UErrorCode* status);
/**
@ -103,7 +104,8 @@ U_DRAFT UCurrRegistryKey U_EXPORT2
* @draft ICU 2.6
*/
U_DRAFT UBool U_EXPORT2
ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
#endif /* UCONFIG_NO_SERVICE */
/**
* Returns the display name for the given currency in the