UnicodeString& LocaleDisplayNamesImpl::keyValueDisplayName(const char* key, const char* value, UnicodeString& result, UBool skipAdjust) const { if (uprv_strcmp(key, "currency") == 0) { // ICU4C does not have ICU4J CurrencyDisplayInfo equivalent for now. UErrorCode sts = U_ZERO_ERROR; UnicodeString ustrValue(value, -1, US_INV); int32_t len; UBool isChoice = FALSE; const UChar *currencyName = ucurr_getName(ustrValue.getTerminatedBuffer(), locale.getBaseName(), UCURR_LONG_NAME, &isChoice, &len, &sts); if (U_FAILURE(sts)) { // Return the value as is on failure result = ustrValue; return result; } result.setTo(currencyName, len); return skipAdjust? result: adjustForUsageAndContext(kCapContextUsageKeyValue, result); } if (nameLength == UDISPCTX_LENGTH_SHORT) { langData.get("Types%short", key, value, result); if (!result.isBogus()) { return skipAdjust? result: adjustForUsageAndContext(kCapContextUsageKeyValue, result); } } langData.get("Types", key, value, result); return skipAdjust? result: adjustForUsageAndContext(kCapContextUsageKeyValue, result); }
UnicodeString& LocaleDisplayNamesImpl::scriptDisplayName(const char* script, UnicodeString& result) const { if (nameLength == UDISPCTX_LENGTH_SHORT) { langData.get("Scripts%short", script, result); if (!result.isBogus()) { return adjustForUsageAndContext(kCapContextUsageScript, result); } } langData.get("Scripts", script, result); return adjustForUsageAndContext(kCapContextUsageScript, result); }
UnicodeString& LocaleDisplayNamesImpl::regionDisplayName(const char* region, UnicodeString& result) const { if (nameLength == UDISPCTX_LENGTH_SHORT) { regionData.get("Countries%short", region, result); if (!result.isBogus()) { return adjustForUsageAndContext(kCapContextUsageTerritory, result); } } regionData.get("Countries", region, result); return adjustForUsageAndContext(kCapContextUsageTerritory, result); }
UnicodeString& LocaleDisplayNamesImpl::languageDisplayName(const char* lang, UnicodeString& result) const { if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) { return result = UnicodeString(lang, -1, US_INV); } if (nameLength == UDISPCTX_LENGTH_SHORT) { langData.get("Languages%short", lang, result); if (!result.isBogus()) { return adjustForUsageAndContext(kCapContextUsageLanguage, result); } } langData.get("Languages", lang, result); return adjustForUsageAndContext(kCapContextUsageLanguage, result); }
UnicodeString& LocaleDisplayNamesImpl::keyDisplayName(const char* key, UnicodeString& result) const { // don't have a resource for short key names langData.get("Keys", key, result); return adjustForUsageAndContext(kCapContextUsageKey, result); }
UnicodeString& LocaleDisplayNamesImpl::variantDisplayName(const char* variant, UnicodeString& result) const { // don't have a resource for short variant names langData.get("Variants", variant, result); return adjustForUsageAndContext(kCapContextUsageVariant, result); }
UnicodeString& LocaleDisplayNamesImpl::languageDisplayName(const char* lang, UnicodeString& result) const { if (uprv_strcmp("root", lang) == 0 || uprv_strchr(lang, '_') != NULL) { return result = UnicodeString(lang, -1, US_INV); } return langData.get("Languages", lang, result); }
void LocaleDisplayNamesImpl::initialize(void) { LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this; nonConstThis->locale = langData.getLocale() == Locale::getRoot() ? regionData.getLocale() : langData.getLocale(); UnicodeString sep; langData.getNoFallback("localeDisplayPattern", "separator", sep); if (sep.isBogus()) { sep = UnicodeString("{0}, {1}", -1, US_INV); } UErrorCode status = U_ZERO_ERROR; separatorFormat.applyPatternMinMaxArguments(sep, 2, 2, status); UnicodeString pattern; langData.getNoFallback("localeDisplayPattern", "pattern", pattern); if (pattern.isBogus()) { pattern = UnicodeString("{0} ({1})", -1, US_INV); } format.applyPatternMinMaxArguments(pattern, 2, 2, status); if (pattern.indexOf((UChar)0xFF08) >= 0) { formatOpenParen.setTo((UChar)0xFF08); // fullwidth ( formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [ formatCloseParen.setTo((UChar)0xFF09); // fullwidth ) formatReplaceCloseParen.setTo((UChar)0xFF3D); // fullwidth ] } else { formatOpenParen.setTo((UChar)0x0028); // ( formatReplaceOpenParen.setTo((UChar)0x005B); // [ formatCloseParen.setTo((UChar)0x0029); // ) formatReplaceCloseParen.setTo((UChar)0x005D); // ] } UnicodeString ktPattern; langData.get("localeDisplayPattern", "keyTypePattern", ktPattern); if (ktPattern.isBogus()) { ktPattern = UnicodeString("{0}={1}", -1, US_INV); } keyTypeFormat.applyPatternMinMaxArguments(ktPattern, 2, 2, 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 }, { "keyValue", kCapContextUsageKeyValue }, { "languages", kCapContextUsageLanguage }, { "script", kCapContextUsageScript }, { "territory", kCapContextUsageTerritory }, { "variant", kCapContextUsageVariant }, { NULL, (CapContextUsage)0 }, }; // Only get the context data if we need it! This is a const object so we know now... // Also check whether we will need a break iterator (depends on the data) UBool needBrkIter = FALSE; if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE) { 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) { int32_t titlecaseInt = (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU)? intVector[0]: intVector[1]; if (titlecaseInt != 0) { fCapitalization[typeMapPtr->usageEnum] = TRUE;; needBrkIter = TRUE; } } } } status = U_ZERO_ERROR; ures_close(contextTransformUsage); } ures_close(contextTransforms); } ures_close(localeBundle); } } // Get a sentence break iterator if we will need it if (needBrkIter || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) { status = U_ZERO_ERROR; capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status); if (U_FAILURE(status)) { delete capitalizationBrkIter; capitalizationBrkIter = NULL; } } #endif }
void LocaleDisplayNamesImpl::initialize(void) { LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this; nonConstThis->locale = langData.getLocale() == Locale::getRoot() ? regionData.getLocale() : langData.getLocale(); UnicodeString sep; langData.getNoFallback("localeDisplayPattern", "separator", sep); if (sep.isBogus()) { sep = UnicodeString("{0}, {1}", -1, US_INV); } UErrorCode status = U_ZERO_ERROR; separatorFormat.applyPatternMinMaxArguments(sep, 2, 2, status); UnicodeString pattern; langData.getNoFallback("localeDisplayPattern", "pattern", pattern); if (pattern.isBogus()) { pattern = UnicodeString("{0} ({1})", -1, US_INV); } format.applyPatternMinMaxArguments(pattern, 2, 2, status); if (pattern.indexOf((UChar)0xFF08) >= 0) { formatOpenParen.setTo((UChar)0xFF08); // fullwidth ( formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [ formatCloseParen.setTo((UChar)0xFF09); // fullwidth ) formatReplaceCloseParen.setTo((UChar)0xFF3D); // fullwidth ] } else { formatOpenParen.setTo((UChar)0x0028); // ( formatReplaceOpenParen.setTo((UChar)0x005B); // [ formatCloseParen.setTo((UChar)0x0029); // ) formatReplaceCloseParen.setTo((UChar)0x005D); // ] } UnicodeString ktPattern; langData.get("localeDisplayPattern", "keyTypePattern", ktPattern); if (ktPattern.isBogus()) { ktPattern = UnicodeString("{0}={1}", -1, US_INV); } keyTypeFormat.applyPatternMinMaxArguments(ktPattern, 2, 2, status); uprv_memset(fCapitalization, 0, sizeof(fCapitalization)); #if !UCONFIG_NO_BREAK_ITERATION // Only get the context data if we need it! This is a const object so we know now... // Also check whether we will need a break iterator (depends on the data) UBool needBrkIter = FALSE; if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE) { LocalUResourceBundlePointer resource(ures_open(NULL, locale.getName(), &status)); if (U_FAILURE(status)) { return; } CapitalizationContextSink sink(*this); ures_getAllItemsWithFallback(resource.getAlias(), "contextTransforms", sink, status); if (status == U_MISSING_RESOURCE_ERROR) { // Silently ignore. Not every locale has contextTransforms. status = U_ZERO_ERROR; } else if (U_FAILURE(status)) { return; } needBrkIter = sink.hasCapitalizationUsage; } // Get a sentence break iterator if we will need it if (needBrkIter || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) { status = U_ZERO_ERROR; capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status); if (U_FAILURE(status)) { delete capitalizationBrkIter; capitalizationBrkIter = NULL; } } #endif }
UnicodeString& LocaleDisplayNamesImpl::keyValueDisplayName(const char* key, const char* value, UnicodeString& result) const { return langData.get("Types", key, value, result); }
UnicodeString& LocaleDisplayNamesImpl::keyDisplayName(const char* key, UnicodeString& result) const { return langData.get("Keys", key, result); }
UnicodeString& LocaleDisplayNamesImpl::variantDisplayName(const char* variant, UnicodeString& result) const { return langData.get("Variants", variant, result); }
UnicodeString& LocaleDisplayNamesImpl::regionDisplayName(const char* region, UnicodeString& result) const { return regionData.get("Countries", region, result); }
UnicodeString& LocaleDisplayNamesImpl::scriptDisplayName(UScriptCode scriptCode, UnicodeString& result) const { const char* name = uscript_getName(scriptCode); return langData.get("Scripts", name, result); }
UnicodeString& LocaleDisplayNamesImpl::scriptDisplayName(const char* script, UnicodeString& result) const { return langData.get("Scripts", script, result); }