| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/** |
| 4 |
******************************************************************************* |
| 5 |
* Copyright (C) 2001-2014, International Business Machines Corporation and * |
| 6 |
* others. All Rights Reserved. * |
| 7 |
******************************************************************************* |
| 8 |
* |
| 9 |
******************************************************************************* |
| 10 |
*/ |
| 11 |
#include "unicode/utypes.h" |
| 12 |
|
| 13 |
#if !UCONFIG_NO_SERVICE |
| 14 |
|
| 15 |
#include "unicode/resbund.h" |
| 16 |
#include "uresimp.h" |
| 17 |
#include "cmemory.h" |
| 18 |
#include "servloc.h" |
| 19 |
#include "ustrfmt.h" |
| 20 |
#include "uhash.h" |
| 21 |
#include "charstr.h" |
| 22 |
#include "ucln_cmn.h" |
| 23 |
#include "uassert.h" |
| 24 |
|
| 25 |
#define UNDERSCORE_CHAR ((char16_t)0x005f) |
| 26 |
#define AT_SIGN_CHAR ((char16_t)64) |
| 27 |
#define PERIOD_CHAR ((char16_t)46) |
| 28 |
|
| 29 |
U_NAMESPACE_BEGIN |
| 30 |
|
| 31 |
ICUResourceBundleFactory::ICUResourceBundleFactory() |
| 32 |
: LocaleKeyFactory(VISIBLE) |
| 33 |
, _bundleName() |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName) |
| 38 |
: LocaleKeyFactory(VISIBLE) |
| 39 |
, _bundleName(bundleName) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
ICUResourceBundleFactory::~ICUResourceBundleFactory() {} |
| 44 |
|
| 45 |
const Hashtable* |
| 46 |
ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const |
| 47 |
{ |
| 48 |
if (U_SUCCESS(status)) { |
| 49 |
return LocaleUtility::getAvailableLocaleNames(_bundleName); |
| 50 |
} |
| 51 |
return nullptr; |
| 52 |
} |
| 53 |
|
| 54 |
UObject* |
| 55 |
ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const |
| 56 |
{ |
| 57 |
if (U_SUCCESS(status)) { |
| 58 |
// _bundleName is a package name |
| 59 |
// and should only contain invariant characters |
| 60 |
// ??? is it always true that the max length of the bundle name is 19? |
| 61 |
// who made this change? -- dlf |
| 62 |
char pkg[20]; |
| 63 |
int32_t length; |
| 64 |
length = _bundleName.extract(0, INT32_MAX, pkg, static_cast<int32_t>(sizeof(pkg)), US_INV); |
| 65 |
if (length >= static_cast<int32_t>(sizeof(pkg))) { |
| 66 |
return nullptr; |
| 67 |
} |
| 68 |
return new ResourceBundle(pkg, loc, status); |
| 69 |
} |
| 70 |
return nullptr; |
| 71 |
} |
| 72 |
|
| 73 |
#ifdef SERVICE_DEBUG |
| 74 |
UnicodeString& |
| 75 |
ICUResourceBundleFactory::debug(UnicodeString& result) const |
| 76 |
{ |
| 77 |
LocaleKeyFactory::debug(result); |
| 78 |
result.append((UnicodeString)", bundle: "); |
| 79 |
return result.append(_bundleName); |
| 80 |
} |
| 81 |
|
| 82 |
UnicodeString& |
| 83 |
ICUResourceBundleFactory::debugClass(UnicodeString& result) const |
| 84 |
{ |
| 85 |
return result.append((UnicodeString)"ICUResourceBundleFactory"); |
| 86 |
} |
| 87 |
#endif |
| 88 |
|
| 89 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory) |
| 90 |
|
| 91 |
U_NAMESPACE_END |
| 92 |
|
| 93 |
/* !UCONFIG_NO_SERVICE */ |
| 94 |
#endif |
| 95 |
|
| 96 |
|