/*
*******************************************************************************
-* Copyright (C) 2008, International Business Machines Corporation and
+* Copyright (C) 2009, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
pluralRules = other.pluralRules->clone();
pattern = other.pattern;
copyHashtable(other.fParsedValuesHash, status);
+ if (U_FAILURE(status)) {
+ delete pluralRules;
+ pluralRules = NULL;
+ return;
+ }
numberFormat=NumberFormat::createInstance(locale, status);
+ if (U_FAILURE(status)) {
+ delete pluralRules;
+ pluralRules = NULL;
+ delete fParsedValuesHash;
+ fParsedValuesHash = NULL;
+ return;
+ }
replacedNumberFormat=other.replacedNumberFormat;
}
void
PluralFormat::init(const PluralRules* rules, const Locale& curLocale, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
locale = curLocale;
if ( rules==NULL) {
pluralRules = PluralRules::forLocale(locale, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
}
else {
pluralRules = rules->clone();
fParsedValuesHash=NULL;
pattern.remove();
numberFormat= NumberFormat::createInstance(curLocale, status);
+ if (U_FAILURE(status)) {
+ delete pluralRules;
+ pluralRules = NULL;
+ return;
+ }
replacedNumberFormat=NULL;
}
void
PluralFormat::applyPattern(const UnicodeString& newPattern, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
this->pattern = newPattern;
UnicodeString token;
int32_t braceCount=0;
else {
hashPattern = new UnicodeString(token);
fParsedValuesHash->put(hashKeyword, hashPattern, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
braceCount--;
if ( braceCount==0 ) {
getKeyword=TRUE;
UnicodeString
PluralFormat::format(int32_t number, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
FieldPosition fpos(0);
UnicodeString result;
UnicodeString
PluralFormat::format(double number, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
FieldPosition fpos(0);
UnicodeString result;
void
PluralFormat::setLocale(const Locale& loc, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
if (pluralRules!=NULL) {
delete pluralRules;
pluralRules=NULL;
pluralRules = other.pluralRules->clone();
pattern = other.pattern;
copyHashtable(other.fParsedValuesHash, status);
+ if (U_FAILURE(status)) {
+ delete pluralRules;
+ pluralRules = NULL;
+ fParsedValuesHash = NULL;
+ numberFormat = NULL;
+ return *this;
+ }
numberFormat=NumberFormat::createInstance(locale, status);
+ if (U_FAILURE(status)) {
+ delete pluralRules;
+ delete fParsedValuesHash;
+ pluralRules = NULL;
+ fParsedValuesHash = NULL;
+ numberFormat = NULL;
+ return *this;
+ }
replacedNumberFormat=other.replacedNumberFormat;
}
void
PluralFormat::copyHashtable(Hashtable *other, UErrorCode& status) {
- if (other == NULL) {
+ if (other == NULL || U_FAILURE(status)) {
fParsedValuesHash = NULL;
return;
}