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: U_NAMESPACE_BEGIN michael@0: michael@0: /* michael@0: ****************************************************************** michael@0: */ michael@0: michael@0: SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt, michael@0: const UnicodeString& locale, michael@0: int32_t kind, michael@0: int32_t coverage) michael@0: : LocaleKeyFactory(coverage) michael@0: , _obj(objToAdopt) michael@0: , _id(locale) michael@0: , _kind(kind) michael@0: { michael@0: } michael@0: michael@0: SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt, michael@0: const Locale& locale, michael@0: int32_t kind, michael@0: int32_t coverage) michael@0: : LocaleKeyFactory(coverage) michael@0: , _obj(objToAdopt) michael@0: , _id() michael@0: , _kind(kind) michael@0: { michael@0: LocaleUtility::initNameFromLocale(locale, _id); michael@0: } michael@0: michael@0: SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory() michael@0: { michael@0: delete _obj; michael@0: _obj = NULL; michael@0: } michael@0: michael@0: UObject* michael@0: SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const michael@0: { michael@0: if (U_SUCCESS(status)) { michael@0: const LocaleKey& lkey = (const LocaleKey&)key; michael@0: if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) { michael@0: UnicodeString keyID; michael@0: lkey.currentID(keyID); michael@0: if (_id == keyID) { michael@0: return service->cloneInstance(_obj); michael@0: } michael@0: } michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: //UBool michael@0: //SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const michael@0: //{ michael@0: // return id == _id; michael@0: //} michael@0: michael@0: void michael@0: SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const michael@0: { michael@0: if (U_SUCCESS(status)) { michael@0: if (_coverage & 0x1) { michael@0: result.remove(_id); michael@0: } else { michael@0: result.put(_id, (void*)this, status); michael@0: } michael@0: } michael@0: } michael@0: michael@0: #ifdef SERVICE_DEBUG michael@0: UnicodeString& michael@0: SimpleLocaleKeyFactory::debug(UnicodeString& result) const michael@0: { michael@0: LocaleKeyFactory::debug(result); michael@0: result.append(", id: "); michael@0: result.append(_id); michael@0: result.append(", kind: "); michael@0: result.append(_kind); michael@0: return result; michael@0: } michael@0: michael@0: UnicodeString& michael@0: SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const michael@0: { michael@0: return result.append("SimpleLocaleKeyFactory"); michael@0: } michael@0: #endif michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory) michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: /* !UCONFIG_NO_SERVICE */ michael@0: #endif michael@0: michael@0: