]> granicus.if.org Git - icu/commitdiff
ICU-13306 Move rounding mode API to superclass as per technical committee review...
authorGeorge Rhoten <grhoten@users.noreply.github.com>
Wed, 23 Aug 2017 17:38:00 +0000 (17:38 +0000)
committerGeorge Rhoten <grhoten@users.noreply.github.com>
Wed, 23 Aug 2017 17:38:00 +0000 (17:38 +0000)
X-SVN-Rev: 40347

icu4c/source/i18n/numfmt.cpp
icu4c/source/i18n/unicode/decimfmt.h
icu4c/source/i18n/unicode/numfmt.h
icu4c/source/i18n/unicode/rbnf.h
icu4c/source/i18n/unum.cpp

index ea9aed1a359cde0b2cdc13a688724d1995454d58..8ed71a580e111bfb18869c47aeb12c251ed99f4b 100644 (file)
@@ -1509,6 +1509,24 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
     return f;
 }
 
+/**
+ * Get the rounding mode.
+ * @return A rounding mode
+ */
+NumberFormat::ERoundingMode NumberFormat::getRoundingMode() const {
+    // Default value. ICU4J throws an exception and we can't change this API.
+    return NumberFormat::ERoundingMode::kRoundUnnecessary;
+}
+
+/**
+ * Set the rounding mode.  This has no effect unless the rounding
+ * increment is greater than zero.
+ * @param roundingMode A rounding mode
+ */
+void NumberFormat::setRoundingMode(NumberFormat::ERoundingMode /*roundingMode*/) {
+    // No-op ICU4J throws an exception, and we can't change this API.
+}
+
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
index 1deff5bf921c87cdde9b5ab758d00408eadc4846..bd8d2ab2bab4c8da2b610ca2a5d0493c81430565 100644 (file)
@@ -668,28 +668,6 @@ template class U_I18N_API    EnumSet<UNumberFormatAttribute,
  */
 class U_I18N_API DecimalFormat: public NumberFormat {
 public:
-    /**
-     * Rounding mode.
-     * @stable ICU 2.4
-     */
-    enum ERoundingMode {
-        kRoundCeiling,  /**< Round towards positive infinity */
-        kRoundFloor,    /**< Round towards negative infinity */
-        kRoundDown,     /**< Round towards zero */
-        kRoundUp,       /**< Round away from zero */
-        kRoundHalfEven, /**< Round towards the nearest integer, or
-                             towards the nearest even integer if equidistant */
-        kRoundHalfDown, /**< Round towards the nearest integer, or
-                             towards zero if equidistant */
-        kRoundHalfUp,   /**< Round towards the nearest integer, or
-                             away from zero if equidistant */
-        /**
-          *  Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
-          *  @stable ICU 4.8
-          */
-        kRoundUnnecessary
-    };
-
     /**
      * Pad position.
      * @stable ICU 2.4
index b8dec36be644eb6b73c2433617691b1495f099cc..9aaff0c7b8bd92dabef7f42d00876d5f757d8501 100644 (file)
@@ -168,6 +168,28 @@ class StringEnumeration;
  */
 class U_I18N_API NumberFormat : public Format {
 public:
+    /**
+     * Rounding mode.
+     * @stable ICU 2.4
+     */
+    enum ERoundingMode {
+        kRoundCeiling,  /**< Round towards positive infinity */
+        kRoundFloor,    /**< Round towards negative infinity */
+        kRoundDown,     /**< Round towards zero */
+        kRoundUp,       /**< Round away from zero */
+        kRoundHalfEven, /**< Round towards the nearest integer, or
+                             towards the nearest even integer if equidistant */
+        kRoundHalfDown, /**< Round towards the nearest integer, or
+                             towards zero if equidistant */
+        kRoundHalfUp,   /**< Round towards the nearest integer, or
+                             away from zero if equidistant */
+        /**
+          *  Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
+          *  @stable ICU 4.8
+          */
+        kRoundUnnecessary
+    };
+
     /**
      * Alignment Field constants used to construct a FieldPosition object.
      * Signifies that the position of the integer part or fraction part of
@@ -965,6 +987,21 @@ public:
      */
     virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
 
+    /**
+     * Get the rounding mode. This will always return NumberFormat::ERoundingMode::kRoundUnnecessary
+     * if the subclass does not support rounding. 
+     * @return A rounding mode
+     * @draft ICU 60
+     */
+    virtual ERoundingMode getRoundingMode(void) const;
+
+    /**
+     * Set the rounding mode. If a subclass does not support rounding, this will do nothing.
+     * @param roundingMode A rounding mode
+     * @draft ICU 60
+     */
+    virtual void setRoundingMode(ERoundingMode roundingMode);
+
 public:
 
     /**
index 98e786008f336a97291e3d538677bf6f2fd448d2..5ef662ec62c71bf13f908427b8ae865182a3a288 100644 (file)
@@ -1011,7 +1011,6 @@ public:
    */
   virtual void setContext(UDisplayContext value, UErrorCode& status);
 
-#ifndef U_HIDE_DRAFT_API
     /**
      * Get the rounding mode.
      * @return A rounding mode
@@ -1025,7 +1024,6 @@ public:
      * @draft ICU 60
      */
     virtual void setRoundingMode(DecimalFormat::ERoundingMode roundingMode);
-#endif  /* U_HIDE_DRAFT_API */
 
 public:
     /**
index 23861d375f78081e8eb6b020039b1d6bd3515323..c0bb9cbf4014753067abd511f1987023e1873656 100644 (file)
@@ -532,22 +532,17 @@ unum_getAttribute(const UNumberFormat*          fmt,
         // TODO: what should this return?
         return nf->getMinimumFractionDigits();
     }
+    else if (attr == UNUM_ROUNDING_MODE) {
+        return nf->getRoundingMode();
+    }
 
-    // DecimalFormat specific attributes
+    // The remaining attributes are only supported for DecimalFormat
     const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
     if (df != NULL) {
         UErrorCode ignoredStatus = U_ZERO_ERROR;
         return df->getAttribute(attr, ignoredStatus);
     }
 
-    // RuleBasedNumberFormat specific attributes
-    const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(nf);
-    if (rbnf != NULL) {
-        if (attr == UNUM_ROUNDING_MODE) {
-            return rbnf->getRoundingMode();
-        }
-    }
-
     return -1;
 }
 
@@ -582,21 +577,16 @@ unum_setAttribute(    UNumberFormat*          fmt,
         nf->setMinimumFractionDigits(newValue);
         return nf->setMaximumFractionDigits(newValue);
     }
+    else if (attr == UNUM_ROUNDING_MODE) {
+        return nf->setRoundingMode((NumberFormat::ERoundingMode)newValue);
+    }
 
-    // DecimalFormat specific attributes
+    // The remaining attributes are only supported for DecimalFormat
     DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
     if (df != NULL) {
         UErrorCode ignoredStatus = U_ZERO_ERROR;
         df->setAttribute(attr, newValue, ignoredStatus);
     }
-
-    // RuleBasedNumberFormat specific attributes
-    RuleBasedNumberFormat* rbnf = dynamic_cast<RuleBasedNumberFormat*>(nf);
-    if (rbnf != NULL) {
-        if (attr == UNUM_ROUNDING_MODE) {
-            return rbnf->setRoundingMode((DecimalFormat::ERoundingMode)newValue);
-        }
-    }
 }
 
 U_CAPI double U_EXPORT2