fInternalStatus = info.fInternalStatus; if (U_FAILURE(fInternalStatus)) { // bail out early if the object we were copying from was already 'invalid'. return *this;
}
if (info.fPluralRules != nullptr) {
fPluralRules = info.fPluralRules->clone(); if (fPluralRules == nullptr) {
fInternalStatus = U_MEMORY_ALLOCATION_ERROR; return *this;
}
} if (info.fLocale != nullptr) {
fLocale = info.fLocale->clone(); if (fLocale == nullptr) { // Note: If clone had an error parameter, then we could check/set that instead.
fInternalStatus = U_MEMORY_ALLOCATION_ERROR; return *this;
} // If the other locale wasn't bogus, but our clone'd locale is bogus, then OOM happened // during the call to clone(). if (!info.fLocale->isBogus() && fLocale->isBogus()) {
fInternalStatus = U_MEMORY_ALLOCATION_ERROR; return *this;
}
} return *this;
}
CurrencyPluralInfo*
CurrencyPluralInfo::clone() const {
CurrencyPluralInfo* newObj = new CurrencyPluralInfo(*this); // Since clone doesn't have a 'status' parameter, the best we can do is return nullptr // if the new object was not full constructed properly (an error occurred). if (newObj != nullptr && U_FAILURE(newObj->fInternalStatus)) { delete newObj;
newObj = nullptr;
} return newObj;
}
UnicodeString&
CurrencyPluralInfo::getCurrencyPluralPattern(const UnicodeString& pluralCount,
UnicodeString& result) const { const UnicodeString* currencyPluralPattern = static_cast<UnicodeString*>(fPluralCountToCurrencyUnitPattern->get(pluralCount)); if (currencyPluralPattern == nullptr) { // fall back to "other" if (pluralCount.compare(gPluralCountOther, 5)) {
currencyPluralPattern = static_cast<UnicodeString*>(fPluralCountToCurrencyUnitPattern->get(UnicodeString(true, gPluralCountOther, 5)));
} if (currencyPluralPattern == nullptr) { // no currencyUnitPatterns defined, // fallback to predefined default. // This should never happen when ICU resource files are // available, since currencyUnitPattern of "other" is always // defined in root.
result = UnicodeString(gDefaultCurrencyPluralPattern); return result;
}
}
result = *currencyPluralPattern; return result;
}
void
CurrencyPluralInfo::setCurrencyPluralPattern(const UnicodeString& pluralCount, const UnicodeString& pattern,
UErrorCode& status) { if (U_SUCCESS(status)) {
UnicodeString* oldValue = static_cast<UnicodeString*>(
fPluralCountToCurrencyUnitPattern->get(pluralCount)); delete oldValue;
LocalPointer<UnicodeString> p(new UnicodeString(pattern), status); if (U_SUCCESS(status)) { // the p object allocated above will be owned by fPluralCountToCurrencyUnitPattern // after the call to put(), even if the method returns failure.
fPluralCountToCurrencyUnitPattern->put(pluralCount, p.orphan(), status);
}
}
}
fLocale = loc.clone(); if (fLocale == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return;
} // If the locale passed in wasn't bogus, but our clone'd locale is bogus, then OOM happened // during the call to loc.clone(). if (!loc.isBogus() && fLocale->isBogus()) {
status = U_MEMORY_ALLOCATION_ERROR; return;
}
fPluralRules = PluralRules::forLocale(loc, status);
setupCurrencyPluralPattern(loc, status);
}
deleteHash(fPluralCountToCurrencyUnitPattern);
fPluralCountToCurrencyUnitPattern = initHash(status); if (U_FAILURE(status)) { return;
}
LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(loc, status), status); if (U_FAILURE(status)) { return;
}
UErrorCode ec = U_ZERO_ERROR;
LocalUResourceBundlePointer rb(ures_open(nullptr, loc.getName(), &ec));
LocalUResourceBundlePointer numElements(ures_getByKeyWithFallback(rb.getAlias(), gNumberElementsTag, nullptr, &ec));
ures_getByKeyWithFallback(numElements.getAlias(), ns->getName(), rb.getAlias(), &ec);
ures_getByKeyWithFallback(rb.getAlias(), gPatternsTag, rb.getAlias(), &ec);
int32_t ptnLen; const char16_t* numberStylePattern = ures_getStringByKeyWithFallback(rb.getAlias(), gDecimalFormatTag, &ptnLen, &ec); // Fall back to "latn" if num sys specific pattern isn't there. if ( ec == U_MISSING_RESOURCE_ERROR && (uprv_strcmp(ns->getName(), gLatnTag) != 0)) {
ec = U_ZERO_ERROR;
ures_getByKeyWithFallback(numElements.getAlias(), gLatnTag, rb.getAlias(), &ec);
ures_getByKeyWithFallback(rb.getAlias(), gPatternsTag, rb.getAlias(), &ec);
numberStylePattern = ures_getStringByKeyWithFallback(rb.getAlias(), gDecimalFormatTag, &ptnLen, &ec);
}
int32_t numberStylePatternLen = ptnLen; const char16_t* negNumberStylePattern = nullptr;
int32_t negNumberStylePatternLen = 0; // TODO: Java // parse to check whether there is ";" separator in the numberStylePattern
UBool hasSeparator = false; if (U_SUCCESS(ec)) { for (int32_t styleCharIndex = 0; styleCharIndex < ptnLen; ++styleCharIndex) { if (numberStylePattern[styleCharIndex] == gNumberPatternSeparator) {
hasSeparator = true; // split the number style pattern into positive and negative
negNumberStylePattern = numberStylePattern + styleCharIndex + 1;
negNumberStylePatternLen = ptnLen - styleCharIndex - 1;
numberStylePatternLen = styleCharIndex;
}
}
}
if (U_FAILURE(ec)) { // If OOM occurred during the above code, then we want to report that back to the caller. if (ec == U_MEMORY_ALLOCATION_ERROR) {
status = ec;
} return;
}
if (hasSeparator) {
UnicodeString negPattern(patternChars, ptnLength);
negPattern.findAndReplace(UnicodeString(true, gPart0, 3),
UnicodeString(negNumberStylePattern, negNumberStylePatternLen));
negPattern.findAndReplace(UnicodeString(true, gPart1, 3), UnicodeString(true, gTripleCurrencySign, 3));
pattern->append(gNumberPatternSeparator);
pattern->append(negPattern);
} #ifdef CURRENCY_PLURAL_INFO_DEBUG
pattern->extract(0, pattern->length(), result_1, "UTF-8");
std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n"; #endif // the 'pattern' object allocated above will be owned by the fPluralCountToCurrencyUnitPattern after the call to // put(), even if the method returns failure.
fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount, -1, US_INV), pattern, status);
}
}
} // If OOM occurred during the above code, then we want to report that back to the caller. if (ec == U_MEMORY_ALLOCATION_ERROR) {
status = ec;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.