+/**
+ * Returns the DecimalFormatSymbols object that should be used by all DecimalFormat
+ * instances owned by this formatter.
+*/
+const DecimalFormatSymbols*
+RuleBasedNumberFormat::getDecimalFormatSymbols() const
+{
+ return decimalFormatSymbols;
+}
+
+NFRule*
+RuleBasedNumberFormat::initializeDefaultInfinityRule(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (defaultInfinityRule == NULL) {
+ UnicodeString rule(UNICODE_STRING_SIMPLE("Inf: "));
+ rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kInfinitySymbol));
+ LocalPointer<NFRule> temp(new NFRule(this, rule, status), status);
+ if (U_SUCCESS(status)) {
+ defaultInfinityRule = temp.orphan();
+ }
+ }
+ return defaultInfinityRule;
+}
+
+const NFRule*
+RuleBasedNumberFormat::getDefaultInfinityRule() const
+{
+ return defaultInfinityRule;
+}
+
+NFRule*
+RuleBasedNumberFormat::initializeDefaultNaNRule(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (defaultNaNRule == nullptr) {
+ UnicodeString rule(UNICODE_STRING_SIMPLE("NaN: "));
+ rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kNaNSymbol));
+ LocalPointer<NFRule> temp(new NFRule(this, rule, status), status);
+ if (U_SUCCESS(status)) {
+ defaultNaNRule = temp.orphan();
+ }
+ }
+ return defaultNaNRule;
+}
+
+const NFRule*
+RuleBasedNumberFormat::getDefaultNaNRule() const
+{
+ return defaultNaNRule;
+}
+
+// De-owning the current localized symbols and adopt the new symbols.
+void
+RuleBasedNumberFormat::adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt)
+{
+ if (symbolsToAdopt == NULL) {
+ return; // do not allow caller to set decimalFormatSymbols to NULL
+ }
+
+ if (decimalFormatSymbols != NULL) {
+ delete decimalFormatSymbols;
+ }
+
+ decimalFormatSymbols = symbolsToAdopt;
+
+ {
+ // Apply the new decimalFormatSymbols by reparsing the rulesets
+ UErrorCode status = U_ZERO_ERROR;
+
+ delete defaultInfinityRule;
+ defaultInfinityRule = NULL;
+ initializeDefaultInfinityRule(status); // Reset with the new DecimalFormatSymbols
+
+ delete defaultNaNRule;
+ defaultNaNRule = NULL;
+ initializeDefaultNaNRule(status); // Reset with the new DecimalFormatSymbols
+
+ if (fRuleSets) {
+ for (int32_t i = 0; i < numRuleSets; i++) {
+ fRuleSets[i]->setDecimalFormatSymbols(*symbolsToAdopt, status);
+ }
+ }
+ }
+}
+
+// Setting the symbols is equivalent to adopting a newly created localized symbols.
+void
+RuleBasedNumberFormat::setDecimalFormatSymbols(const DecimalFormatSymbols& symbols)
+{
+ adoptDecimalFormatSymbols(new DecimalFormatSymbols(symbols));
+}
+
+PluralFormat *
+RuleBasedNumberFormat::createPluralFormat(UPluralType pluralType,
+ const UnicodeString &pattern,
+ UErrorCode& status) const
+{
+ auto *pf = new PluralFormat(locale, pluralType, pattern, status);
+ if (pf == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return pf;
+}
+
+/**
+ * Get the rounding mode.
+ * @return A rounding mode
+ */
+DecimalFormat::ERoundingMode RuleBasedNumberFormat::getRoundingMode() const {
+ return fRoundingMode;
+}
+
+/**
+ * Set the rounding mode. This has no effect unless the rounding
+ * increment is greater than zero.
+ * @param roundingMode A rounding mode
+ */
+void RuleBasedNumberFormat::setRoundingMode(DecimalFormat::ERoundingMode roundingMode) {
+ fRoundingMode = roundingMode;
+}
+