]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/servlkf.cpp
ICU-551.30.tar.gz
[apple/icu.git] / icuSources / common / servlkf.cpp
CommitLineData
73c04bcf
A
1/**
2 *******************************************************************************
b331163b 3 * Copyright (C) 2001-2014, International Business Machines Corporation and *
73c04bcf
A
4 * others. All Rights Reserved. *
5 *******************************************************************************
6 *
7 *******************************************************************************
8 */
9#include "unicode/utypes.h"
10
11#if !UCONFIG_NO_SERVICE
12
13#include "unicode/resbund.h"
14#include "uresimp.h"
15#include "cmemory.h"
16#include "servloc.h"
17#include "ustrfmt.h"
18#include "uhash.h"
19#include "charstr.h"
20#include "ucln_cmn.h"
21#include "uassert.h"
22
23#define UNDERSCORE_CHAR ((UChar)0x005f)
24#define AT_SIGN_CHAR ((UChar)64)
25#define PERIOD_CHAR ((UChar)46)
26
27
28U_NAMESPACE_BEGIN
29
30LocaleKeyFactory::LocaleKeyFactory(int32_t coverage)
31 : _name()
32 , _coverage(coverage)
33{
34}
35
36LocaleKeyFactory::LocaleKeyFactory(int32_t coverage, const UnicodeString& name)
37 : _name(name)
38 , _coverage(coverage)
39{
40}
41
42LocaleKeyFactory::~LocaleKeyFactory() {
43}
44
45UObject*
46LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const {
47 if (handlesKey(key, status)) {
48 const LocaleKey& lkey = (const LocaleKey&)key;
49 int32_t kind = lkey.kind();
50 Locale loc;
51 lkey.currentLocale(loc);
52
53 return handleCreate(loc, kind, service, status);
54 }
55 return NULL;
56}
57
58UBool
59LocaleKeyFactory::handlesKey(const ICUServiceKey& key, UErrorCode& status) const {
60 const Hashtable* supported = getSupportedIDs(status);
61 if (supported) {
62 UnicodeString id;
63 key.currentID(id);
64 return supported->get(id) != NULL;
65 }
66 return FALSE;
67}
68
69void
70LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const {
71 const Hashtable* supported = getSupportedIDs(status);
72 if (supported) {
73 UBool visible = (_coverage & 0x1) == 0;
73c04bcf 74 const UHashElement* elem = NULL;
b331163b 75 int32_t pos = UHASH_FIRST;
73c04bcf
A
76 while ((elem = supported->nextElement(pos)) != NULL) {
77 const UnicodeString& id = *((const UnicodeString*)elem->key.pointer);
78 if (!visible) {
79 result.remove(id);
80 } else {
81 result.put(id, (void*)this, status); // this is dummy non-void marker used for set semantics
82 if (U_FAILURE(status)) {
83 break;
84 }
85 }
86 }
87 }
88}
89
90UnicodeString&
91LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const {
92 if ((_coverage & 0x1) == 0) {
93 //UErrorCode status = U_ZERO_ERROR;
94 // assume if this is called on us, we support some fallback of this id
95 // if (isSupportedID(id, status)) {
96 Locale loc;
97 LocaleUtility::initLocaleFromName(id, loc);
98 return loc.getDisplayName(locale, result);
99 // }
100 }
101 result.setToBogus();
102 return result;
103}
104
105UObject*
106LocaleKeyFactory::handleCreate(const Locale& /* loc */,
107 int32_t /* kind */,
108 const ICUService* /* service */,
109 UErrorCode& /* status */) const {
110 return NULL;
111}
112
113//UBool
114//LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
115// const Hashtable* ids = getSupportedIDs(status);
116// return ids && ids->get(id);
117//}
118
119const Hashtable*
120LocaleKeyFactory::getSupportedIDs(UErrorCode& /* status */) const {
121 return NULL;
122}
123
124#ifdef SERVICE_DEBUG
125UnicodeString&
126LocaleKeyFactory::debug(UnicodeString& result) const
127{
128 debugClass(result);
b331163b 129 result.append((UnicodeString)", name: ");
73c04bcf 130 result.append(_name);
b331163b 131 result.append((UnicodeString)", coverage: ");
73c04bcf
A
132 result.append(_coverage);
133 return result;
134}
135
136UnicodeString&
137LocaleKeyFactory::debugClass(UnicodeString& result) const
138{
b331163b 139 return result.append((UnicodeString)"LocaleKeyFactory");
73c04bcf
A
140}
141#endif
142
143UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocaleKeyFactory)
144
145U_NAMESPACE_END
146
147/* !UCONFIG_NO_SERVICE */
148#endif
149
150