2002-11-06 22:14:49 +00:00
|
|
|
/**
|
|
|
|
*******************************************************************************
|
|
|
|
* Copyright (C) 2001-2002, International Business Machines Corporation and *
|
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
|
|
|
|
#include "unicode/resbund.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "iculserv.h"
|
2002-11-30 02:46:55 +00:00
|
|
|
#include "ustrfmt.h"
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-12-14 09:03:22 +00:00
|
|
|
static Hashtable * LocaleUtility_cache = NULL;
|
|
|
|
|
|
|
|
#define UNDERSCORE_CHAR ((UChar)0x005f)
|
|
|
|
|
2002-11-06 22:14:49 +00:00
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleUtility::canonicalLocaleString(const UnicodeString* id, UnicodeString& result)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
|
|
|
if (id == NULL) {
|
|
|
|
result.setToBogus();
|
|
|
|
} else {
|
|
|
|
result = *id;
|
|
|
|
int32_t i = 0;
|
|
|
|
int32_t n = result.indexOf(UNDERSCORE_CHAR);
|
|
|
|
if (n < 0) {
|
|
|
|
n = result.length();
|
|
|
|
}
|
|
|
|
for (; i < n; ++i) {
|
|
|
|
UChar c = result.charAt(i);
|
|
|
|
if (c >= 0x0041 && c <= 0x005a) {
|
|
|
|
c += 0x20;
|
|
|
|
result.setCharAt(i, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (n = result.length(); i < n; ++i) {
|
|
|
|
UChar c = result.charAt(i);
|
|
|
|
if (c >= 0x0061 && c <= 0x007a) {
|
|
|
|
c -= 0x20;
|
|
|
|
result.setCharAt(i, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
Locale&
|
|
|
|
LocaleUtility::initLocaleFromName(const UnicodeString& id, Locale& result)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (id.isBogus()) {
|
|
|
|
result.setToBogus();
|
2002-11-06 22:14:49 +00:00
|
|
|
} else {
|
2002-11-30 02:46:55 +00:00
|
|
|
const int32_t BUFLEN = 128; // larger than ever needed
|
|
|
|
char buffer[BUFLEN];
|
|
|
|
int len = id.extract(0, BUFLEN, buffer);
|
|
|
|
if (len >= BUFLEN) {
|
|
|
|
result.setToBogus();
|
|
|
|
} else {
|
|
|
|
buffer[len] = '\0';
|
|
|
|
result = Locale::createFromName(buffer);
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleUtility::initNameFromLocale(const Locale& locale, UnicodeString& result)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (locale.isBogus()) {
|
|
|
|
result.setToBogus();
|
|
|
|
} else {
|
|
|
|
result.append(locale.getName());
|
|
|
|
}
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const Hashtable*
|
|
|
|
LocaleUtility::getAvailableLocaleNames(const UnicodeString& bundleID)
|
|
|
|
{
|
|
|
|
// have to ignore bundleID for the moment, since we don't have easy C++ api.
|
|
|
|
// assume it's the default bundle
|
|
|
|
|
2003-05-05 23:21:48 +00:00
|
|
|
Hashtable* htp;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
htp = LocaleUtility_cache;
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
if (htp == NULL) {
|
|
|
|
htp = new Hashtable();
|
|
|
|
if (htp) {
|
2002-11-30 02:46:55 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t count = uloc_countAvailable();
|
|
|
|
for (int32_t i = 0; i < count; ++i) {
|
2003-03-20 00:05:11 +00:00
|
|
|
UnicodeString temp(uloc_getAvailable(i), "");
|
2003-05-05 23:21:48 +00:00
|
|
|
htp->put(temp, (void*)htp, status);
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2003-05-05 23:21:48 +00:00
|
|
|
delete htp;
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-05-05 23:21:48 +00:00
|
|
|
umtx_lock(NULL);
|
|
|
|
if (LocaleUtility_cache == NULL) {
|
|
|
|
LocaleUtility_cache = htp;
|
|
|
|
htp = NULL;
|
2002-11-30 02:46:55 +00:00
|
|
|
}
|
2003-05-05 23:21:48 +00:00
|
|
|
umtx_unlock(NULL);
|
|
|
|
delete htp;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-14 09:03:22 +00:00
|
|
|
return LocaleUtility_cache;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UBool
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleUtility::isFallbackOf(const UnicodeString& root, const UnicodeString& child)
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return child.indexOf(root) == 0 &&
|
|
|
|
(child.length() == root.length() ||
|
|
|
|
child.charAt(root.length()) == UNDERSCORE_CHAR);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-12-06 00:22:10 +00:00
|
|
|
UBool
|
|
|
|
LocaleUtility::cleanup(void) {
|
2002-12-14 09:03:22 +00:00
|
|
|
if (LocaleUtility_cache) {
|
|
|
|
delete LocaleUtility_cache;
|
|
|
|
LocaleUtility_cache = NULL;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2002-12-06 00:22:10 +00:00
|
|
|
}
|
|
|
|
|
2002-11-06 22:14:49 +00:00
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
const int32_t LocaleKey::KIND_ANY = -1;
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
LocaleKey*
|
|
|
|
LocaleKey::createWithCanonicalFallback(const UnicodeString* primaryID,
|
2002-11-08 00:20:14 +00:00
|
|
|
const UnicodeString* canonicalFallbackID,
|
2002-11-30 02:46:55 +00:00
|
|
|
UErrorCode& status)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return LocaleKey::createWithCanonicalFallback(primaryID, canonicalFallbackID, KIND_ANY, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
|
|
|
|
LocaleKey*
|
|
|
|
LocaleKey::createWithCanonicalFallback(const UnicodeString* primaryID,
|
|
|
|
const UnicodeString* canonicalFallbackID,
|
2002-11-08 00:20:14 +00:00
|
|
|
int32_t kind,
|
2002-11-30 02:46:55 +00:00
|
|
|
UErrorCode& status)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (primaryID == NULL || U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
UnicodeString canonicalPrimaryID;
|
|
|
|
LocaleUtility::canonicalLocaleString(primaryID, canonicalPrimaryID);
|
|
|
|
return new LocaleKey(*primaryID, canonicalPrimaryID, canonicalFallbackID, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocaleKey::LocaleKey(const UnicodeString& primaryID,
|
|
|
|
const UnicodeString& canonicalPrimaryID,
|
|
|
|
const UnicodeString* canonicalFallbackID,
|
|
|
|
int32_t kind)
|
2002-11-20 17:16:11 +00:00
|
|
|
: ICUServiceKey(primaryID)
|
2002-11-06 22:14:49 +00:00
|
|
|
, _kind(kind)
|
|
|
|
, _primaryID(canonicalPrimaryID)
|
|
|
|
, _fallbackID()
|
|
|
|
, _currentID()
|
|
|
|
{
|
|
|
|
_fallbackID.setToBogus();
|
|
|
|
if (_primaryID.length() != 0) {
|
|
|
|
if (canonicalFallbackID != NULL && _primaryID != *canonicalFallbackID) {
|
|
|
|
_fallbackID = *canonicalFallbackID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentID = _primaryID;
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::prefix(UnicodeString& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
if (_kind != KIND_ANY) {
|
|
|
|
UChar buffer[64];
|
2003-01-27 17:24:33 +00:00
|
|
|
uprv_itou(buffer, 64, _kind, 10, 0);
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString temp(buffer);
|
|
|
|
result.append(temp);
|
|
|
|
}
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
int32_t
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::kind() const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return _kind;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::canonicalID(UnicodeString& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return result.append(_primaryID);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::currentID(UnicodeString& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
if (!_currentID.isBogus()) {
|
|
|
|
result.append(_currentID);
|
|
|
|
}
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::currentDescriptor(UnicodeString& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
if (!_currentID.isBogus()) {
|
|
|
|
prefix(result).append(PREFIX_DELIMITER).append(_currentID);
|
|
|
|
} else {
|
|
|
|
result.setToBogus();
|
|
|
|
}
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
Locale&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::canonicalLocale(Locale& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return LocaleUtility::initLocaleFromName(_primaryID, result);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
Locale&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::currentLocale(Locale& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return LocaleUtility::initLocaleFromName(_currentID, result);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UBool
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::fallback() {
|
2002-11-30 02:46:55 +00:00
|
|
|
if (!_currentID.isBogus()) {
|
|
|
|
int x = _currentID.lastIndexOf(UNDERSCORE_CHAR);
|
|
|
|
if (x != -1) {
|
|
|
|
_currentID.remove(x); // truncate current or fallback, whichever we're pointing to
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
if (!_fallbackID.isBogus()) {
|
|
|
|
_currentID = _fallbackID;
|
|
|
|
_fallbackID.setToBogus();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
if (_currentID.length() > 0) {
|
|
|
|
_currentID.remove(0); // completely truncate
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentID.setToBogus();
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
return FALSE;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UBool
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKey::isFallbackOf(const UnicodeString& id) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString temp(id);
|
|
|
|
parseSuffix(temp);
|
|
|
|
return temp.indexOf(_primaryID) == 0 &&
|
|
|
|
(temp.length() == _primaryID.length() ||
|
|
|
|
temp.charAt(_primaryID.length()) == UNDERSCORE_CHAR);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-20 17:16:11 +00:00
|
|
|
#ifdef SERVICE_DEBUG
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleKey::debug(UnicodeString& result) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-20 17:16:11 +00:00
|
|
|
ICUServiceKey::debug(result);
|
2002-11-06 22:14:49 +00:00
|
|
|
result.append(" kind: ");
|
|
|
|
result.append(_kind);
|
|
|
|
result.append(" primaryID: ");
|
|
|
|
result.append(_primaryID);
|
|
|
|
result.append(" fallbackID: ");
|
|
|
|
result.append(_fallbackID);
|
|
|
|
result.append(" currentID: ");
|
|
|
|
result.append(_currentID);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleKey::debugClass(UnicodeString& result) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
|
|
|
return result.append("LocaleKey ");
|
|
|
|
}
|
2002-11-20 17:16:11 +00:00
|
|
|
#endif
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
const char LocaleKey::fgClassID = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
LocaleKeyFactory::LocaleKeyFactory(int32_t coverage)
|
2002-11-06 22:14:49 +00:00
|
|
|
: _name()
|
|
|
|
, _coverage(coverage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LocaleKeyFactory::LocaleKeyFactory(int32_t coverage, const UnicodeString& name)
|
|
|
|
: _name(name)
|
|
|
|
, _coverage(coverage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LocaleKeyFactory::~LocaleKeyFactory() {
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
2002-11-20 17:16:11 +00:00
|
|
|
LocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
if (handlesKey(key, status)) {
|
|
|
|
const LocaleKey& lkey = (const LocaleKey&)key;
|
|
|
|
int32_t kind = lkey.kind();
|
|
|
|
Locale loc;
|
2003-04-28 21:13:14 +00:00
|
|
|
lkey.currentLocale(loc);
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
return handleCreate(loc, kind, service, status);
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UBool
|
2002-11-20 17:16:11 +00:00
|
|
|
LocaleKeyFactory::handlesKey(const ICUServiceKey& key, UErrorCode& status) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
const Hashtable* supported = getSupportedIDs(status);
|
|
|
|
if (supported) {
|
|
|
|
UnicodeString id;
|
|
|
|
key.currentID(id);
|
|
|
|
return supported->get(id) != NULL;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
void
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
const Hashtable* supported = getSupportedIDs(status);
|
|
|
|
if (supported) {
|
|
|
|
UBool visible = (_coverage & 0x1) == 0;
|
|
|
|
|
|
|
|
const UHashElement* elem = NULL;
|
|
|
|
int32_t pos = 0;
|
|
|
|
while (elem = supported->nextElement(pos)) {
|
|
|
|
const UnicodeString& id = *((const UnicodeString*)elem->key.pointer);
|
|
|
|
if (!visible) {
|
|
|
|
result.remove(id);
|
|
|
|
} else {
|
|
|
|
result.put(id, (void*)this, status); // this is dummy non-void marker used for set semantics
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
if ((_coverage & 0x1) == 0) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2003-05-01 18:59:36 +00:00
|
|
|
if (isSupportedID(id, status)) {
|
2002-11-30 02:46:55 +00:00
|
|
|
Locale loc;
|
|
|
|
LocaleUtility::initLocaleFromName(id, loc);
|
|
|
|
return loc.getDisplayName(locale, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.setToBogus();
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKeyFactory::handleCreate(const Locale& loc, int32_t kind, const ICUService* service, UErrorCode& status) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 18:27:24 +00:00
|
|
|
UBool
|
|
|
|
LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
|
2003-05-01 18:59:36 +00:00
|
|
|
const Hashtable* ids = getSupportedIDs(status);
|
|
|
|
return ids && ids->get(id);
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const Hashtable*
|
2002-11-06 22:14:49 +00:00
|
|
|
LocaleKeyFactory::getSupportedIDs(UErrorCode& status) const {
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-22 18:20:28 +00:00
|
|
|
#ifdef SERVICE_DEBUG
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleKeyFactory::debug(UnicodeString& result) const
|
|
|
|
{
|
|
|
|
debugClass(result);
|
|
|
|
result.append(", name: ");
|
|
|
|
result.append(_name);
|
|
|
|
result.append(", coverage: ");
|
|
|
|
result.append(_coverage);
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
LocaleKeyFactory::debugClass(UnicodeString& result) const
|
|
|
|
{
|
|
|
|
return result.append("LocaleKeyFactory");
|
|
|
|
}
|
2002-11-22 18:20:28 +00:00
|
|
|
#endif
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
const char LocaleKeyFactory::fgClassID = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
|
|
|
|
const UnicodeString& locale,
|
|
|
|
int32_t kind,
|
2002-11-06 22:14:49 +00:00
|
|
|
int32_t coverage)
|
|
|
|
: LocaleKeyFactory(coverage)
|
|
|
|
, _obj(objToAdopt)
|
2002-11-22 18:20:28 +00:00
|
|
|
, _id(locale)
|
2002-11-06 22:14:49 +00:00
|
|
|
, _kind(kind)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-05-02 22:17:14 +00:00
|
|
|
SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
|
|
|
|
const Locale& locale,
|
|
|
|
int32_t kind,
|
|
|
|
int32_t coverage)
|
|
|
|
: LocaleKeyFactory(coverage)
|
|
|
|
, _obj(objToAdopt)
|
|
|
|
, _id()
|
|
|
|
, _kind(kind)
|
|
|
|
{
|
|
|
|
LocaleUtility::initNameFromLocale(locale, _id);
|
|
|
|
}
|
|
|
|
|
2002-12-06 00:22:10 +00:00
|
|
|
SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
|
|
|
|
{
|
|
|
|
delete _obj;
|
|
|
|
_obj = NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
|
|
|
SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
const LocaleKey& lkey = (const LocaleKey&)key;
|
|
|
|
if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
|
|
|
|
UnicodeString keyID;
|
|
|
|
lkey.currentID(keyID);
|
|
|
|
if (_id == keyID) {
|
|
|
|
return service->cloneInstance(_obj);
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 18:27:24 +00:00
|
|
|
UBool
|
|
|
|
SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const
|
|
|
|
{
|
2003-05-01 18:59:36 +00:00
|
|
|
return id == _id;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
void
|
2002-11-06 22:14:49 +00:00
|
|
|
SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (_coverage & 0x1) {
|
|
|
|
result.remove(_id);
|
|
|
|
} else {
|
|
|
|
result.put(_id, (void*)this, status);
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-22 18:20:28 +00:00
|
|
|
#ifdef SERVICE_DEBUG
|
|
|
|
UnicodeString&
|
2002-11-30 02:46:55 +00:00
|
|
|
SimpleLocaleKeyFactory::debug(UnicodeString& result) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
LocaleKeyFactory::debug(result);
|
|
|
|
result.append(", id: ");
|
|
|
|
result.append(_id);
|
|
|
|
result.append(", kind: ");
|
|
|
|
result.append(_kind);
|
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return result.append("SimpleLocaleKeyFactory");
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-22 18:20:28 +00:00
|
|
|
#endif
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
const char SimpleLocaleKeyFactory::fgClassID = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
ICUResourceBundleFactory::ICUResourceBundleFactory()
|
2002-11-06 22:14:49 +00:00
|
|
|
: LocaleKeyFactory(VISIBLE)
|
|
|
|
, _bundleName()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName)
|
2002-11-06 22:14:49 +00:00
|
|
|
: LocaleKeyFactory(VISIBLE)
|
|
|
|
, _bundleName(bundleName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const Hashtable*
|
2002-11-06 22:14:49 +00:00
|
|
|
ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return LocaleUtility::getAvailableLocaleNames(_bundleName);
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
2002-11-06 22:14:49 +00:00
|
|
|
ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t kind, const ICUService* service, UErrorCode& status) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return new ResourceBundle(_bundleName, loc, status);
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-22 18:20:28 +00:00
|
|
|
#ifdef SERVICE_DEBUG
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
ICUResourceBundleFactory::debug(UnicodeString& result) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
LocaleKeyFactory::debug(result);
|
|
|
|
result.append(", bundle: ");
|
|
|
|
return result.append(_bundleName);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UnicodeString&
|
2002-11-06 22:14:49 +00:00
|
|
|
ICUResourceBundleFactory::debugClass(UnicodeString& result) const
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return result.append("ICUResourceBundleFactory");
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-22 18:20:28 +00:00
|
|
|
#endif
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
const char ICUResourceBundleFactory::fgClassID = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
ICULocaleService::ICULocaleService()
|
2002-11-30 02:46:55 +00:00
|
|
|
: fallbackLocale(Locale::getDefault())
|
2002-11-07 08:02:41 +00:00
|
|
|
, llock(0)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-24 23:46:04 +00:00
|
|
|
ICULocaleService::ICULocaleService(const UnicodeString& dname)
|
|
|
|
: ICUService(dname)
|
2002-11-30 02:46:55 +00:00
|
|
|
, fallbackLocale(Locale::getDefault())
|
2002-11-07 08:02:41 +00:00
|
|
|
, llock(0)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
ICULocaleService::~ICULocaleService()
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-08 18:49:15 +00:00
|
|
|
umtx_destroy(&llock);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
|
|
|
ICULocaleService::get(const Locale& locale, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return get(locale, LocaleKey::KIND_ANY, NULL, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
|
|
|
ICULocaleService::get(const Locale& locale, int32_t kind, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return get(locale, kind, NULL, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject*
|
|
|
|
ICULocaleService::get(const Locale& locale, Locale* actualReturn, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return get(locale, LocaleKey::KIND_ANY, actualReturn, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
|
|
|
|
UObject*
|
|
|
|
ICULocaleService::get(const Locale& locale, int32_t kind, Locale* actualReturn, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
UObject* result = NULL;
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return result;
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2003-03-20 00:05:11 +00:00
|
|
|
UnicodeString locName(locale.getName(), "");
|
2002-11-30 02:46:55 +00:00
|
|
|
if (locName.isBogus()) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
ICUServiceKey* key = createKey(&locName, kind, status);
|
|
|
|
if (key) {
|
|
|
|
if (actualReturn == NULL) {
|
|
|
|
result = getKey(*key, status);
|
|
|
|
} else {
|
|
|
|
UnicodeString temp;
|
|
|
|
result = getKey(*key, &temp, status);
|
|
|
|
|
|
|
|
if (result != NULL) {
|
|
|
|
key->parseSuffix(temp);
|
|
|
|
LocaleUtility::initLocaleFromName(temp, *actualReturn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete key;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return result;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-02 22:17:14 +00:00
|
|
|
|
2002-11-22 23:58:49 +00:00
|
|
|
URegistryKey
|
2003-05-02 22:17:14 +00:00
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale,
|
|
|
|
UBool visible, UErrorCode& status)
|
2002-11-22 23:58:49 +00:00
|
|
|
{
|
2003-05-02 22:17:14 +00:00
|
|
|
Locale loc;
|
|
|
|
LocaleUtility::initLocaleFromName(locale, loc);
|
|
|
|
return registerInstance(objToAdopt, loc, LocaleKey::KIND_ANY,
|
|
|
|
visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE, status);
|
2002-11-22 23:58:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, UErrorCode& status)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, UErrorCode& status)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return registerInstance(objToAdopt, locale, kind, LocaleKeyFactory::VISIBLE, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status)
|
2002-11-22 18:20:28 +00:00
|
|
|
{
|
2003-05-02 22:17:14 +00:00
|
|
|
ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage);
|
2002-11-30 02:46:55 +00:00
|
|
|
if (factory != NULL) {
|
|
|
|
return registerFactory(factory, status);
|
|
|
|
}
|
|
|
|
delete objToAdopt;
|
|
|
|
return NULL;
|
2002-11-22 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
2002-11-22 18:20:28 +00:00
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UErrorCode& status)
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status);
|
2002-11-22 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
2002-11-22 18:20:28 +00:00
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status)
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY,
|
|
|
|
visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE,
|
|
|
|
status);
|
2002-11-22 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
URegistryKey
|
|
|
|
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, int32_t kind, int32_t coverage, UErrorCode& status)
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage);
|
|
|
|
if (factory != NULL) {
|
|
|
|
return registerFactory(factory, status);
|
|
|
|
}
|
|
|
|
delete objToAdopt;
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-22 18:20:28 +00:00
|
|
|
#endif
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-26 00:46:48 +00:00
|
|
|
class ServiceEnumeration : public StringEnumeration {
|
2002-11-06 22:14:49 +00:00
|
|
|
private:
|
2002-11-30 02:46:55 +00:00
|
|
|
const ICULocaleService* _service;
|
|
|
|
int32_t _timestamp;
|
|
|
|
UVector _ids;
|
|
|
|
int32_t _pos;
|
|
|
|
void* _bufp;
|
|
|
|
int32_t _buflen;
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
private:
|
2002-11-30 02:46:55 +00:00
|
|
|
ServiceEnumeration(const ICULocaleService* service, UErrorCode status)
|
|
|
|
: _service(service)
|
|
|
|
, _timestamp(service->getTimestamp())
|
|
|
|
, _ids(uhash_deleteUnicodeString, NULL, status)
|
|
|
|
, _pos(0)
|
|
|
|
, _bufp(NULL)
|
|
|
|
, _buflen(0)
|
|
|
|
{
|
|
|
|
_service->getVisibleIDs(_ids, status);
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
|
|
|
public:
|
2002-11-30 02:46:55 +00:00
|
|
|
static ServiceEnumeration* create(const ICULocaleService* service) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
ServiceEnumeration* result = new ServiceEnumeration(service, status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
delete result;
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
virtual ~ServiceEnumeration() {
|
|
|
|
uprv_free(_bufp);
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
virtual int32_t count(UErrorCode& status) const {
|
|
|
|
return upToDate(status) ? _ids.size() : 0;
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const char* next(int32_t* resultLength, UErrorCode& status) {
|
|
|
|
const UnicodeString* us = snext(status);
|
|
|
|
if (us) {
|
|
|
|
while (TRUE) {
|
|
|
|
int32_t newlen = us->extract((char*)_bufp, _buflen / sizeof(char), NULL, status);
|
|
|
|
if (status == U_STRING_NOT_TERMINATED_WARNING || status == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
resizeBuffer((newlen + 1) * sizeof(char));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
} else if (U_SUCCESS(status)) {
|
|
|
|
((char*)_bufp)[newlen] = 0;
|
|
|
|
if (resultLength) {
|
|
|
|
resultLength[0] = newlen;
|
|
|
|
}
|
|
|
|
return (const char*)_bufp;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const UChar* unext(int32_t* resultLength, UErrorCode& status) {
|
|
|
|
const UnicodeString* us = snext(status);
|
|
|
|
if (us) {
|
|
|
|
while (TRUE) {
|
|
|
|
int32_t newlen = us->extract((UChar*)_bufp, _buflen / sizeof(UChar), status);
|
|
|
|
if (status == U_STRING_NOT_TERMINATED_WARNING || status == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
resizeBuffer((newlen + 1) * sizeof(UChar));
|
|
|
|
} else if (U_SUCCESS(status)) {
|
|
|
|
((UChar*)_bufp)[newlen] = 0;
|
|
|
|
if (resultLength) {
|
|
|
|
resultLength[0] = newlen;
|
|
|
|
}
|
|
|
|
return (const UChar*)_bufp;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const UnicodeString* snext(UErrorCode& status) {
|
|
|
|
if (upToDate(status) && (_pos < _ids.size())) {
|
|
|
|
return (const UnicodeString*)_ids[_pos++];
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
void resizeBuffer(int32_t newlen) {
|
|
|
|
if (_bufp) {
|
|
|
|
_bufp = uprv_realloc(_bufp, newlen);
|
|
|
|
} else {
|
|
|
|
_bufp = uprv_malloc(newlen);
|
|
|
|
}
|
|
|
|
_buflen = newlen;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
UBool upToDate(UErrorCode& status) const {
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (_timestamp == _service->getTimestamp()) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
status = U_ENUM_OUT_OF_SYNC_ERROR;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
void reset(UErrorCode& status) {
|
2003-02-25 23:36:48 +00:00
|
|
|
if (status == U_ENUM_OUT_OF_SYNC_ERROR) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
_timestamp = _service->getTimestamp();
|
|
|
|
_pos = 0;
|
|
|
|
_service->getVisibleIDs(_ids, status);
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-24 23:46:04 +00:00
|
|
|
|
2002-11-26 00:46:48 +00:00
|
|
|
public:
|
2002-11-30 02:46:55 +00:00
|
|
|
virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); }
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
2002-11-26 00:46:48 +00:00
|
|
|
private:
|
2002-11-30 02:46:55 +00:00
|
|
|
static const char fgClassID;
|
2002-11-06 22:14:49 +00:00
|
|
|
};
|
|
|
|
|
2002-11-26 00:46:48 +00:00
|
|
|
const char ServiceEnumeration::fgClassID = '\0';
|
|
|
|
|
2002-11-06 22:14:49 +00:00
|
|
|
StringEnumeration*
|
2002-11-30 02:46:55 +00:00
|
|
|
ICULocaleService::getAvailableLocales(void) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return ServiceEnumeration::create(this);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
const UnicodeString&
|
|
|
|
ICULocaleService::validateFallbackLocale() const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2003-05-05 23:21:48 +00:00
|
|
|
const Locale& loc = Locale::getDefault();
|
|
|
|
ICULocaleService* ncThis = (ICULocaleService*)this;
|
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
Mutex mutex(&ncThis->llock);
|
|
|
|
if (loc != fallbackLocale) {
|
|
|
|
ncThis->fallbackLocale = loc;
|
|
|
|
LocaleUtility::initNameFromLocale(loc, ncThis->fallbackLocaleName);
|
|
|
|
ncThis->clearServiceCache();
|
|
|
|
}
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
2002-11-30 02:46:55 +00:00
|
|
|
return fallbackLocaleName;
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
ICUServiceKey*
|
|
|
|
ICULocaleService::createKey(const UnicodeString* id, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-30 02:46:55 +00:00
|
|
|
ICUServiceKey*
|
|
|
|
ICULocaleService::createKey(const UnicodeString* id, int32_t kind, UErrorCode& status) const
|
2002-11-06 22:14:49 +00:00
|
|
|
{
|
2002-11-30 02:46:55 +00:00
|
|
|
return LocaleKey::createWithCanonicalFallback(id, &validateFallbackLocale(), kind, status);
|
2002-11-06 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-12-06 00:22:10 +00:00
|
|
|
// defined in ucln_cmn.h
|
|
|
|
|
|
|
|
/**
|
2003-05-05 23:21:48 +00:00
|
|
|
* Release all static memory held by Locale Utility.
|
2002-12-06 00:22:10 +00:00
|
|
|
*/
|
|
|
|
U_CFUNC UBool service_cleanup(void) {
|
|
|
|
return LocaleUtility::cleanup();
|
|
|
|
}
|
|
|
|
|
2002-11-06 22:14:49 +00:00
|
|
|
/* !UCONFIG_NO_SERVICE */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|