IMPORTANT: New users are strongly encouraged to see if * numberformatter.h fits their use case. Although not deprecated, this header * is provided for backwards compatibility only. * * @see Format * @author Alan Liu * @stable ICU 3.0 */ class U_I18N_API MeasureFormat : public Format { public: using Format::parseObject; using Format::format; /** * Constructor. *
* NOTE: New users are strongly encouraged to use * {@link icu::number::NumberFormatter} instead of NumberFormat. * @stable ICU 53 */ MeasureFormat( const Locale &locale, UMeasureFormatWidth width, UErrorCode &status); /** * Constructor. *
* NOTE: New users are strongly encouraged to use * {@link icu::number::NumberFormatter} instead of NumberFormat. * @stable ICU 53 */ MeasureFormat( const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status); /** * Copy constructor. * @stable ICU 3.0 */ MeasureFormat(const MeasureFormat &other); /** * Assignment operator. * @stable ICU 3.0 */ MeasureFormat &operator=(const MeasureFormat &rhs); /** * Destructor. * @stable ICU 3.0 */ virtual ~MeasureFormat(); /** * Return true if given Format objects are semantically equal. * @stable ICU 53 */ virtual UBool operator==(const Format &other) const; /** * Clones this object polymorphically. * @stable ICU 53 */ virtual MeasureFormat *clone() const; /** * Formats object to produce a string. * @stable ICU 53 */ virtual UnicodeString &format( const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const; #ifndef U_FORCE_HIDE_DRAFT_API /** * Parse a string to produce an object. This implementation sets * status to U_UNSUPPORTED_ERROR. * * @draft ICU 53 */ virtual void parseObject( const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const; #endif // U_FORCE_HIDE_DRAFT_API /** * Formats measure objects to produce a string. An example of such a * formatted string is 3 meters, 3.5 centimeters. Measure objects appear * in the formatted string in the same order they appear in the "measures" * array. The NumberFormat of this object is used only to format the amount * of the very last measure. The other amounts are formatted with zero * decimal places while rounding toward zero. * @param measures array of measure objects. * @param measureCount the number of measure objects. * @param appendTo formatted string appended here. * @param pos the field position. * @param status the error. * @return appendTo reference * * @stable ICU 53 */ UnicodeString &formatMeasures( const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const; /** * Formats a single measure per unit. An example of such a * formatted string is 3.5 meters per second. * @param measure The measure object. In above example, 3.5 meters. * @param perUnit The per unit. In above example, it is * `*%MeasureUnit::createSecond(status)`. * @param appendTo formatted string appended here. * @param pos the field position. * @param status the error. * @return appendTo reference * * @stable ICU 55 */ UnicodeString &formatMeasurePerUnit( const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const; /** * Gets the display name of the specified {@link MeasureUnit} corresponding to the current * locale and format width. * @param unit The unit for which to get a display name. * @param status the error. * @return The display name in the locale and width specified in * the MeasureFormat constructor, or null if there is no display name available * for the specified unit. * * @stable ICU 58 */ UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const; /** * Return a formatter for CurrencyAmount objects in the given * locale. *
* NOTE: New users are strongly encouraged to use * {@link icu::number::NumberFormatter} instead of NumberFormat. * @param locale desired locale * @param ec input-output error code * @return a formatter object, or NULL upon error * @stable ICU 3.0 */ static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale, UErrorCode& ec); /** * Return a formatter for CurrencyAmount objects in the default * locale. *
* NOTE: New users are strongly encouraged to use * {@link icu::number::NumberFormatter} instead of NumberFormat. * @param ec input-output error code * @return a formatter object, or NULL upon error * @stable ICU 3.0 */ static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec); /** * Return the class ID for this class. This is useful only for comparing to * a return value from getDynamicClassID(). For example: *
* . Base* polymorphic_pointer = createPolymorphicObject(); * . if (polymorphic_pointer->getDynamicClassID() == * . erived::getStaticClassID()) ... *