intl/icu/source/common/servlkf.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial