ICU-10682 Fix clone, copy constructor, and assignment operator in RulesBasedNumberFormat.

X-SVN-Rev: 35085
This commit is contained in:
Travis Keep 2014-02-06 00:34:24 +00:00
parent c7519ed407
commit 25c7ba8e57
3 changed files with 14 additions and 22 deletions

View File

@ -815,15 +815,19 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs)
RuleBasedNumberFormat&
RuleBasedNumberFormat::operator=(const RuleBasedNumberFormat& rhs)
{
if (this == &rhs) {
return *this;
}
NumberFormat::operator=(rhs);
UErrorCode status = U_ZERO_ERROR;
dispose();
locale = rhs.locale;
lenient = rhs.lenient;
UnicodeString rules = rhs.getRules();
UParseError perror;
init(rules, rhs.localizations ? rhs.localizations->ref() : NULL, perror, status);
init(rhs.originalDescription, rhs.localizations ? rhs.localizations->ref() : NULL, perror, status);
setDecimalFormatSymbols(*rhs.getDecimalFormatSymbols());
setDefaultRuleSet(rhs.getDefaultRuleSetName(), status);
return *this;
}
@ -835,23 +839,7 @@ RuleBasedNumberFormat::~RuleBasedNumberFormat()
Format*
RuleBasedNumberFormat::clone(void) const
{
RuleBasedNumberFormat * result = NULL;
UnicodeString rules = getRules();
UErrorCode status = U_ZERO_ERROR;
UParseError perror;
result = new RuleBasedNumberFormat(rules, localizations, locale, perror, status);
/* test for NULL */
if (result == 0) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (U_FAILURE(status)) {
delete result;
result = 0;
} else {
result->lenient = lenient;
}
return result;
return new RuleBasedNumberFormat(*this);
}
UBool
@ -1431,6 +1419,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* locali
} else {
defaultRuleSet = getDefaultRuleSet();
}
originalDescription = rules;
}
void

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2013, International Business Machines Corporation and others.
* Copyright (C) 1997-2014, International Business Machines Corporation and others.
* All Rights Reserved.
*******************************************************************************
*/
@ -965,6 +965,7 @@ private:
UBool lenient;
UnicodeString* lenientParseRules;
LocalizationInfo* localizations;
UnicodeString originalDescription;
};
// ---------------

View File

@ -3133,7 +3133,9 @@ void NumberFormatTest::TestNumberingSystems() {
for (item = DATA; item->localeName != NULL; item++) {
ec = U_ZERO_ERROR;
Locale loc = Locale::createFromName(item->localeName);
NumberFormat *fmt = NumberFormat::createInstance(loc,ec);
// Clone to test ticket #10682
NumberFormat *fmt = (NumberFormat *) NumberFormat::createInstance(loc,ec)->clone();
if (U_FAILURE(ec)) {
dataerrln("FAIL: getInstance(%s) - %s", item->localeName, u_errorName(ec));