michael@0: /** michael@0: ******************************************************************************* michael@0: * Copyright (C) 2001-2005, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: * michael@0: ******************************************************************************* michael@0: */ michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_SERVICE michael@0: michael@0: #include "unicode/resbund.h" michael@0: #include "uresimp.h" michael@0: #include "cmemory.h" michael@0: #include "servloc.h" michael@0: #include "ustrfmt.h" michael@0: #include "uhash.h" michael@0: #include "charstr.h" michael@0: #include "ucln_cmn.h" michael@0: #include "uassert.h" michael@0: michael@0: #define UNDERSCORE_CHAR ((UChar)0x005f) michael@0: #define AT_SIGN_CHAR ((UChar)64) michael@0: #define PERIOD_CHAR ((UChar)46) michael@0: michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: LocaleKeyFactory::LocaleKeyFactory(int32_t coverage) michael@0: : _name() michael@0: , _coverage(coverage) michael@0: { michael@0: } michael@0: michael@0: LocaleKeyFactory::LocaleKeyFactory(int32_t coverage, const UnicodeString& name) michael@0: : _name(name) michael@0: , _coverage(coverage) michael@0: { michael@0: } michael@0: michael@0: LocaleKeyFactory::~LocaleKeyFactory() { michael@0: } michael@0: michael@0: UObject* michael@0: LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const { michael@0: if (handlesKey(key, status)) { michael@0: const LocaleKey& lkey = (const LocaleKey&)key; michael@0: int32_t kind = lkey.kind(); michael@0: Locale loc; michael@0: lkey.currentLocale(loc); michael@0: michael@0: return handleCreate(loc, kind, service, status); michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: UBool michael@0: LocaleKeyFactory::handlesKey(const ICUServiceKey& key, UErrorCode& status) const { michael@0: const Hashtable* supported = getSupportedIDs(status); michael@0: if (supported) { michael@0: UnicodeString id; michael@0: key.currentID(id); michael@0: return supported->get(id) != NULL; michael@0: } michael@0: return FALSE; michael@0: } michael@0: michael@0: void michael@0: LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const { michael@0: const Hashtable* supported = getSupportedIDs(status); michael@0: if (supported) { michael@0: UBool visible = (_coverage & 0x1) == 0; michael@0: michael@0: const UHashElement* elem = NULL; michael@0: int32_t pos = 0; michael@0: while ((elem = supported->nextElement(pos)) != NULL) { michael@0: const UnicodeString& id = *((const UnicodeString*)elem->key.pointer); michael@0: if (!visible) { michael@0: result.remove(id); michael@0: } else { michael@0: result.put(id, (void*)this, status); // this is dummy non-void marker used for set semantics michael@0: if (U_FAILURE(status)) { michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: UnicodeString& michael@0: LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const { michael@0: if ((_coverage & 0x1) == 0) { michael@0: //UErrorCode status = U_ZERO_ERROR; michael@0: // assume if this is called on us, we support some fallback of this id michael@0: // if (isSupportedID(id, status)) { michael@0: Locale loc; michael@0: LocaleUtility::initLocaleFromName(id, loc); michael@0: return loc.getDisplayName(locale, result); michael@0: // } michael@0: } michael@0: result.setToBogus(); michael@0: return result; michael@0: } michael@0: michael@0: UObject* michael@0: LocaleKeyFactory::handleCreate(const Locale& /* loc */, michael@0: int32_t /* kind */, michael@0: const ICUService* /* service */, michael@0: UErrorCode& /* status */) const { michael@0: return NULL; michael@0: } michael@0: michael@0: //UBool michael@0: //LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const { michael@0: // const Hashtable* ids = getSupportedIDs(status); michael@0: // return ids && ids->get(id); michael@0: //} michael@0: michael@0: const Hashtable* michael@0: LocaleKeyFactory::getSupportedIDs(UErrorCode& /* status */) const { michael@0: return NULL; michael@0: } michael@0: michael@0: #ifdef SERVICE_DEBUG michael@0: UnicodeString& michael@0: LocaleKeyFactory::debug(UnicodeString& result) const michael@0: { michael@0: debugClass(result); michael@0: result.append(", name: "); michael@0: result.append(_name); michael@0: result.append(", coverage: "); michael@0: result.append(_coverage); michael@0: return result; michael@0: } michael@0: michael@0: UnicodeString& michael@0: LocaleKeyFactory::debugClass(UnicodeString& result) const michael@0: { michael@0: return result.append("LocaleKeyFactory"); michael@0: } michael@0: #endif michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocaleKeyFactory) michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: /* !UCONFIG_NO_SERVICE */ michael@0: #endif michael@0: michael@0: