diff --git a/icu4c/source/i18n/rbnf.cpp b/icu4c/source/i18n/rbnf.cpp index 360c07433e..4a6742c661 100644 --- a/icu4c/source/i18n/rbnf.cpp +++ b/icu4c/source/i18n/rbnf.cpp @@ -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 diff --git a/icu4c/source/i18n/unicode/rbnf.h b/icu4c/source/i18n/unicode/rbnf.h index 880c740d81..25b39e23cd 100644 --- a/icu4c/source/i18n/unicode/rbnf.h +++ b/icu4c/source/i18n/unicode/rbnf.h @@ -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; }; // --------------- diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 0ee892fa0c..3a3243d470 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -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));