2010-01-14 02:23:46 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
* Copyright (C) 2010, International Business Machines Corporation and *
|
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/locdspnm.h"
|
|
|
|
|
|
|
|
#include "unicode/msgfmt.h"
|
|
|
|
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "ulocimp.h"
|
|
|
|
#include "ureslocs.h"
|
|
|
|
|
2010-01-14 07:03:36 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-01-14 02:23:46 +00:00
|
|
|
/**
|
|
|
|
* Concatenate a number of null-terminated strings to buffer, leaving a
|
|
|
|
* null-terminated string. The last argument should be the null pointer.
|
|
|
|
* Return the length of the string in the buffer, not counting the trailing
|
|
|
|
* null. Return -1 if there is an error (buffer is null, or buflen < 1).
|
|
|
|
*/
|
|
|
|
static int32_t ncat(char *buffer, uint32_t buflen, ...) {
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
char *p = buffer;
|
|
|
|
const char* e = buffer + buflen - 1;
|
|
|
|
|
|
|
|
if (buffer == NULL || buflen < 1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, buflen);
|
2010-01-17 01:46:09 +00:00
|
|
|
while ((str = va_arg(args, char *))) {
|
2010-01-14 02:23:46 +00:00
|
|
|
char c;
|
|
|
|
while (p != e && (c = *str++)) {
|
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return p - buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Access resource data for locale components.
|
|
|
|
// Wrap code in uloc.c for now.
|
|
|
|
class ICUDataTable {
|
|
|
|
const char* path;
|
|
|
|
Locale locale;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ICUDataTable(const char* path, const Locale& locale);
|
|
|
|
~ICUDataTable();
|
|
|
|
|
|
|
|
const Locale& getLocale();
|
|
|
|
|
|
|
|
UnicodeString& get(const char* tableKey, const char* itemKey,
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
UnicodeString& get(const char* tableKey, const char* subTableKey, const char* itemKey,
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString& getNoFallback(const char* tableKey, const char* itemKey,
|
|
|
|
UnicodeString &result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
UnicodeString& getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey,
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString &result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline UnicodeString &
|
|
|
|
ICUDataTable::get(const char* tableKey, const char* itemKey, UnicodeString& result) const {
|
|
|
|
return get(tableKey, NULL, itemKey, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline UnicodeString &
|
|
|
|
ICUDataTable::getNoFallback(const char* tableKey, const char* itemKey, UnicodeString& result) const {
|
|
|
|
return getNoFallback(tableKey, NULL, itemKey, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
ICUDataTable::ICUDataTable(const char* path, const Locale& locale)
|
2010-01-14 02:23:46 +00:00
|
|
|
: path(NULL), locale(Locale::getRoot())
|
|
|
|
{
|
|
|
|
if (path) {
|
|
|
|
int32_t len = uprv_strlen(path);
|
|
|
|
this->path = (const char*) uprv_malloc(len + 1);
|
|
|
|
if (this->path) {
|
|
|
|
uprv_strcpy((char *)this->path, path);
|
|
|
|
this->locale = locale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ICUDataTable::~ICUDataTable() {
|
|
|
|
if (path) {
|
|
|
|
uprv_free((void*) path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
const Locale&
|
2010-01-14 02:23:46 +00:00
|
|
|
ICUDataTable::getLocale() {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString &
|
|
|
|
ICUDataTable::get(const char* tableKey, const char* subTableKey, const char* itemKey,
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString &result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t len = 0;
|
|
|
|
|
|
|
|
const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(),
|
2010-01-18 20:15:34 +00:00
|
|
|
tableKey, subTableKey, itemKey,
|
|
|
|
&len, &status);
|
2010-01-14 02:23:46 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return result.setTo(s, len);
|
|
|
|
}
|
|
|
|
return result.setTo(UnicodeString(itemKey, -1, US_INV));
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString &
|
|
|
|
ICUDataTable::getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey,
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t len = 0;
|
|
|
|
|
|
|
|
const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(),
|
2010-01-18 20:15:34 +00:00
|
|
|
tableKey, subTableKey, itemKey,
|
|
|
|
&len, &status);
|
2010-01-14 02:23:46 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return result.setTo(s, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.setToBogus();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-02-24 22:29:08 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(LocaleDisplayNames)
|
2010-01-14 02:23:46 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-02-24 22:29:08 +00:00
|
|
|
#if 0 // currently unused
|
|
|
|
|
2010-01-14 02:23:46 +00:00
|
|
|
class DefaultLocaleDisplayNames : public LocaleDisplayNames {
|
|
|
|
UDialectHandling dialectHandling;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
DefaultLocaleDisplayNames(UDialectHandling dialectHandling);
|
|
|
|
|
|
|
|
virtual ~DefaultLocaleDisplayNames();
|
|
|
|
|
|
|
|
virtual const Locale& getLocale() const;
|
|
|
|
virtual UDialectHandling getDialectHandling() const;
|
2010-01-18 20:15:34 +00:00
|
|
|
virtual UnicodeString& localeDisplayName(const Locale& locale,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& localeDisplayName(const char* localeId,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& languageDisplayName(const char* lang,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& scriptDisplayName(const char* script,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& regionDisplayName(const char* region,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& variantDisplayName(const char* variant,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& keyDisplayName(const char* key,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& keyValueDisplayName(const char* key,
|
|
|
|
const char* value,
|
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DefaultLocaleDisplayNames::DefaultLocaleDisplayNames(UDialectHandling dialectHandling)
|
|
|
|
: dialectHandling(dialectHandling) {
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultLocaleDisplayNames::~DefaultLocaleDisplayNames() {
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
const Locale&
|
2010-01-14 02:23:46 +00:00
|
|
|
DefaultLocaleDisplayNames::getLocale() const {
|
|
|
|
return Locale::getRoot();
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UDialectHandling
|
2010-01-14 02:23:46 +00:00
|
|
|
DefaultLocaleDisplayNames::getDialectHandling() const {
|
|
|
|
return dialectHandling;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::localeDisplayName(const Locale& locale,
|
|
|
|
UnicodeString& result) const {
|
2010-01-15 02:35:02 +00:00
|
|
|
return result = UnicodeString(locale.getName(), -1, US_INV);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::localeDisplayName(const char* localeId,
|
|
|
|
UnicodeString& result) const {
|
2010-01-15 02:35:02 +00:00
|
|
|
return result = UnicodeString(localeId, -1, US_INV);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::languageDisplayName(const char* lang,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(lang, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::scriptDisplayName(const char* script,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(script, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::scriptDisplayName(UScriptCode scriptCode,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
const char* name = uscript_getName(scriptCode);
|
|
|
|
if (name) {
|
|
|
|
return result = UnicodeString(name, -1, US_INV);
|
|
|
|
}
|
|
|
|
return result.remove();
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::regionDisplayName(const char* region,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(region, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::variantDisplayName(const char* variant,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(variant, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::keyDisplayName(const char* key,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(key, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
DefaultLocaleDisplayNames::keyValueDisplayName(const char* /* key */,
|
|
|
|
const char* value,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return result = UnicodeString(value, -1, US_INV);
|
|
|
|
}
|
|
|
|
|
2010-02-24 22:29:08 +00:00
|
|
|
#endif // currently unused class DefaultLocaleDisplayNames
|
|
|
|
|
2010-01-14 02:23:46 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class LocaleDisplayNamesImpl : public LocaleDisplayNames {
|
|
|
|
Locale locale;
|
|
|
|
UDialectHandling dialectHandling;
|
|
|
|
ICUDataTable langData;
|
|
|
|
ICUDataTable regionData;
|
|
|
|
UnicodeString sep;
|
|
|
|
MessageFormat *format;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
LocaleDisplayNamesImpl(const Locale& locale, UDialectHandling dialectHandling);
|
|
|
|
virtual ~LocaleDisplayNamesImpl();
|
|
|
|
|
|
|
|
virtual const Locale& getLocale() const;
|
|
|
|
virtual UDialectHandling getDialectHandling() const;
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
virtual UnicodeString& localeDisplayName(const Locale& locale,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& localeDisplayName(const char* localeId,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& languageDisplayName(const char* lang,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& scriptDisplayName(const char* script,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& regionDisplayName(const char* region,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& variantDisplayName(const char* variant,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& keyDisplayName(const char* key,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
virtual UnicodeString& keyValueDisplayName(const char* key,
|
|
|
|
const char* value,
|
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
private:
|
2010-01-21 02:45:53 +00:00
|
|
|
UnicodeString& localeIdName(const char* localeId,
|
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
UnicodeString& appendWithSep(UnicodeString& buffer, const UnicodeString& src) const;
|
|
|
|
};
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
|
|
|
|
UDialectHandling dialectHandling)
|
2010-01-14 02:23:46 +00:00
|
|
|
: dialectHandling(dialectHandling)
|
|
|
|
, langData(U_ICUDATA_LANG, locale)
|
|
|
|
, regionData(U_ICUDATA_REGION, locale)
|
2010-03-11 19:54:35 +00:00
|
|
|
, format(NULL)
|
2010-01-14 02:23:46 +00:00
|
|
|
{
|
|
|
|
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
|
|
|
|
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
|
2010-01-18 20:15:34 +00:00
|
|
|
? regionData.getLocale()
|
2010-01-14 02:23:46 +00:00
|
|
|
: langData.getLocale();
|
|
|
|
|
|
|
|
langData.getNoFallback("localeDisplayPattern", "separator", sep);
|
|
|
|
if (sep.isBogus()) {
|
|
|
|
sep = UnicodeString(", ", -1, US_INV);
|
|
|
|
}
|
2010-01-18 20:15:34 +00:00
|
|
|
|
2010-01-14 02:23:46 +00:00
|
|
|
UnicodeString pattern;
|
|
|
|
langData.getNoFallback("localeDisplayPattern", "pattern", pattern);
|
|
|
|
if (pattern.isBogus()) {
|
|
|
|
pattern = UnicodeString("{0} ({1})", -1, US_INV);
|
|
|
|
}
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
format = new MessageFormat(pattern, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() {
|
2010-03-11 19:54:35 +00:00
|
|
|
delete format;
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
const Locale&
|
2010-01-14 02:23:46 +00:00
|
|
|
LocaleDisplayNamesImpl::getLocale() const {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UDialectHandling
|
2010-01-14 02:23:46 +00:00
|
|
|
LocaleDisplayNamesImpl::getDialectHandling() const {
|
|
|
|
return dialectHandling;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
UnicodeString resultName;
|
|
|
|
|
|
|
|
const char* lang = locale.getLanguage();
|
2010-01-21 02:45:53 +00:00
|
|
|
if (uprv_strlen(lang) == 0) {
|
|
|
|
lang = "root";
|
|
|
|
}
|
2010-01-14 02:23:46 +00:00
|
|
|
const char* script = locale.getScript();
|
|
|
|
const char* country = locale.getCountry();
|
|
|
|
const char* variant = locale.getVariant();
|
|
|
|
|
|
|
|
UBool hasScript = uprv_strlen(script) > 0;
|
|
|
|
UBool hasCountry = uprv_strlen(country) > 0;
|
|
|
|
UBool hasVariant = uprv_strlen(variant) > 0;
|
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
if (dialectHandling == ULDN_DIALECT_NAMES) {
|
|
|
|
char buffer[ULOC_FULLNAME_CAPACITY];
|
|
|
|
do { // loop construct is so we can break early out of search
|
|
|
|
if (hasScript && hasCountry) {
|
|
|
|
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
|
|
|
|
localeIdName(buffer, resultName);
|
|
|
|
if (!resultName.isBogus()) {
|
|
|
|
hasScript = FALSE;
|
|
|
|
hasCountry = FALSE;
|
|
|
|
break;
|
2010-01-18 20:15:34 +00:00
|
|
|
}
|
2010-01-21 02:45:53 +00:00
|
|
|
}
|
|
|
|
if (hasScript) {
|
|
|
|
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
|
|
|
|
localeIdName(buffer, resultName);
|
|
|
|
if (!resultName.isBogus()) {
|
|
|
|
hasScript = FALSE;
|
|
|
|
break;
|
2010-01-18 20:15:34 +00:00
|
|
|
}
|
2010-01-21 02:45:53 +00:00
|
|
|
}
|
|
|
|
if (hasCountry) {
|
|
|
|
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
|
|
|
|
localeIdName(buffer, resultName);
|
|
|
|
if (!resultName.isBogus()) {
|
|
|
|
hasCountry = FALSE;
|
|
|
|
break;
|
2010-01-18 20:15:34 +00:00
|
|
|
}
|
2010-01-21 02:45:53 +00:00
|
|
|
}
|
|
|
|
} while (FALSE);
|
|
|
|
}
|
|
|
|
if (resultName.isBogus() || resultName.isEmpty()) {
|
|
|
|
localeIdName(lang, resultName);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
UnicodeString resultRemainder;
|
|
|
|
UnicodeString temp;
|
|
|
|
StringEnumeration *e = NULL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
if (hasScript) {
|
|
|
|
resultRemainder.append(scriptDisplayName(script, temp));
|
|
|
|
}
|
|
|
|
if (hasCountry) {
|
|
|
|
appendWithSep(resultRemainder, regionDisplayName(country, temp));
|
|
|
|
}
|
|
|
|
if (hasVariant) {
|
|
|
|
appendWithSep(resultRemainder, variantDisplayName(variant, temp));
|
|
|
|
}
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
e = locale.createKeywords(status);
|
|
|
|
if (e && U_SUCCESS(status)) {
|
|
|
|
UnicodeString temp2;
|
|
|
|
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
|
|
|
|
const char* key;
|
|
|
|
while ((key = e->next((int32_t *)0, status)) != NULL) {
|
|
|
|
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
|
|
|
|
appendWithSep(resultRemainder, keyDisplayName(key, temp))
|
2010-01-18 20:15:34 +00:00
|
|
|
.append("=")
|
|
|
|
.append(keyValueDisplayName(key, value, temp2));
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
2010-01-21 02:45:53 +00:00
|
|
|
delete e;
|
|
|
|
}
|
2010-01-18 20:15:34 +00:00
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
if (!resultRemainder.isEmpty()) {
|
|
|
|
Formattable data[] = {
|
|
|
|
resultName,
|
|
|
|
resultRemainder
|
|
|
|
};
|
|
|
|
FieldPosition fpos;
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
format->format(data, 2, result, fpos, status);
|
|
|
|
return result;
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result = resultName;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
2010-01-14 02:23:46 +00:00
|
|
|
LocaleDisplayNamesImpl::appendWithSep(UnicodeString& buffer, const UnicodeString& src) const {
|
|
|
|
if (!buffer.isEmpty()) {
|
|
|
|
buffer.append(sep);
|
|
|
|
}
|
|
|
|
buffer.append(src);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::localeDisplayName(const char* localeId,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return localeDisplayName(Locale(localeId), result);
|
|
|
|
}
|
|
|
|
|
2010-01-21 02:45:53 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::localeIdName(const char* localeId,
|
|
|
|
UnicodeString& result) const {
|
|
|
|
return langData.getNoFallback("Languages", localeId, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::languageDisplayName(const char* lang,
|
|
|
|
UnicodeString& result) const {
|
2010-01-21 02:45:53 +00:00
|
|
|
if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) {
|
|
|
|
return result = UnicodeString(lang, -1, US_INV);
|
|
|
|
}
|
2010-01-14 02:23:46 +00:00
|
|
|
return langData.get("Languages", lang, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::scriptDisplayName(const char* script,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return langData.get("Scripts", script, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
const char* name = uscript_getName(scriptCode);
|
|
|
|
return langData.get("Scripts", name, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::regionDisplayName(const char* region,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return regionData.get("Countries", region, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::variantDisplayName(const char* variant,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return langData.get("Variants", variant, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::keyDisplayName(const char* key,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return langData.get("Keys", key, result);
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::keyValueDisplayName(const char* key,
|
|
|
|
const char* value,
|
|
|
|
UnicodeString& result) const {
|
2010-01-14 02:23:46 +00:00
|
|
|
return langData.get("Types", key, value, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
LocaleDisplayNames*
|
2010-01-14 02:23:46 +00:00
|
|
|
LocaleDisplayNames::createInstance(const Locale& locale,
|
2010-01-18 20:15:34 +00:00
|
|
|
UDialectHandling dialectHandling) {
|
2010-01-14 02:23:46 +00:00
|
|
|
return new LocaleDisplayNamesImpl(locale, dialectHandling);
|
|
|
|
}
|
|
|
|
|
2010-01-16 19:01:03 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2010-01-15 02:35:02 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-01-16 19:01:03 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2010-01-17 01:46:09 +00:00
|
|
|
U_DRAFT ULocaleDisplayNames * U_EXPORT2
|
2010-01-15 02:35:02 +00:00
|
|
|
uldn_open(const char * locale,
|
2010-01-18 20:15:34 +00:00
|
|
|
UDialectHandling dialectHandling,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (locale == NULL) {
|
2010-02-24 22:29:08 +00:00
|
|
|
locale = uloc_getDefault();
|
2010-01-15 02:35:02 +00:00
|
|
|
}
|
|
|
|
return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), dialectHandling);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT void U_EXPORT2
|
|
|
|
uldn_close(ULocaleDisplayNames *ldn) {
|
|
|
|
delete (LocaleDisplayNames *)ldn;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT const char * U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_getLocale(const ULocaleDisplayNames *ldn) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (ldn) {
|
2010-01-18 20:15:34 +00:00
|
|
|
return ((const LocaleDisplayNames *)ldn)->getLocale().getName();
|
2010-01-15 02:35:02 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT UDialectHandling U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_getDialectHandling(const ULocaleDisplayNames *ldn) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (ldn) {
|
2010-01-18 20:15:34 +00:00
|
|
|
return ((const LocaleDisplayNames *)ldn)->getDialectHandling();
|
2010-01-15 02:35:02 +00:00
|
|
|
}
|
|
|
|
return ULDN_STANDARD_NAMES;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_localeDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *locale,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || locale == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->localeDisplayName(locale, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_languageDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *lang,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || lang == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->languageDisplayName(lang, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_scriptDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *script,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || script == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->scriptDisplayName(script, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
UScriptCode scriptCode,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
return uldn_scriptDisplayName(ldn, uscript_getName(scriptCode), result, maxResultSize, pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_regionDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *region,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || region == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->regionDisplayName(region, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_variantDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *variant,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || variant == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->variantDisplayName(variant, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_keyDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *key,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ldn == NULL || key == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->keyDisplayName(key, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_DRAFT int32_t U_EXPORT2
|
2010-01-18 20:15:34 +00:00
|
|
|
uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn,
|
|
|
|
const char *key,
|
|
|
|
const char *value,
|
|
|
|
UChar *result,
|
|
|
|
int32_t maxResultSize,
|
|
|
|
UErrorCode *pErrorCode) {
|
2010-01-15 02:35:02 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-18 20:15:34 +00:00
|
|
|
if (ldn == NULL || key == NULL || value == NULL || (result == NULL && maxResultSize > 0)
|
2010-01-15 02:35:02 +00:00
|
|
|
|| maxResultSize < 0) {
|
|
|
|
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString temp(result, 0, maxResultSize);
|
2010-01-18 20:15:34 +00:00
|
|
|
((const LocaleDisplayNames *)ldn)->keyValueDisplayName(key, value, temp);
|
2010-01-15 02:35:02 +00:00
|
|
|
return temp.extract(result, maxResultSize, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:23:46 +00:00
|
|
|
#endif
|