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: ICUResourceBundleFactory::ICUResourceBundleFactory() michael@0: : LocaleKeyFactory(VISIBLE) michael@0: , _bundleName() michael@0: { michael@0: } michael@0: michael@0: ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName) michael@0: : LocaleKeyFactory(VISIBLE) michael@0: , _bundleName(bundleName) michael@0: { michael@0: } michael@0: michael@0: ICUResourceBundleFactory::~ICUResourceBundleFactory() {} michael@0: michael@0: const Hashtable* michael@0: ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const michael@0: { michael@0: if (U_SUCCESS(status)) { michael@0: return LocaleUtility::getAvailableLocaleNames(_bundleName); michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: UObject* michael@0: ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const michael@0: { michael@0: if (U_SUCCESS(status)) { michael@0: // _bundleName is a package name michael@0: // and should only contain invariant characters michael@0: // ??? is it always true that the max length of the bundle name is 19? michael@0: // who made this change? -- dlf michael@0: char pkg[20]; michael@0: int32_t length; michael@0: length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV); michael@0: if(length>=(int32_t)sizeof(pkg)) { michael@0: return NULL; michael@0: } michael@0: return new ResourceBundle(pkg, loc, status); michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: #ifdef SERVICE_DEBUG michael@0: UnicodeString& michael@0: ICUResourceBundleFactory::debug(UnicodeString& result) const michael@0: { michael@0: LocaleKeyFactory::debug(result); michael@0: result.append(", bundle: "); michael@0: return result.append(_bundleName); michael@0: } michael@0: michael@0: UnicodeString& michael@0: ICUResourceBundleFactory::debugClass(UnicodeString& result) const michael@0: { michael@0: return result.append("ICUResourceBundleFactory"); michael@0: } michael@0: #endif michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory) michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: /* !UCONFIG_NO_SERVICE */ michael@0: #endif michael@0: michael@0: