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