]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/servslkf.cpp
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / common / servslkf.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"
73c04bcf
A
20#include "uassert.h"
21
22#define UNDERSCORE_CHAR ((UChar)0x005f)
23#define AT_SIGN_CHAR ((UChar)64)
24#define PERIOD_CHAR ((UChar)46)
25
26U_NAMESPACE_BEGIN
27
28/*
29 ******************************************************************
30 */
31
32SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
33 const UnicodeString& locale,
34 int32_t kind,
35 int32_t coverage)
36 : LocaleKeyFactory(coverage)
37 , _obj(objToAdopt)
38 , _id(locale)
39 , _kind(kind)
40{
41}
42
43SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
44 const Locale& locale,
45 int32_t kind,
46 int32_t coverage)
47 : LocaleKeyFactory(coverage)
48 , _obj(objToAdopt)
49 , _id()
50 , _kind(kind)
51{
52 LocaleUtility::initNameFromLocale(locale, _id);
53}
54
55SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
56{
57 delete _obj;
58 _obj = NULL;
59}
60
61UObject*
62SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
63{
64 if (U_SUCCESS(status)) {
65 const LocaleKey& lkey = (const LocaleKey&)key;
66 if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
67 UnicodeString keyID;
68 lkey.currentID(keyID);
69 if (_id == keyID) {
70 return service->cloneInstance(_obj);
71 }
72 }
73 }
74 return NULL;
75}
76
77//UBool
78//SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
79//{
80// return id == _id;
81//}
82
83void
84SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
85{
86 if (U_SUCCESS(status)) {
87 if (_coverage & 0x1) {
88 result.remove(_id);
89 } else {
90 result.put(_id, (void*)this, status);
91 }
92 }
93}
94
95#ifdef SERVICE_DEBUG
96UnicodeString&
97SimpleLocaleKeyFactory::debug(UnicodeString& result) const
98{
99 LocaleKeyFactory::debug(result);
b331163b 100 result.append((UnicodeString)", id: ");
73c04bcf 101 result.append(_id);
b331163b 102 result.append((UnicodeString)", kind: ");
73c04bcf
A
103 result.append(_kind);
104 return result;
105}
106
107UnicodeString&
108SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
109{
b331163b 110 return result.append((UnicodeString)"SimpleLocaleKeyFactory");
73c04bcf
A
111}
112#endif
113
114UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory)
115
116U_NAMESPACE_END
117
118/* !UCONFIG_NO_SERVICE */
119#endif
120
121