ICU-13587 Changing NumberFormatter adoption methods to take non-const pointers, and updating documentation strings according to feedback.

X-SVN-Rev: 40886
This commit is contained in:
Shane Carr 2018-02-09 22:52:42 +00:00
parent cf95e1ec2e
commit c8d0e34905
2 changed files with 24 additions and 16 deletions

View 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;

View 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: