150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/* 250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho******************************************************************************* 3fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* Copyright (C) 2010-2014, International Business Machines Corporation and 4b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho* others. All Rights Reserved. 550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho******************************************************************************* 650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho*/ 750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/utypes.h" 950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FORMATTING 1150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/locdspnm.h" 1350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/msgfmt.h" 1454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "unicode/ures.h" 15fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "unicode/udisplaycontext.h" 1654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "unicode/brkiter.h" 1750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "cmemory.h" 1950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "cstring.h" 20f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius#include "mutex.h" 2150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "ulocimp.h" 22f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius#include "umutex.h" 2350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "ureslocs.h" 2454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "uresimp.h" 2550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include <stdarg.h> 2750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** 2950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Concatenate a number of null-terminated strings to buffer, leaving a 3050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * null-terminated string. The last argument should be the null pointer. 3150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Return the length of the string in the buffer, not counting the trailing 3250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * null. Return -1 if there is an error (buffer is null, or buflen < 1). 3350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 3450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic int32_t ncat(char *buffer, uint32_t buflen, ...) { 3550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho va_list args; 3650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char *str; 3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char *p = buffer; 3850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* e = buffer + buflen - 1; 3950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 4050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (buffer == NULL || buflen < 1) { 4150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return -1; 4250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 4350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 4450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho va_start(args, buflen); 4550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho while ((str = va_arg(args, char *))) { 4650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char c; 4750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho while (p != e && (c = *str++)) { 4850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *p++ = c; 4950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 5050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 5150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *p = 0; 5250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho va_end(args); 5350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 5450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return p - buffer; 5550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 5650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 5750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_BEGIN 5850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 5950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 6050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 6150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho// Access resource data for locale components. 6250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho// Wrap code in uloc.c for now. 6350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoclass ICUDataTable { 6454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius const char* path; 6554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius Locale locale; 6650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 6750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehopublic: 6854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ICUDataTable(const char* path, const Locale& locale); 6954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ~ICUDataTable(); 7050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 7154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius const Locale& getLocale(); 7250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 7354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& get(const char* tableKey, const char* itemKey, 7454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 7554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& get(const char* tableKey, const char* subTableKey, const char* itemKey, 7654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 7750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 7854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& getNoFallback(const char* tableKey, const char* itemKey, 7954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString &result) const; 8054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey, 8154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString &result) const; 8250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}; 8350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 8450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoinline UnicodeString & 8550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::get(const char* tableKey, const char* itemKey, UnicodeString& result) const { 8654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return get(tableKey, NULL, itemKey, result); 8750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 8850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 8950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoinline UnicodeString & 9050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::getNoFallback(const char* tableKey, const char* itemKey, UnicodeString& result) const { 9154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return getNoFallback(tableKey, NULL, itemKey, result); 9250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 9350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 9450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::ICUDataTable(const char* path, const Locale& locale) 9554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius : path(NULL), locale(Locale::getRoot()) 9650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho{ 9750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (path) { 9850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t len = uprv_strlen(path); 9950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho this->path = (const char*) uprv_malloc(len + 1); 10050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (this->path) { 10150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uprv_strcpy((char *)this->path, path); 10250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho this->locale = locale; 10350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 10450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 10550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 10650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 10750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::~ICUDataTable() { 10850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (path) { 10950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho uprv_free((void*) path); 11050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho path = NULL; 11150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 11250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 11350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 11450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoconst Locale& 11550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::getLocale() { 11650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return locale; 11750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 11850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 11950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString & 12050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::get(const char* tableKey, const char* subTableKey, const char* itemKey, 12150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString &result) const { 12250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode status = U_ZERO_ERROR; 12350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t len = 0; 12450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 12550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(), 12650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho tableKey, subTableKey, itemKey, 12750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho &len, &status); 128b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_SUCCESS(status) && len > 0) { 12950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result.setTo(s, len); 13050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 13150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result.setTo(UnicodeString(itemKey, -1, US_INV)); 13250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 13350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 13450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString & 13550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoICUDataTable::getNoFallback(const char* tableKey, const char* subTableKey, const char* itemKey, 13650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 13750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode status = U_ZERO_ERROR; 13850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t len = 0; 13950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 14050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(), 14150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho tableKey, subTableKey, itemKey, 14250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho &len, &status); 14350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_SUCCESS(status)) { 14450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result.setTo(s, len); 14550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 14650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 14750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho result.setToBogus(); 14850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result; 14950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 15050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 15150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 15250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 153103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusLocaleDisplayNames::~LocaleDisplayNames() {} 154103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 15550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 15650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 15750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if 0 // currently unused 15850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 15950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoclass DefaultLocaleDisplayNames : public LocaleDisplayNames { 16050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UDialectHandling dialectHandling; 16150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 16250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehopublic: 16350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho // constructor 16450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho DefaultLocaleDisplayNames(UDialectHandling dialectHandling); 16550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 16650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual ~DefaultLocaleDisplayNames(); 16750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 16850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual const Locale& getLocale() const; 16950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UDialectHandling getDialectHandling() const; 17054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 17150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& localeDisplayName(const Locale& locale, 17250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 17350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& localeDisplayName(const char* localeId, 17450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 17550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& languageDisplayName(const char* lang, 17650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 17750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& scriptDisplayName(const char* script, 17850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 17950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode, 18050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 18150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& regionDisplayName(const char* region, 18250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 18350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& variantDisplayName(const char* variant, 18450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 18550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& keyDisplayName(const char* key, 18650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 18750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual UnicodeString& keyValueDisplayName(const char* key, 18850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* value, 18950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const; 19050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}; 19150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 19250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::DefaultLocaleDisplayNames(UDialectHandling dialectHandling) 19350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho : dialectHandling(dialectHandling) { 19450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 19550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 19650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::~DefaultLocaleDisplayNames() { 19750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 19850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 19950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoconst Locale& 20050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::getLocale() const { 20150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return Locale::getRoot(); 20250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 20350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 20450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUDialectHandling 20550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::getDialectHandling() const { 20650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return dialectHandling; 20750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 20850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 20950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 21050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::localeDisplayName(const Locale& locale, 21150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 21250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(locale.getName(), -1, US_INV); 21350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 21450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 21550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 21650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::localeDisplayName(const char* localeId, 21750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 21850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(localeId, -1, US_INV); 21950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 22050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 22150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 22250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::languageDisplayName(const char* lang, 22350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 22450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(lang, -1, US_INV); 22550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 22650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 22750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 22850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::scriptDisplayName(const char* script, 22950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 23050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(script, -1, US_INV); 23150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 23250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 23350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 23450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::scriptDisplayName(UScriptCode scriptCode, 23550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 23650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* name = uscript_getName(scriptCode); 23750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (name) { 23850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(name, -1, US_INV); 23950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 24050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result.remove(); 24150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 24250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 24350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 24450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::regionDisplayName(const char* region, 24550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 24650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(region, -1, US_INV); 24750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 24850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 24950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 25050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::variantDisplayName(const char* variant, 25150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 25250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(variant, -1, US_INV); 25350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 25450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 25550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 25650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::keyDisplayName(const char* key, 25750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 25850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(key, -1, US_INV); 25950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 26050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 26150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 26250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoDefaultLocaleDisplayNames::keyValueDisplayName(const char* /* key */, 26350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* value, 26450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 26550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return result = UnicodeString(value, -1, US_INV); 26650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 26750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 26850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif // currently unused class DefaultLocaleDisplayNames 26950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 27050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 27150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 27250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoclass LocaleDisplayNamesImpl : public LocaleDisplayNames { 27354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius Locale locale; 27454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDialectHandling dialectHandling; 27554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ICUDataTable langData; 27654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ICUDataTable regionData; 27759d709d503bab6e2b61931737e662dd293b40578ccornelius MessageFormat *separatorFormat; 27854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius MessageFormat *format; 27954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius MessageFormat *keyTypeFormat; 28054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContext capitalizationContext; 281fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius BreakIterator* capitalizationBrkIter; 282f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius static UMutex capitalizationBrkIterLock; 28359d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString formatOpenParen; 28459d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString formatReplaceOpenParen; 28559d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString formatCloseParen; 28659d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString formatReplaceCloseParen; 287f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius UDisplayContext nameLength; 28854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 28954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // Constants for capitalization context usage types. 29054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius enum CapContextUsage { 29154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageLanguage, 29254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageScript, 29354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageTerritory, 29454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageVariant, 29554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageKey, 296fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius kCapContextUsageKeyValue, 29754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius kCapContextUsageCount 29854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius }; 299fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // Capitalization transforms. For each usage type, indicates whether to titlecase for 300fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // the context specified in capitalizationContext (which we know at construction time) 301fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool fCapitalization[kCapContextUsageCount]; 30250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 30350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehopublic: 30454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // constructor 30554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius LocaleDisplayNamesImpl(const Locale& locale, UDialectHandling dialectHandling); 30654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius LocaleDisplayNamesImpl(const Locale& locale, UDisplayContext *contexts, int32_t length); 30754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual ~LocaleDisplayNamesImpl(); 30854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 30954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual const Locale& getLocale() const; 31054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UDialectHandling getDialectHandling() const; 31154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UDisplayContext getContext(UDisplayContextType type) const; 31254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 31354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& localeDisplayName(const Locale& locale, 31454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 31554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& localeDisplayName(const char* localeId, 31654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 31754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& languageDisplayName(const char* lang, 31854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 31954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& scriptDisplayName(const char* script, 32054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 32154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode, 32254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 32354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& regionDisplayName(const char* region, 32454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 32554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& variantDisplayName(const char* variant, 32654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 32754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& keyDisplayName(const char* key, 32854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 32954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius virtual UnicodeString& keyValueDisplayName(const char* key, 33054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius const char* value, 33154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 33250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoprivate: 33354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& localeIdName(const char* localeId, 33454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const; 33554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& appendWithSep(UnicodeString& buffer, const UnicodeString& src) const; 33654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& adjustForUsageAndContext(CapContextUsage usage, UnicodeString& result) const; 33754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius void initialize(void); 33850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}; 33950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 340f9878a236aa0d9662d8e40cafdaf2e04cd615835ccorneliusUMutex LocaleDisplayNamesImpl::capitalizationBrkIterLock = U_MUTEX_INITIALIZER; 341f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius 34250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale, 34350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UDialectHandling dialectHandling) 34454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius : dialectHandling(dialectHandling) 34554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , langData(U_ICUDATA_LANG, locale) 34654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , regionData(U_ICUDATA_REGION, locale) 34759d709d503bab6e2b61931737e662dd293b40578ccornelius , separatorFormat(NULL) 34854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , format(NULL) 34954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , keyTypeFormat(NULL) 35054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , capitalizationContext(UDISPCTX_CAPITALIZATION_NONE) 351fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius , capitalizationBrkIter(NULL) 352f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius , nameLength(UDISPCTX_LENGTH_FULL) 35350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho{ 35454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius initialize(); 35554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 35650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 35754dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale, 35854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContext *contexts, int32_t length) 35954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius : dialectHandling(ULDN_STANDARD_NAMES) 36054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , langData(U_ICUDATA_LANG, locale) 36154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , regionData(U_ICUDATA_REGION, locale) 36259d709d503bab6e2b61931737e662dd293b40578ccornelius , separatorFormat(NULL) 36354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , format(NULL) 36454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , keyTypeFormat(NULL) 36554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius , capitalizationContext(UDISPCTX_CAPITALIZATION_NONE) 366fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius , capitalizationBrkIter(NULL) 367f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius , nameLength(UDISPCTX_LENGTH_FULL) 36854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius{ 36954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius while (length-- > 0) { 37054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContext value = *contexts++; 37154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContextType selector = (UDisplayContextType)((uint32_t)value >> 8); 37254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius switch (selector) { 37354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius case UDISPCTX_TYPE_DIALECT_HANDLING: 37454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius dialectHandling = (UDialectHandling)value; 37554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius break; 37654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius case UDISPCTX_TYPE_CAPITALIZATION: 37754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius capitalizationContext = value; 37854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius break; 379f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius case UDISPCTX_TYPE_DISPLAY_LENGTH: 380f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius nameLength = value; 381f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius break; 38254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius default: 38354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius break; 38454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 38554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 38654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius initialize(); 38754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 38850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 38954dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusvoid 39054dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNamesImpl::initialize(void) { 39154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this; 39254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius nonConstThis->locale = langData.getLocale() == Locale::getRoot() 39354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ? regionData.getLocale() 39454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius : langData.getLocale(); 395103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 39659d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString sep; 39754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.getNoFallback("localeDisplayPattern", "separator", sep); 39854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (sep.isBogus()) { 39959d709d503bab6e2b61931737e662dd293b40578ccornelius sep = UnicodeString("{0}, {1}", -1, US_INV); 40054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 40159d709d503bab6e2b61931737e662dd293b40578ccornelius UErrorCode status = U_ZERO_ERROR; 40259d709d503bab6e2b61931737e662dd293b40578ccornelius separatorFormat = new MessageFormat(sep, status); 40354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 40454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString pattern; 40554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.getNoFallback("localeDisplayPattern", "pattern", pattern); 40654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (pattern.isBogus()) { 40754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius pattern = UnicodeString("{0} ({1})", -1, US_INV); 40854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 40954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius format = new MessageFormat(pattern, status); 41059d709d503bab6e2b61931737e662dd293b40578ccornelius if (pattern.indexOf((UChar)0xFF08) >= 0) { 41159d709d503bab6e2b61931737e662dd293b40578ccornelius formatOpenParen.setTo((UChar)0xFF08); // fullwidth ( 41259d709d503bab6e2b61931737e662dd293b40578ccornelius formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [ 41359d709d503bab6e2b61931737e662dd293b40578ccornelius formatCloseParen.setTo((UChar)0xFF09); // fullwidth ) 41459d709d503bab6e2b61931737e662dd293b40578ccornelius formatReplaceCloseParen.setTo((UChar)0xFF3D); // fullwidth ] 41559d709d503bab6e2b61931737e662dd293b40578ccornelius } else { 41659d709d503bab6e2b61931737e662dd293b40578ccornelius formatOpenParen.setTo((UChar)0x0028); // ( 41759d709d503bab6e2b61931737e662dd293b40578ccornelius formatReplaceOpenParen.setTo((UChar)0x005B); // [ 41859d709d503bab6e2b61931737e662dd293b40578ccornelius formatCloseParen.setTo((UChar)0x0029); // ) 41959d709d503bab6e2b61931737e662dd293b40578ccornelius formatReplaceCloseParen.setTo((UChar)0x005D); // ] 42059d709d503bab6e2b61931737e662dd293b40578ccornelius } 42154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 42254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString ktPattern; 42354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("localeDisplayPattern", "keyTypePattern", ktPattern); 42454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (ktPattern.isBogus()) { 42554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ktPattern = UnicodeString("{0}={1}", -1, US_INV); 42654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 42754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius keyTypeFormat = new MessageFormat(ktPattern, status); 42854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 42954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uprv_memset(fCapitalization, 0, sizeof(fCapitalization)); 43054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#if !UCONFIG_NO_BREAK_ITERATION 43154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // The following is basically copied from DateFormatSymbols::initializeData 43254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius typedef struct { 43354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius const char * usageName; 43454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius LocaleDisplayNamesImpl::CapContextUsage usageEnum; 43554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } ContextUsageNameToEnum; 43654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius const ContextUsageNameToEnum contextUsageTypeMap[] = { 43754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // Entries must be sorted by usageTypeName; entry with NULL name terminates list. 43854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { "key", kCapContextUsageKey }, 439fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius { "keyValue", kCapContextUsageKeyValue }, 44054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { "languages", kCapContextUsageLanguage }, 44154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { "script", kCapContextUsageScript }, 44254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { "territory", kCapContextUsageTerritory }, 44354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { "variant", kCapContextUsageVariant }, 44454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius { NULL, (CapContextUsage)0 }, 44554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius }; 446fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // Only get the context data if we need it! This is a const object so we know now... 447fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // Also check whether we will need a break iterator (depends on the data) 448fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool needBrkIter = FALSE; 449fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE) { 450fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int32_t len = 0; 451fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &status); 45254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (U_SUCCESS(status)) { 453fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, "contextTransforms", NULL, &status); 454fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (U_SUCCESS(status)) { 455fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UResourceBundle *contextTransformUsage; 456fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &status)) != NULL ) { 457fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status); 458fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (U_SUCCESS(status) && intVector != NULL && len >= 2) { 459fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const char* usageKey = ures_getKey(contextTransformUsage); 460fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (usageKey != NULL) { 461fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const ContextUsageNameToEnum * typeMapPtr = contextUsageTypeMap; 462fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int32_t compResult = 0; 463fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // linear search; list is short and we cannot be sure that bsearch is available 464fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius while ( typeMapPtr->usageName != NULL && (compResult = uprv_strcmp(usageKey, typeMapPtr->usageName)) > 0 ) { 465fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ++typeMapPtr; 466fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 467fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (typeMapPtr->usageName != NULL && compResult == 0) { 468fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int32_t titlecaseInt = (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU)? intVector[0]: intVector[1]; 469fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (titlecaseInt != 0) { 470fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius fCapitalization[typeMapPtr->usageEnum] = TRUE;; 471fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius needBrkIter = TRUE; 472fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 473fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 47454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 47554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 476fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius status = U_ZERO_ERROR; 477fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ures_close(contextTransformUsage); 47854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 479fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ures_close(contextTransforms); 48054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 481fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ures_close(localeBundle); 482fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 483fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 484fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // Get a sentence break iterator if we will need it 485fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (needBrkIter || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) { 486fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius status = U_ZERO_ERROR; 487fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status); 488fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (U_FAILURE(status)) { 489fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius delete capitalizationBrkIter; 490fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius capitalizationBrkIter = NULL; 49154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 49254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 49354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#endif 49450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 49550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 49650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() { 49759d709d503bab6e2b61931737e662dd293b40578ccornelius delete separatorFormat; 49854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius delete format; 49954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius delete keyTypeFormat; 500fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius delete capitalizationBrkIter; 50154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 50250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 50350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoconst Locale& 50450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::getLocale() const { 50554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return locale; 50650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 50750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 50850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUDialectHandling 50950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::getDialectHandling() const { 51054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return dialectHandling; 51154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 51254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 51354dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusUDisplayContext 51454dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNamesImpl::getContext(UDisplayContextType type) const { 51554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius switch (type) { 51654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius case UDISPCTX_TYPE_DIALECT_HANDLING: 51754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return (UDisplayContext)dialectHandling; 51854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius case UDISPCTX_TYPE_CAPITALIZATION: 51954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return capitalizationContext; 520f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius case UDISPCTX_TYPE_DISPLAY_LENGTH: 521f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return nameLength; 52254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius default: 52354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius break; 52454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 52554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return (UDisplayContext)0; 52654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 52754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 52854dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusUnicodeString& 52954dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNamesImpl::adjustForUsageAndContext(CapContextUsage usage, 53054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UnicodeString& result) const { 53154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#if !UCONFIG_NO_BREAK_ITERATION 53254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // check to see whether we need to titlecase result 533fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if ( result.length() > 0 && u_islower(result.char32At(0)) && capitalizationBrkIter!= NULL && 534fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ( capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE || fCapitalization[usage] ) ) { 535fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // note fCapitalization[usage] won't be set unless capitalizationContext is UI_LIST_OR_MENU or STANDALONE 536f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius Mutex lock(&capitalizationBrkIterLock); 537fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius result.toTitle(capitalizationBrkIter, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT); 53854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 53954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#endif 54054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return result; 54150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 54250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 54350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 54450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::localeDisplayName(const Locale& locale, 54550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 54650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString resultName; 54750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 54850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* lang = locale.getLanguage(); 54950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (uprv_strlen(lang) == 0) { 55050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho lang = "root"; 55150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 55250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* script = locale.getScript(); 55350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* country = locale.getCountry(); 55450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* variant = locale.getVariant(); 55550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 55650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool hasScript = uprv_strlen(script) > 0; 55750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool hasCountry = uprv_strlen(country) > 0; 55850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UBool hasVariant = uprv_strlen(variant) > 0; 55950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 56050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (dialectHandling == ULDN_DIALECT_NAMES) { 56150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char buffer[ULOC_FULLNAME_CAPACITY]; 56250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho do { // loop construct is so we can break early out of search 56350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasScript && hasCountry) { 56450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0); 56550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho localeIdName(buffer, resultName); 56650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (!resultName.isBogus()) { 56750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho hasScript = FALSE; 56850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho hasCountry = FALSE; 56950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho break; 57050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 57150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 57250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasScript) { 57350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0); 57450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho localeIdName(buffer, resultName); 57550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (!resultName.isBogus()) { 57650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho hasScript = FALSE; 57750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho break; 57850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 57950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 58050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasCountry) { 58150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0); 58250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho localeIdName(buffer, resultName); 58350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (!resultName.isBogus()) { 58450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho hasCountry = FALSE; 58550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho break; 58650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 58750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 58850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } while (FALSE); 58950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 59050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (resultName.isBogus() || resultName.isEmpty()) { 59150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho localeIdName(lang, resultName); 59250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 59350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 59450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString resultRemainder; 59550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp; 59650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho StringEnumeration *e = NULL; 59750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode status = U_ZERO_ERROR; 59850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 59950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasScript) { 60050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultRemainder.append(scriptDisplayName(script, temp)); 60150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 60250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasCountry) { 60350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho appendWithSep(resultRemainder, regionDisplayName(country, temp)); 60450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 60550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (hasVariant) { 60650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho appendWithSep(resultRemainder, variantDisplayName(variant, temp)); 60750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 60859d709d503bab6e2b61931737e662dd293b40578ccornelius resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen); 60959d709d503bab6e2b61931737e662dd293b40578ccornelius resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen); 61050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 61150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho e = locale.createKeywords(status); 61250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (e && U_SUCCESS(status)) { 61350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp2; 61450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY 61550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* key; 61650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho while ((key = e->next((int32_t *)0, status)) != NULL) { 61750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status); 618103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius keyDisplayName(key, temp); 61959d709d503bab6e2b61931737e662dd293b40578ccornelius temp.findAndReplace(formatOpenParen, formatReplaceOpenParen); 62059d709d503bab6e2b61931737e662dd293b40578ccornelius temp.findAndReplace(formatCloseParen, formatReplaceCloseParen); 621103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius keyValueDisplayName(key, value, temp2); 62259d709d503bab6e2b61931737e662dd293b40578ccornelius temp2.findAndReplace(formatOpenParen, formatReplaceOpenParen); 62359d709d503bab6e2b61931737e662dd293b40578ccornelius temp2.findAndReplace(formatCloseParen, formatReplaceCloseParen); 624103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (temp2 != UnicodeString(value, -1, US_INV)) { 625103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius appendWithSep(resultRemainder, temp2); 626103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else if (temp != UnicodeString(key, -1, US_INV)) { 627103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UnicodeString temp3; 628103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius Formattable data[] = { 629103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius temp, 630103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius temp2 631103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius }; 632103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius FieldPosition fpos; 633103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius status = U_ZERO_ERROR; 634103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius keyTypeFormat->format(data, 2, temp3, fpos, status); 635103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius appendWithSep(resultRemainder, temp3); 636103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else { 637103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius appendWithSep(resultRemainder, temp) 638b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho .append((UChar)0x3d /* = */) 639103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius .append(temp2); 640103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 64150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 64250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho delete e; 64350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 64450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 64550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (!resultRemainder.isEmpty()) { 64650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho Formattable data[] = { 64750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultName, 64850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho resultRemainder 64950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho }; 65050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho FieldPosition fpos; 65150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho status = U_ZERO_ERROR; 65250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho format->format(data, 2, result, fpos, status); 65354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageLanguage, result); 65450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 65550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 65654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius result = resultName; 65754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageLanguage, result); 65850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 65950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 66050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 66150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::appendWithSep(UnicodeString& buffer, const UnicodeString& src) const { 66259d709d503bab6e2b61931737e662dd293b40578ccornelius if (buffer.isEmpty()) { 66359d709d503bab6e2b61931737e662dd293b40578ccornelius buffer.setTo(src); 66459d709d503bab6e2b61931737e662dd293b40578ccornelius } else { 66559d709d503bab6e2b61931737e662dd293b40578ccornelius UnicodeString combined; 66659d709d503bab6e2b61931737e662dd293b40578ccornelius Formattable data[] = { 66759d709d503bab6e2b61931737e662dd293b40578ccornelius buffer, 66859d709d503bab6e2b61931737e662dd293b40578ccornelius src 66959d709d503bab6e2b61931737e662dd293b40578ccornelius }; 67059d709d503bab6e2b61931737e662dd293b40578ccornelius FieldPosition fpos; 67159d709d503bab6e2b61931737e662dd293b40578ccornelius UErrorCode status = U_ZERO_ERROR; 67259d709d503bab6e2b61931737e662dd293b40578ccornelius separatorFormat->format(data, 2, combined, fpos, status); 67359d709d503bab6e2b61931737e662dd293b40578ccornelius if (U_SUCCESS(status)) { 67459d709d503bab6e2b61931737e662dd293b40578ccornelius buffer.setTo(combined); 67559d709d503bab6e2b61931737e662dd293b40578ccornelius } 67654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 67754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return buffer; 67850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 67950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 68050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 68150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::localeDisplayName(const char* localeId, 68250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 68354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return localeDisplayName(Locale(localeId), result); 68450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 68550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 68654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// private 68750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 68850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::localeIdName(const char* localeId, 68950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 690f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (nameLength == UDISPCTX_LENGTH_SHORT) { 6911b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert langData.getNoFallback("Languages%short", localeId, result); 692f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (!result.isBogus()) { 693f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return result; 694f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 695f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 69654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return langData.getNoFallback("Languages", localeId, result); 69750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 69850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 69950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 70050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::languageDisplayName(const char* lang, 70150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 70254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) { 70354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return result = UnicodeString(lang, -1, US_INV); 70454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 705f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (nameLength == UDISPCTX_LENGTH_SHORT) { 7061b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert langData.get("Languages%short", lang, result); 707f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (!result.isBogus()) { 708f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return adjustForUsageAndContext(kCapContextUsageLanguage, result); 709f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 710f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 71154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("Languages", lang, result); 71254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageLanguage, result); 71350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 71450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 71550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 71650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::scriptDisplayName(const char* script, 71750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 718f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (nameLength == UDISPCTX_LENGTH_SHORT) { 719f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius langData.get("Scripts%short", script, result); 720f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (!result.isBogus()) { 721f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return adjustForUsageAndContext(kCapContextUsageScript, result); 722f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 723f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 72454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("Scripts", script, result); 72554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageScript, result); 72650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 72750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 72850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 72950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode, 73050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 731f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return scriptDisplayName(uscript_getName(scriptCode), result); 73250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 73350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 73450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 73550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::regionDisplayName(const char* region, 73650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 737f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (nameLength == UDISPCTX_LENGTH_SHORT) { 7381b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert regionData.get("Countries%short", region, result); 739f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (!result.isBogus()) { 740f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return adjustForUsageAndContext(kCapContextUsageTerritory, result); 741f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 742f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 74354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius regionData.get("Countries", region, result); 74454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageTerritory, result); 74550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 74650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 74750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 74850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::variantDisplayName(const char* variant, 74950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 750f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // don't have a resource for short variant names 75154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("Variants", variant, result); 75254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageVariant, result); 75350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 75450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 75550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 75650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::keyDisplayName(const char* key, 75750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 758f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius // don't have a resource for short key names 75954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("Keys", key, result); 76054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return adjustForUsageAndContext(kCapContextUsageKey, result); 76150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 76250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 76350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoUnicodeString& 76450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNamesImpl::keyValueDisplayName(const char* key, 76550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char* value, 76650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString& result) const { 7671b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert if (uprv_strcmp(key, "currency") == 0) { 7681b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert // ICU4C does not have ICU4J CurrencyDisplayInfo equivalent for now. 7691b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert UErrorCode sts = U_ZERO_ERROR; 7701b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert UnicodeString ustrValue(value, -1, US_INV); 7711b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert int32_t len; 7721b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert UBool isChoice = FALSE; 7731b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert const UChar *currencyName = ucurr_getName(ustrValue.getTerminatedBuffer(), 7741b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert locale.getBaseName(), UCURR_LONG_NAME, &isChoice, &len, &sts); 7751b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert if (U_FAILURE(sts)) { 7761b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert // Return the value as is on failure 7771b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert result = ustrValue; 7781b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert return result; 7791b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert } 7801b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert result.setTo(currencyName, len); 7811b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert return adjustForUsageAndContext(kCapContextUsageKeyValue, result); 7821b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert } 7831b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert 784f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (nameLength == UDISPCTX_LENGTH_SHORT) { 785f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius langData.get("Types%short", key, value, result); 786f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius if (!result.isBogus()) { 787f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius return adjustForUsageAndContext(kCapContextUsageKeyValue, result); 788f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 789f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius } 79054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius langData.get("Types", key, value, result); 791fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius return adjustForUsageAndContext(kCapContextUsageKeyValue, result); 79250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 79350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 79450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 79550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 79650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNames* 79750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoLocaleDisplayNames::createInstance(const Locale& locale, 79850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UDialectHandling dialectHandling) { 79954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return new LocaleDisplayNamesImpl(locale, dialectHandling); 80054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 80154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 80254dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNames* 80354dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusLocaleDisplayNames::createInstance(const Locale& locale, 80454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContext *contexts, int32_t length) { 80554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (contexts == NULL) { 80654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius length = 0; 80754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 80854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return new LocaleDisplayNamesImpl(locale, contexts, length); 80950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 81050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 81150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_END 81250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 81350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho//////////////////////////////////////////////////////////////////////////////////////////////////// 81450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 81550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_USE 81650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 81754dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI ULocaleDisplayNames * U_EXPORT2 81850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_open(const char * locale, 81950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UDialectHandling dialectHandling, 82050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 82150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 82250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 82350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 82450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (locale == NULL) { 82550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho locale = uloc_getDefault(); 82650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 82750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), dialectHandling); 82850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 82950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 83054dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI ULocaleDisplayNames * U_EXPORT2 83154dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusuldn_openForContext(const char * locale, 83254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContext *contexts, int32_t length, 83354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode *pErrorCode) { 83454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (U_FAILURE(*pErrorCode)) { 83554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return 0; 83654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 83754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (locale == NULL) { 83854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius locale = uloc_getDefault(); 83954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 84054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), contexts, length); 84154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 84254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 84354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 84454dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI void U_EXPORT2 84550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_close(ULocaleDisplayNames *ldn) { 84650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho delete (LocaleDisplayNames *)ldn; 84750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 84850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 84954dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI const char * U_EXPORT2 85050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_getLocale(const ULocaleDisplayNames *ldn) { 85150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn) { 85250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return ((const LocaleDisplayNames *)ldn)->getLocale().getName(); 85350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 85450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return NULL; 85550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 85650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 85754dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI UDialectHandling U_EXPORT2 85850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_getDialectHandling(const ULocaleDisplayNames *ldn) { 85950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn) { 86050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return ((const LocaleDisplayNames *)ldn)->getDialectHandling(); 86150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 86250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return ULDN_STANDARD_NAMES; 86350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 86450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 86554dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI UDisplayContext U_EXPORT2 86654dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusuldn_getContext(const ULocaleDisplayNames *ldn, 86754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UDisplayContextType type, 86854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode *pErrorCode) { 86954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (U_FAILURE(*pErrorCode)) { 87054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return (UDisplayContext)0; 87154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 87254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return ((const LocaleDisplayNames *)ldn)->getContext(type); 87354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 87454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 87554dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 87650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_localeDisplayName(const ULocaleDisplayNames *ldn, 87750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *locale, 87850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 87950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 88050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 88150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 88250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 88350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 88450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || locale == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 88550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 88650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 88750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 88850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 88950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->localeDisplayName(locale, temp); 89050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 89150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 89250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 89354dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 89450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_languageDisplayName(const ULocaleDisplayNames *ldn, 89550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *lang, 89650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 89750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 89850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 89950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 90050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 90150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 90250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || lang == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 90350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 90450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 90550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 90650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 90750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->languageDisplayName(lang, temp); 90850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 90950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 91050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 91154dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 91250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_scriptDisplayName(const ULocaleDisplayNames *ldn, 91350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *script, 91450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 91550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 91650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 91750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 91850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 91950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 92050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || script == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 92150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 92250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 92350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 92450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 92550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->scriptDisplayName(script, temp); 92650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 92750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 92850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 92954dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 93050294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn, 93150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UScriptCode scriptCode, 93250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 93350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 93450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 93550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return uldn_scriptDisplayName(ldn, uscript_getName(scriptCode), result, maxResultSize, pErrorCode); 93650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 93750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 93854dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 93950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_regionDisplayName(const ULocaleDisplayNames *ldn, 94050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *region, 94150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 94250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 94350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 94450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 94550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 94650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 94750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || region == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 94850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 94950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 95050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 95150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 95250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->regionDisplayName(region, temp); 95350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 95450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 95550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 95654dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 95750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_variantDisplayName(const ULocaleDisplayNames *ldn, 95850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *variant, 95950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 96050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 96150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 96250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 96350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 96450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 96550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || variant == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 96650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 96750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 96850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 96950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 97050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->variantDisplayName(variant, temp); 97150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 97250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 97350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 97454dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 97550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_keyDisplayName(const ULocaleDisplayNames *ldn, 97650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *key, 97750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 97850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 97950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 98050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 98150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 98250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 98350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || key == NULL || (result == NULL && maxResultSize > 0) || maxResultSize < 0) { 98450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 98550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 98650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 98750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 98850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->keyDisplayName(key, temp); 98950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 99050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 99150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 99254dcd9b6a06071f647dac967e9e267abb9410720Craig CorneliusU_CAPI int32_t U_EXPORT2 99350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehouldn_keyValueDisplayName(const ULocaleDisplayNames *ldn, 99450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *key, 99550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *value, 99650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UChar *result, 99750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t maxResultSize, 99850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UErrorCode *pErrorCode) { 99950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (U_FAILURE(*pErrorCode)) { 100050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 100150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 100250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (ldn == NULL || key == NULL || value == NULL || (result == NULL && maxResultSize > 0) 100350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho || maxResultSize < 0) { 100450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; 100550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return 0; 100650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho } 100750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho UnicodeString temp(result, 0, maxResultSize); 100850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho ((const LocaleDisplayNames *)ldn)->keyValueDisplayName(key, value, temp); 100950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho return temp.extract(result, maxResultSize, *pErrorCode); 101050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho} 101150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 101250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 1013