1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2001-2014, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
9 *******************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_SERVICE
15 #include "unicode/resbund.h"
25 #define UNDERSCORE_CHAR ((UChar)0x005f)
26 #define AT_SIGN_CHAR ((UChar)64)
27 #define PERIOD_CHAR ((UChar)46)
32 LocaleKeyFactory::LocaleKeyFactory(int32_t coverage)
38 LocaleKeyFactory::LocaleKeyFactory(int32_t coverage, const UnicodeString& name)
44 LocaleKeyFactory::~LocaleKeyFactory() {
48 LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const {
49 if (handlesKey(key, status)) {
50 const LocaleKey& lkey = (const LocaleKey&)key;
51 int32_t kind = lkey.kind();
53 lkey.currentLocale(loc);
55 return handleCreate(loc, kind, service, status);
61 LocaleKeyFactory::handlesKey(const ICUServiceKey& key, UErrorCode& status) const {
62 const Hashtable* supported = getSupportedIDs(status);
66 return supported->get(id) != NULL;
72 LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const {
73 const Hashtable* supported = getSupportedIDs(status);
75 UBool visible = (_coverage & 0x1) == 0;
76 const UHashElement* elem = NULL;
77 int32_t pos = UHASH_FIRST;
78 while ((elem = supported->nextElement(pos)) != NULL) {
79 const UnicodeString& id = *((const UnicodeString*)elem->key.pointer);
83 result.put(id, (void*)this, status); // this is dummy non-void marker used for set semantics
84 if (U_FAILURE(status)) {
93 LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const {
94 if ((_coverage & 0x1) == 0) {
95 //UErrorCode status = U_ZERO_ERROR;
96 // assume if this is called on us, we support some fallback of this id
97 // if (isSupportedID(id, status)) {
99 LocaleUtility::initLocaleFromName(id, loc);
100 return loc.getDisplayName(locale, result);
108 LocaleKeyFactory::handleCreate(const Locale& /* loc */,
110 const ICUService* /* service */,
111 UErrorCode& /* status */) const {
116 //LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
117 // const Hashtable* ids = getSupportedIDs(status);
118 // return ids && ids->get(id);
122 LocaleKeyFactory::getSupportedIDs(UErrorCode& /* status */) const {
128 LocaleKeyFactory::debug(UnicodeString& result) const
131 result.append((UnicodeString)", name: ");
132 result.append(_name);
133 result.append((UnicodeString)", coverage: ");
134 result.append(_coverage);
139 LocaleKeyFactory::debugClass(UnicodeString& result) const
141 return result.append((UnicodeString)"LocaleKeyFactory");
145 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocaleKeyFactory)
149 /* !UCONFIG_NO_SERVICE */