本文整理汇总了C++中NumberFormat::setLocaleIDs方法的典型用法代码示例。如果您正苦于以下问题:C++ NumberFormat::setLocaleIDs方法的具体用法?C++ NumberFormat::setLocaleIDs怎么用?C++ NumberFormat::setLocaleIDs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumberFormat
的用法示例。
在下文中一共展示了NumberFormat::setLocaleIDs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
//.........这里部分代码省略.........
hashKey = desiredLocale.hashCode();
umtx_lock(&nscacheMutex);
ns = (NumberingSystem *)uhash_iget(cache, hashKey);
if (ns == NULL) {
ns = NumberingSystem::createInstance(desiredLocale,status);
uhash_iput(cache, hashKey, (void*)ns, &status);
}
umtx_unlock(&nscacheMutex);
}
else {
ns = NumberingSystem::createInstance(desiredLocale,status);
deleteNS = TRUE;
}
// check results of getting a numbering system
if ((ns == NULL) || (U_FAILURE(status))) {
goto cleanup;
}
if (ns->isAlgorithmic()) {
UnicodeString nsDesc;
UnicodeString nsRuleSetGroup;
UnicodeString nsRuleSetName;
Locale nsLoc;
URBNFRuleSetTag desiredRulesType = URBNF_NUMBERING_SYSTEM;
nsDesc.setTo(ns->getDescription());
int32_t firstSlash = nsDesc.indexOf(gSlash);
int32_t lastSlash = nsDesc.lastIndexOf(gSlash);
if ( lastSlash > firstSlash ) {
char nsLocID[ULOC_FULLNAME_CAPACITY];
nsDesc.extract(0,firstSlash,nsLocID,ULOC_FULLNAME_CAPACITY,US_INV);
nsRuleSetGroup.setTo(nsDesc,firstSlash+1,lastSlash-firstSlash-1);
nsRuleSetName.setTo(nsDesc,lastSlash+1);
nsLoc = Locale::createFromName(nsLocID);
UnicodeString SpelloutRules = UNICODE_STRING_SIMPLE("SpelloutRules");
if ( nsRuleSetGroup.compare(SpelloutRules) == 0 ) {
desiredRulesType = URBNF_SPELLOUT;
}
} else {
nsLoc = desiredLocale;
nsRuleSetName.setTo(nsDesc);
}
RuleBasedNumberFormat *r = new RuleBasedNumberFormat(desiredRulesType,nsLoc,status);
if (U_FAILURE(status) || r == NULL) {
goto cleanup;
}
r->setDefaultRuleSet(nsRuleSetName,status);
f = (NumberFormat *) r;
} else {
// replace single currency sign in the pattern with double currency sign
// if the style is kIsoCurrencyStyle
if (style == kIsoCurrencyStyle) {
pattern.findAndReplace(gSingleCurrencySign, gDoubleCurrencySign);
}
f = new DecimalFormat(pattern, symbolsToAdopt, style, status);
if (U_FAILURE(status) || f == NULL) {
goto cleanup;
}
deleteSymbols = FALSE;
}
f->setLocaleIDs(ures_getLocaleByType(numberPatterns, ULOC_VALID_LOCALE, &status),
ures_getLocaleByType(numberPatterns, ULOC_ACTUAL_LOCALE, &status));
cleanup:
ures_close(numberPatterns);
ures_close(resource);
if (deleteNS && ns) {
delete ns;
}
if (U_FAILURE(status)) {
/* If f exists, then it will delete the symbols */
if (f==NULL) {
delete symbolsToAdopt;
}
else {
delete f;
}
return NULL;
}
if (f == NULL || symbolsToAdopt == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
f = NULL;
}
if (deleteSymbols && symbolsToAdopt != NULL) {
delete symbolsToAdopt;
}
return f;
}
示例2: lock
//.........这里部分代码省略.........
if (symbolsToAdopt.isNull()) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
UResourceBundle *resource = ownedResource.orphan();
UResourceBundle *numElements = ures_getByKeyWithFallback(resource, gNumberElements, NULL, &status);
resource = ures_getByKeyWithFallback(numElements, ns->getName(), resource, &status);
resource = ures_getByKeyWithFallback(resource, gPatterns, resource, &status);
ownedResource.adoptInstead(resource);
int32_t patLen = 0;
const UChar *patResStr = ures_getStringByKeyWithFallback(resource, gFormatKeys[style], &patLen, &status);
// Didn't find a pattern specific to the numbering system, so fall back to "latn"
if ( status == U_MISSING_RESOURCE_ERROR && uprv_strcmp(gLatn,ns->getName())) {
status = U_ZERO_ERROR;
resource = ures_getByKeyWithFallback(numElements, gLatn, resource, &status);
resource = ures_getByKeyWithFallback(resource, gPatterns, resource, &status);
patResStr = ures_getStringByKeyWithFallback(resource, gFormatKeys[style], &patLen, &status);
}
ures_close(numElements);
// Creates the specified decimal format style of the desired locale.
pattern.setTo(TRUE, patResStr, patLen);
}
if (U_FAILURE(status)) {
return NULL;
}
if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO){
const UChar* currPattern = symbolsToAdopt->getCurrencyPattern();
if(currPattern!=NULL){
pattern.setTo(currPattern, u_strlen(currPattern));
}
}
NumberFormat *f;
if (ns->isAlgorithmic()) {
UnicodeString nsDesc;
UnicodeString nsRuleSetGroup;
UnicodeString nsRuleSetName;
Locale nsLoc;
URBNFRuleSetTag desiredRulesType = URBNF_NUMBERING_SYSTEM;
nsDesc.setTo(ns->getDescription());
int32_t firstSlash = nsDesc.indexOf(gSlash);
int32_t lastSlash = nsDesc.lastIndexOf(gSlash);
if ( lastSlash > firstSlash ) {
CharString nsLocID;
nsLocID.appendInvariantChars(nsDesc.tempSubString(0, firstSlash), status);
nsRuleSetGroup.setTo(nsDesc,firstSlash+1,lastSlash-firstSlash-1);
nsRuleSetName.setTo(nsDesc,lastSlash+1);
nsLoc = Locale::createFromName(nsLocID.data());
UnicodeString SpelloutRules = UNICODE_STRING_SIMPLE("SpelloutRules");
if ( nsRuleSetGroup.compare(SpelloutRules) == 0 ) {
desiredRulesType = URBNF_SPELLOUT;
}
} else {
nsLoc = desiredLocale;
nsRuleSetName.setTo(nsDesc);
}
RuleBasedNumberFormat *r = new RuleBasedNumberFormat(desiredRulesType,nsLoc,status);
if (r == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
r->setDefaultRuleSet(nsRuleSetName,status);
f = r;
} else {
// replace single currency sign in the pattern with double currency sign
// if the style is UNUM_CURRENCY_ISO
if (style == UNUM_CURRENCY_ISO) {
pattern.findAndReplace(UnicodeString(TRUE, gSingleCurrencySign, 1),
UnicodeString(TRUE, gDoubleCurrencySign, 2));
}
// "new DecimalFormat()" does not adopt the symbols if its memory allocation fails.
DecimalFormatSymbols *syms = symbolsToAdopt.orphan();
f = new DecimalFormat(pattern, syms, style, status);
if (f == NULL) {
delete syms;
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
}
f->setLocaleIDs(ures_getLocaleByType(ownedResource.getAlias(), ULOC_VALID_LOCALE, &status),
ures_getLocaleByType(ownedResource.getAlias(), ULOC_ACTUAL_LOCALE, &status));
if (U_FAILURE(status)) {
delete f;
return NULL;
}
return f;
}