ICU 75.1 75.1
|
Format or parse a TimeUnitAmount, using plural rules for the units where available. More...
#include <tmutfmt.h>
Static Public Member Functions | |
static UClassID | getStaticClassID () |
Return the class ID for this class. | |
Static Public Member Functions inherited from icu::MeasureFormat | |
static MeasureFormat * | createCurrencyFormat (const Locale &locale, UErrorCode &ec) |
Return a formatter for CurrencyAmount objects in the given locale. | |
static MeasureFormat * | createCurrencyFormat (UErrorCode &ec) |
Return a formatter for CurrencyAmount objects in the default locale. | |
static UClassID | getStaticClassID () |
Return the class ID for this class. | |
Friends | |
struct | TimeUnitFormatReadSink |
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Code Sample:
// create time unit amount instance - a combination of Number and time unit UErrorCode status = U_ZERO_ERROR; TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status); // create time unit format instance TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status); // format a time unit amount UnicodeString formatted; Formattable formattable; if (U_SUCCESS(status)) { formattable.adoptObject(source); formatted = ((Format*)format)->format(formattable, formatted, status); Formattable result; ((Format*)format)->parseObject(formatted, result, status); if (U_SUCCESS(status)) { assert (result == formattable); } }
icu::TimeUnitFormat::TimeUnitFormat | ( | UErrorCode & | status | ) |
Create TimeUnitFormat with default locale, and full name style.
Use setLocale and/or setFormat to modify.
icu::TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale, |
UErrorCode & | status | ||
) |
Create TimeUnitFormat given locale, and full name style.
icu::TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale, |
UTimeUnitFormatStyle | style, | ||
UErrorCode & | status | ||
) |
Create TimeUnitFormat given locale and style.
icu::TimeUnitFormat::TimeUnitFormat | ( | const TimeUnitFormat & | ) |
Copy constructor.
|
virtual |
deconstructor
|
overridevirtual |
Clone this Format object polymorphically.
The caller owns the result and should delete it when done.
Reimplemented from icu::MeasureFormat.
Returns a unique class ID POLYMORPHICALLY.
Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.
Reimplemented from icu::MeasureFormat.
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()) ...
TimeUnitFormat & icu::TimeUnitFormat::operator= | ( | const TimeUnitFormat & | other | ) |
Assignment operator.
|
overridevirtual |
void icu::TimeUnitFormat::setLocale | ( | const Locale & | locale, |
UErrorCode & | status | ||
) |
Set the locale used for formatting or parsing.
locale | the locale to be set |
status | output param set to success/failure code on exit |
void icu::TimeUnitFormat::setNumberFormat | ( | const NumberFormat & | format, |
UErrorCode & | status | ||
) |
Set the number format used for formatting or parsing.
format | the number formatter to be set |
status | output param set to success/failure code on exit |