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