2010-01-14 02:23:46 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2012-02-14 00:43:47 +00:00
|
|
|
* Copyright (C) 2010-2012, International Business Machines Corporation and
|
2011-06-03 05:23:57 +00:00
|
|
|
* others. All Rights Reserved.
|
2010-01-14 02:23:46 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/locdspnm.h"
|
|
|
|
#include "unicode/msgfmt.h"
|
2012-10-09 12:45:54 +00:00
|
|
|
#include "unicode/ures.h"
|
|
|
|
#include "unicode/brkiter.h"
|
2010-01-14 02:23:46 +00:00
|
|
|
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "ulocimp.h"
|
|
|
|
#include "ureslocs.h"
|
2012-10-09 12:45:54 +00:00
|
|
|
#include "uresimp.h"
|
2010-01-14 02:23:46 +00:00
|
|
|
|
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 {
|
2012-10-09 12:45:54 +00:00
|
|
|
const char* path;
|
|
|
|
Locale locale;
|
2010-01-14 02:23:46 +00:00
|
|
|
|
|
|
|
public:
|
2012-10-09 12:45:54 +00:00
|
|
|
ICUDataTable(const char* path, const Locale& locale);
|
|
|
|
~ICUDataTable();
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
const Locale& getLocale();
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
UnicodeString& get(const char* tableKey, const char* itemKey,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
UnicodeString& get(const char* tableKey, const char* subTableKey, const char* itemKey,
|
|
|
|
UnicodeString& result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
UnicodeString& getNoFallback(const char* tableKey, const char* itemKey,
|
|
|
|
UnicodeString &result) const;
|
|
|
|
UnicodeString& getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey,
|
|
|
|
UnicodeString &result) const;
|
2010-01-14 02:23:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline UnicodeString &
|
|
|
|
ICUDataTable::get(const char* tableKey, const char* itemKey, UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
return get(tableKey, NULL, itemKey, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline UnicodeString &
|
|
|
|
ICUDataTable::getNoFallback(const char* tableKey, const char* itemKey, UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
return getNoFallback(tableKey, NULL, itemKey, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
ICUDataTable::ICUDataTable(const char* path, const Locale& locale)
|
2012-10-09 12:45:54 +00:00
|
|
|
: path(NULL), locale(Locale::getRoot())
|
2010-01-14 02:23:46 +00:00
|
|
|
{
|
|
|
|
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);
|
2011-10-03 19:10:54 +00:00
|
|
|
if (U_SUCCESS(status) && len > 0) {
|
2010-01-14 02:23:46 +00:00
|
|
|
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
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-26 05:32:25 +00:00
|
|
|
LocaleDisplayNames::~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;
|
2012-10-08 16:50:51 +00:00
|
|
|
|
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 {
|
2012-10-09 12:45:54 +00:00
|
|
|
Locale locale;
|
|
|
|
UDialectHandling dialectHandling;
|
|
|
|
ICUDataTable langData;
|
|
|
|
ICUDataTable regionData;
|
|
|
|
UnicodeString sep;
|
|
|
|
MessageFormat *format;
|
|
|
|
MessageFormat *keyTypeFormat;
|
|
|
|
UDisplayContext capitalizationContext;
|
|
|
|
|
|
|
|
// Constants for capitalization context usage types.
|
|
|
|
enum CapContextUsage {
|
|
|
|
kCapContextUsageLanguage,
|
|
|
|
kCapContextUsageScript,
|
|
|
|
kCapContextUsageTerritory,
|
|
|
|
kCapContextUsageVariant,
|
|
|
|
kCapContextUsageKey,
|
|
|
|
kCapContextUsageType,
|
|
|
|
kCapContextUsageCount
|
|
|
|
};
|
|
|
|
// Capitalization transforms. For each usage type, the first array element indicates
|
|
|
|
// whether to titlecase for uiListOrMenu context, the second indicates whether to
|
|
|
|
// titlecase for stand-alone context.
|
|
|
|
UBool fCapitalization[kCapContextUsageCount][2];
|
2010-01-14 02:23:46 +00:00
|
|
|
|
|
|
|
public:
|
2012-10-09 12:45:54 +00:00
|
|
|
// constructor
|
|
|
|
LocaleDisplayNamesImpl(const Locale& locale, UDialectHandling dialectHandling);
|
|
|
|
LocaleDisplayNamesImpl(const Locale& locale, UDisplayContext *contexts, int32_t length);
|
|
|
|
virtual ~LocaleDisplayNamesImpl();
|
|
|
|
|
|
|
|
virtual const Locale& getLocale() const;
|
|
|
|
virtual UDialectHandling getDialectHandling() const;
|
|
|
|
virtual UDisplayContext getContext(UDisplayContextType type) const;
|
|
|
|
|
|
|
|
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:
|
2012-10-09 12:45:54 +00:00
|
|
|
UnicodeString& localeIdName(const char* localeId,
|
|
|
|
UnicodeString& result) const;
|
|
|
|
UnicodeString& appendWithSep(UnicodeString& buffer, const UnicodeString& src) const;
|
|
|
|
UnicodeString& adjustForUsageAndContext(CapContextUsage usage, UnicodeString& result) const;
|
|
|
|
void initialize(void);
|
2010-01-14 02:23:46 +00:00
|
|
|
};
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
|
|
|
|
UDialectHandling dialectHandling)
|
2012-10-09 12:45:54 +00:00
|
|
|
: dialectHandling(dialectHandling)
|
|
|
|
, langData(U_ICUDATA_LANG, locale)
|
|
|
|
, regionData(U_ICUDATA_REGION, locale)
|
|
|
|
, format(NULL)
|
|
|
|
, keyTypeFormat(NULL)
|
|
|
|
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
2012-10-08 16:50:51 +00:00
|
|
|
{
|
2012-10-09 12:45:54 +00:00
|
|
|
initialize();
|
2012-10-08 16:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
|
|
|
|
UDisplayContext *contexts, int32_t length)
|
2012-10-09 12:45:54 +00:00
|
|
|
: dialectHandling(ULDN_STANDARD_NAMES)
|
|
|
|
, langData(U_ICUDATA_LANG, locale)
|
|
|
|
, regionData(U_ICUDATA_REGION, locale)
|
|
|
|
, format(NULL)
|
|
|
|
, keyTypeFormat(NULL)
|
|
|
|
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
2010-01-14 02:23:46 +00:00
|
|
|
{
|
2012-10-09 12:45:54 +00:00
|
|
|
while (length-- > 0) {
|
|
|
|
UDisplayContext value = *contexts++;
|
|
|
|
UDisplayContextType selector = (UDisplayContextType)((uint32_t)value >> 8);
|
|
|
|
switch (selector) {
|
|
|
|
case UDISPCTX_TYPE_DIALECT_HANDLING:
|
|
|
|
dialectHandling = (UDialectHandling)value;
|
|
|
|
break;
|
|
|
|
case UDISPCTX_TYPE_CAPITALIZATION:
|
|
|
|
capitalizationContext = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initialize();
|
2012-10-08 16:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleDisplayNamesImpl::initialize(void) {
|
2012-10-09 12:45:54 +00:00
|
|
|
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
|
|
|
|
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
|
|
|
|
? regionData.getLocale()
|
|
|
|
: langData.getLocale();
|
|
|
|
|
|
|
|
langData.getNoFallback("localeDisplayPattern", "separator", sep);
|
|
|
|
if (sep.isBogus()) {
|
|
|
|
sep = UnicodeString(", ", -1, US_INV);
|
|
|
|
}
|
2010-01-18 20:15:34 +00:00
|
|
|
|
2012-10-09 12:45:54 +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);
|
2012-02-14 00:43:47 +00:00
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
UnicodeString ktPattern;
|
|
|
|
langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
|
|
|
|
if (ktPattern.isBogus()) {
|
|
|
|
ktPattern = UnicodeString("{0}={1}", -1, US_INV);
|
|
|
|
}
|
|
|
|
keyTypeFormat = new MessageFormat(ktPattern, status);
|
|
|
|
|
|
|
|
uprv_memset(fCapitalization, 0, sizeof(fCapitalization));
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
// The following is basically copied from DateFormatSymbols::initializeData
|
|
|
|
typedef struct {
|
|
|
|
const char * usageName;
|
|
|
|
LocaleDisplayNamesImpl::CapContextUsage usageEnum;
|
|
|
|
} ContextUsageNameToEnum;
|
|
|
|
const ContextUsageNameToEnum contextUsageTypeMap[] = {
|
|
|
|
// Entries must be sorted by usageTypeName; entry with NULL name terminates list.
|
|
|
|
{ "key", kCapContextUsageKey },
|
|
|
|
{ "languages", kCapContextUsageLanguage },
|
|
|
|
{ "script", kCapContextUsageScript },
|
|
|
|
{ "territory", kCapContextUsageTerritory },
|
|
|
|
{ "type", kCapContextUsageType },
|
|
|
|
{ "variant", kCapContextUsageVariant },
|
|
|
|
{ NULL, (CapContextUsage)0 },
|
|
|
|
};
|
|
|
|
int32_t len = 0;
|
|
|
|
UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, "contextTransforms", NULL, &status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
UResourceBundle *contextTransformUsage;
|
|
|
|
while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &status)) != NULL ) {
|
|
|
|
const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status);
|
|
|
|
if (U_SUCCESS(status) && intVector != NULL && len >= 2) {
|
|
|
|
const char* usageKey = ures_getKey(contextTransformUsage);
|
|
|
|
if (usageKey != NULL) {
|
|
|
|
const ContextUsageNameToEnum * typeMapPtr = contextUsageTypeMap;
|
|
|
|
int32_t compResult = 0;
|
|
|
|
// linear search; list is short and we cannot be sure that bsearch is available
|
|
|
|
while ( typeMapPtr->usageName != NULL && (compResult = uprv_strcmp(usageKey, typeMapPtr->usageName)) > 0 ) {
|
|
|
|
++typeMapPtr;
|
|
|
|
}
|
|
|
|
if (typeMapPtr->usageName != NULL && compResult == 0) {
|
|
|
|
fCapitalization[typeMapPtr->usageEnum][0] = intVector[0];
|
|
|
|
fCapitalization[typeMapPtr->usageEnum][1] = intVector[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
ures_close(contextTransformUsage);
|
|
|
|
}
|
|
|
|
ures_close(contextTransforms);
|
|
|
|
}
|
|
|
|
ures_close(localeBundle);
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() {
|
2012-10-09 12:45:54 +00:00
|
|
|
delete format;
|
|
|
|
delete keyTypeFormat;
|
|
|
|
}
|
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 {
|
2012-10-09 12:45:54 +00:00
|
|
|
return locale;
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UDialectHandling
|
2010-01-14 02:23:46 +00:00
|
|
|
LocaleDisplayNamesImpl::getDialectHandling() const {
|
2012-10-09 12:45:54 +00:00
|
|
|
return dialectHandling;
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 16:50:51 +00:00
|
|
|
UDisplayContext
|
|
|
|
LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
switch (type) {
|
|
|
|
case UDISPCTX_TYPE_DIALECT_HANDLING:
|
|
|
|
return (UDisplayContext)dialectHandling;
|
|
|
|
case UDISPCTX_TYPE_CAPITALIZATION:
|
|
|
|
return capitalizationContext;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (UDisplayContext)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::adjustForUsageAndContext(CapContextUsage usage,
|
|
|
|
UnicodeString& result) const {
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
// check to see whether we need to titlecase result
|
|
|
|
UBool titlecase = FALSE;
|
|
|
|
switch (capitalizationContext) {
|
|
|
|
case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE:
|
|
|
|
titlecase = TRUE;
|
|
|
|
break;
|
|
|
|
case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU:
|
|
|
|
titlecase = fCapitalization[usage][0];
|
|
|
|
break;
|
|
|
|
case UDISPCTX_CAPITALIZATION_FOR_STANDALONE:
|
|
|
|
titlecase = fCapitalization[usage][1];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// titlecase = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (titlecase) {
|
|
|
|
// TODO: Fix this titlecase hack when we figure out something better to do.
|
|
|
|
// We don't want to titlecase the whole text, only something like the first word,
|
|
|
|
// of the first segment long enough to have a complete cluster, whichever is
|
|
|
|
// shorter. We could have keep a word break iterator around, but I am not sure
|
|
|
|
// that will do the ight thing for the purposes here. For now we assume that in
|
|
|
|
// languages for which titlecasing makes a difference, we can stop at non-letter
|
|
|
|
// characters in 0x0000-0x00FF and only titlecase up to the first occurrence of
|
|
|
|
// any of those, or to a small number of chars, whichever comes first.
|
|
|
|
int32_t stopPos, stopPosLimit = 8, len = result.length();
|
|
|
|
if ( stopPosLimit > len ) {
|
|
|
|
stopPosLimit = len;
|
|
|
|
}
|
|
|
|
for ( stopPos = 0; stopPos < stopPosLimit; stopPos++ ) {
|
|
|
|
UChar32 ch = result.char32At(stopPos);
|
|
|
|
if ( (ch < 0x41) || (ch > 0x5A && ch < 0x61) || (ch > 0x7A && ch < 0xC0) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ch >= 0x10000) {
|
|
|
|
stopPos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( stopPos > 0 && stopPos < len ) {
|
|
|
|
UnicodeString firstWord(result, 0, stopPos);
|
|
|
|
firstWord.toTitle(NULL, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
|
|
|
|
result.replaceBetween(0, stopPos, firstWord);
|
|
|
|
} else {
|
|
|
|
// no stopPos, titlecase the whole text
|
|
|
|
result.toTitle(NULL, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
2012-10-08 16:50:51 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2012-02-14 00:43:47 +00:00
|
|
|
keyDisplayName(key, temp);
|
|
|
|
keyValueDisplayName(key, value, temp2);
|
|
|
|
if (temp2 != UnicodeString(value, -1, US_INV)) {
|
|
|
|
appendWithSep(resultRemainder, temp2);
|
|
|
|
} else if (temp != UnicodeString(key, -1, US_INV)) {
|
|
|
|
UnicodeString temp3;
|
|
|
|
Formattable data[] = {
|
|
|
|
temp,
|
|
|
|
temp2
|
|
|
|
};
|
|
|
|
FieldPosition fpos;
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
keyTypeFormat->format(data, 2, temp3, fpos, status);
|
|
|
|
appendWithSep(resultRemainder, temp3);
|
|
|
|
} else {
|
|
|
|
appendWithSep(resultRemainder, temp)
|
2011-06-03 05:23:57 +00:00
|
|
|
.append((UChar)0x3d /* = */)
|
2012-02-14 00:43:47 +00:00
|
|
|
.append(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);
|
2012-10-09 12:45:54 +00:00
|
|
|
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
result = resultName;
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2012-10-09 12:45:54 +00:00
|
|
|
if (!buffer.isEmpty()) {
|
|
|
|
buffer.append(sep);
|
|
|
|
}
|
|
|
|
buffer.append(src);
|
|
|
|
return buffer;
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::localeDisplayName(const char* localeId,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
return localeDisplayName(Locale(localeId), result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-09 12:45:54 +00:00
|
|
|
// private
|
2010-01-21 02:45:53 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::localeIdName(const char* localeId,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
return langData.getNoFallback("Languages", localeId, result);
|
2010-01-21 02:45:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::languageDisplayName(const char* lang,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) {
|
|
|
|
return result = UnicodeString(lang, -1, US_INV);
|
|
|
|
}
|
|
|
|
langData.get("Languages", lang, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::scriptDisplayName(const char* script,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
langData.get("Scripts", script, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageScript, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
const char* name = uscript_getName(scriptCode);
|
|
|
|
langData.get("Scripts", name, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageScript, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::regionDisplayName(const char* region,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
regionData.get("Countries", region, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageTerritory, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::variantDisplayName(const char* variant,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
langData.get("Variants", variant, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageVariant, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::keyDisplayName(const char* key,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
langData.get("Keys", key, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageKey, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 20:15:34 +00:00
|
|
|
UnicodeString&
|
|
|
|
LocaleDisplayNamesImpl::keyValueDisplayName(const char* key,
|
|
|
|
const char* value,
|
|
|
|
UnicodeString& result) const {
|
2012-10-09 12:45:54 +00:00
|
|
|
langData.get("Types", key, value, result);
|
|
|
|
return adjustForUsageAndContext(kCapContextUsageType, result);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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) {
|
2012-10-09 12:45:54 +00:00
|
|
|
return new LocaleDisplayNamesImpl(locale, dialectHandling);
|
2010-01-14 02:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 16:50:51 +00:00
|
|
|
LocaleDisplayNames*
|
|
|
|
LocaleDisplayNames::createInstance(const Locale& locale,
|
|
|
|
UDisplayContext *contexts, int32_t length) {
|
2012-10-09 12:45:54 +00:00
|
|
|
if (contexts == NULL) {
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
return new LocaleDisplayNamesImpl(locale, contexts, length);
|
2012-10-08 16:50:51 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 16:50:51 +00:00
|
|
|
U_CAPI ULocaleDisplayNames * U_EXPORT2
|
|
|
|
uldn_openForContext(const char * locale,
|
|
|
|
UDisplayContext *contexts, int32_t length,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (locale == NULL) {
|
|
|
|
locale = uloc_getDefault();
|
|
|
|
}
|
|
|
|
return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), contexts, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2010-01-15 02:35:02 +00:00
|
|
|
uldn_close(ULocaleDisplayNames *ldn) {
|
|
|
|
delete (LocaleDisplayNames *)ldn;
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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;
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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;
|
|
|
|
}
|
|
|
|
|
2012-10-08 16:50:51 +00:00
|
|
|
U_CAPI UDisplayContext U_EXPORT2
|
|
|
|
uldn_getContext(const ULocaleDisplayNames *ldn,
|
|
|
|
UDisplayContextType type,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return (UDisplayContext)0;
|
|
|
|
}
|
|
|
|
return ((const LocaleDisplayNames *)ldn)->getContext(type);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:16:32 +00:00
|
|
|
U_CAPI 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
|