1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius * Copyright (C) 2001-2012, International Business Machines Corporation and * 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. * 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_SERVICE 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/resbund.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uresimp.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "servloc.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ustrfmt.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "charstr.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucln_cmn.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uassert.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UNDERSCORE_CHAR ((UChar)0x005f) 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define AT_SIGN_CHAR ((UChar)64) 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define PERIOD_CHAR ((UChar)46) 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2854dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic UMutex llock = U_MUTEX_INITIALIZER; 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::ICULocaleService() 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru : fallbackLocale(Locale::getDefault()) 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::ICULocaleService(const UnicodeString& dname) 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru : ICUService(dname) 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru , fallbackLocale(Locale::getDefault()) 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::~ICULocaleService() 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUObject* 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::get(const Locale& locale, UErrorCode& status) const 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return get(locale, LocaleKey::KIND_ANY, NULL, status); 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUObject* 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::get(const Locale& locale, int32_t kind, UErrorCode& status) const 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return get(locale, kind, NULL, status); 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUObject* 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::get(const Locale& locale, Locale* actualReturn, UErrorCode& status) const 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return get(locale, LocaleKey::KIND_ANY, actualReturn, status); 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUObject* 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::get(const Locale& locale, int32_t kind, Locale* actualReturn, UErrorCode& status) const 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UObject* result = NULL; 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString locName(locale.getName(), -1, US_INV); 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (locName.isBogus()) { 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_MEMORY_ALLOCATION_ERROR; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUServiceKey* key = createKey(&locName, kind, status); 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (key) { 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (actualReturn == NULL) { 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = getKey(*key, status); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString temp; 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru result = getKey(*key, &temp, status); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (result != NULL) { 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru key->parseSuffix(temp); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LocaleUtility::initLocaleFromName(temp, *actualReturn); 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete key; 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result; 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool visible, UErrorCode& status) 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale loc; 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LocaleUtility::initLocaleFromName(locale, loc); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerInstance(objToAdopt, loc, LocaleKey::KIND_ANY, 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE, status); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, UErrorCode& status) 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status); 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, UErrorCode& status) 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerInstance(objToAdopt, locale, kind, LocaleKeyFactory::VISIBLE, status); 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status) 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage); 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (factory != NULL) { 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerFactory(factory, status); 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete objToAdopt; 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UErrorCode& status) 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status); 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status) 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE, 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status); 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruURegistryKey 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, int32_t kind, int32_t coverage, UErrorCode& status) 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage); 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (factory != NULL) { 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return registerFactory(factory, status); 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete objToAdopt; 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass ServiceEnumeration : public StringEnumeration { 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const ICULocaleService* _service; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t _timestamp; 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVector _ids; 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t _pos; 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ServiceEnumeration(const ICULocaleService* service, UErrorCode &status) 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru : _service(service) 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru , _timestamp(service->getTimestamp()) 165103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius , _ids(uprv_deleteUObject, NULL, status) 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru , _pos(0) 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _service->getVisibleIDs(_ids, status); 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ServiceEnumeration(const ServiceEnumeration &other, UErrorCode &status) 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru : _service(other._service) 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru , _timestamp(other._timestamp) 174103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius , _ids(uprv_deleteUObject, NULL, status) 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru , _pos(0) 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, length; 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length = other._ids.size(); 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < length; ++i) { 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _ids.addElement(((UnicodeString *)other._ids.elementAt(i))->clone(), status); 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _pos = other._pos; 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static ServiceEnumeration* create(const ICULocaleService* service) { 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ServiceEnumeration* result = new ServiceEnumeration(service, status); 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result; 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete result; 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 202103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius virtual ~ServiceEnumeration(); 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual StringEnumeration *clone() const { 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ServiceEnumeration *cl = new ServiceEnumeration(*this, status); 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete cl; 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cl = NULL; 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return cl; 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool upToDate(UErrorCode& status) const { 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (_timestamp == _service->getTimestamp()) { 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return TRUE; 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ENUM_OUT_OF_SYNC_ERROR; 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual int32_t count(UErrorCode& status) const { 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return upToDate(status) ? _ids.size() : 0; 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual const UnicodeString* snext(UErrorCode& status) { 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (upToDate(status) && (_pos < _ids.size())) { 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (const UnicodeString*)_ids[_pos++]; 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void reset(UErrorCode& status) { 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status == U_ENUM_OUT_OF_SYNC_ERROR) { 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_SUCCESS(status)) { 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _timestamp = _service->getTimestamp(); 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _pos = 0; 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru _service->getVisibleIDs(_ids, status); 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static UClassID U_EXPORT2 getStaticClassID(void); 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UClassID getDynamicClassID(void) const; 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 251103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusServiceEnumeration::~ServiceEnumeration() {} 252103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(ServiceEnumeration) 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruStringEnumeration* 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::getAvailableLocales(void) const 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return ServiceEnumeration::create(this); 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UnicodeString& 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::validateFallbackLocale() const 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Locale& loc = Locale::getDefault(); 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICULocaleService* ncThis = (ICULocaleService*)this; 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 267b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho Mutex mutex(&llock); 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (loc != fallbackLocale) { 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ncThis->fallbackLocale = loc; 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LocaleUtility::initNameFromLocale(loc, ncThis->fallbackLocaleName); 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ncThis->clearServiceCache(); 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return fallbackLocaleName; 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICUServiceKey* 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::createKey(const UnicodeString* id, UErrorCode& status) const 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), status); 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICUServiceKey* 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruICULocaleService::createKey(const UnicodeString* id, int32_t kind, UErrorCode& status) const 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), kind, status); 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* !UCONFIG_NO_SERVICE */ 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 295