}
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;
}
}
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;
}
}
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;
* 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))
/**
* 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.
* @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.
*
/**
* 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.
* @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.
* @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: