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 ((char16_t)0x005f) |
25 | #define AT_SIGN_CHAR ((char16_t)64) |
26 | #define PERIOD_CHAR ((char16_t)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 | { |
43 | } |
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 | { |
54 | LocaleUtility::initNameFromLocale(locale, _id); |
55 | } |
56 | |
57 | SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory() |
58 | { |
59 | delete _obj; |
60 | _obj = nullptr; |
61 | } |
62 | |
63 | UObject* |
64 | SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const |
65 | { |
66 | if (U_SUCCESS(status)) { |
67 | const LocaleKey& lkey = static_cast<const LocaleKey&>(key); |
68 | if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) { |
69 | UnicodeString keyID; |
70 | lkey.currentID(keyID); |
71 | if (_id == keyID) { |
72 | return service->cloneInstance(_obj); |
73 | } |
74 | } |
75 | } |
76 | return nullptr; |
77 | } |
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 | { |
88 | if (U_SUCCESS(status)) { |
89 | if (_coverage & 0x1) { |
90 | result.remove(_id); |
91 | } else { |
92 | result.put(_id, (void*)this, status); |
93 | } |
94 | } |
95 | } |
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 | |
124 | |