]> granicus.if.org Git - icu/commitdiff
ICU-13587 Changing NumberFormatter adoption methods to take non-const pointers, and...
authorShane Carr <shane@unicode.org>
Fri, 9 Feb 2018 22:52:42 +0000 (22:52 +0000)
committerShane Carr <shane@unicode.org>
Fri, 9 Feb 2018 22:52:42 +0000 (22:52 +0000)
X-SVN-Rev: 40886

icu4c/source/i18n/number_fluent.cpp
icu4c/source/i18n/unicode/numberformatter.h

index 3be3401ef3a28d5e76ef7973fbea6ed495dd589e..27113106c5045117efdc9eb1d4a5e3a467df1d94 100644 (file)
@@ -33,12 +33,13 @@ Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit &unit) con
 }
 
 template<typename Derived>
-Derived NumberFormatterSettings<Derived>::adoptUnit(const icu::MeasureUnit *unit) const {
+Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit *unit) const {
     Derived copy(*this);
     // Just copy the unit into the MacroProps by value, and delete it since we have ownership.
     // NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit.
     // TimeUnit may be affected, but TimeUnit is not as relevant to number formatting.
     if (unit != nullptr) {
+      // TODO: On nullptr, reset to default value?
         copy.fMacros.unit = *unit;
         delete unit;
     }
@@ -54,10 +55,11 @@ Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit &perUni
 }
 
 template<typename Derived>
-Derived NumberFormatterSettings<Derived>::adoptPerUnit(const icu::MeasureUnit *perUnit) const {
+Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit *perUnit) const {
     Derived copy(*this);
     // See comments above about slicing and ownership.
     if (perUnit != nullptr) {
+      // TODO: On nullptr, reset to default value?
         copy.fMacros.perUnit = *perUnit;
         delete perUnit;
     }
@@ -96,7 +98,7 @@ Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols &sy
 }
 
 template<typename Derived>
-Derived NumberFormatterSettings<Derived>::adoptSymbols(const NumberingSystem *ns) const {
+Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem *ns) const {
     Derived copy(*this);
     copy.fMacros.symbols.setTo(ns);
     return copy;
index ac852f27e8eda9cb1124a1a74fee2319c2a8e833..d2c70a990559385dadce5439272b01f41b13ca01 100644 (file)
@@ -1515,7 +1515,8 @@ class U_I18N_API NumberFormatterSettings {
      * All units will be properly localized with locale data, and all units are compatible with notation styles,
      * rounding strategies, and other number formatter settings.
      *
-     * Pass this method any instance of {@link MeasureUnit}. For units of measure:
+     * Pass this method any instance of {@link MeasureUnit}. For units of measure (which often involve the
+     * factory methods that return a pointer):
      *
      * <pre>
      * NumberFormatter::with().adoptUnit(MeasureUnit::createMeter(status))
@@ -1550,7 +1551,11 @@ class U_I18N_API NumberFormatterSettings {
 
     /**
      * Like unit(), but takes ownership of a pointer.  Convenient for use with the MeasureFormat factory
-     * methods, which return pointers that need ownership.
+     * methods, which return pointers that need ownership.  Example:
+     *
+     * <pre>
+     * NumberFormatter::with().adoptUnit(MeasureUnit::createMeter(status))
+     * </pre>
      *
      * @param unit
      *            The unit to render.
@@ -1559,19 +1564,14 @@ class U_I18N_API NumberFormatterSettings {
      * @see MeasureUnit
      * @draft ICU 60
      */
-    Derived adoptUnit(const icu::MeasureUnit *unit) const;
+    Derived adoptUnit(icu::MeasureUnit *unit) const;
 
     /**
      * Sets a unit to be used in the denominator. For example, to format "3 m/s", pass METER to the unit and SECOND to
      * the perUnit.
      *
-     * Pass this method any instance of {@link MeasureUnit}. For example:
-     *
-     * <pre>
-     * NumberFormatter::with()
-     *      .adoptUnit(MeasureUnit::createMeter(status))
-     *      .adoptPerUnit(MeasureUnit::createSecond(status))
-     * </pre>
+     * Pass this method any instance of {@link MeasureUnit}.  Since MeasureUnit factory methods return pointers, the
+     * {@link #adoptPerUnit} version of this method is often more useful.
      *
      * The default is not to display any unit in the denominator.
      *
@@ -1587,7 +1587,13 @@ class U_I18N_API NumberFormatterSettings {
 
     /**
      * Like perUnit(), but takes ownership of a pointer.  Convenient for use with the MeasureFormat factory
-     * methods, which return pointers that need ownership.
+     * methods, which return pointers that need ownership.  Example:
+     *
+     * <pre>
+     * NumberFormatter::with()
+     *      .adoptUnit(MeasureUnit::createMeter(status))
+     *      .adoptPerUnit(MeasureUnit::createSecond(status))
+     * </pre>
      *
      * @param perUnit
      *            The unit to render in the denominator.
@@ -1596,7 +1602,7 @@ class U_I18N_API NumberFormatterSettings {
      * @see MeasureUnit
      * @draft ICU 61
      */
-    Derived adoptPerUnit(const icu::MeasureUnit *perUnit) const;
+    Derived adoptPerUnit(icu::MeasureUnit *perUnit) const;
 
     /**
      * Specifies the rounding strategy to use when formatting numbers.
@@ -1761,7 +1767,7 @@ class U_I18N_API NumberFormatterSettings {
      * @see NumberingSystem
      * @draft ICU 60
      */
-    Derived adoptSymbols(const NumberingSystem *symbols) const;
+    Derived adoptSymbols(NumberingSystem *symbols) const;
 
     /**
      * Sets the width of the unit (measure unit or currency).  Most common values: