Format or parse a TimeUnitAmount, using plural rules for the units where available. More...
#include <tmutfmt.h>
Public Types | |
enum | EStyle { kFull = 0, kAbbreviate = 1, kTotal = kAbbreviate + 1 } |
Constants for various styles. More... | |
Public Member Functions | |
TimeUnitFormat (UErrorCode &status) | |
Create TimeUnitFormat with default locale, and full name style. | |
TimeUnitFormat (const Locale &locale, UErrorCode &status) | |
Create TimeUnitFormat given locale, and full name style. | |
TimeUnitFormat (const Locale &locale, EStyle style, UErrorCode &status) | |
Create TimeUnitFormat given locale and style. | |
TimeUnitFormat (const TimeUnitFormat &) | |
Copy constructor. | |
virtual | ~TimeUnitFormat () |
deconstructor | |
virtual Format * | clone (void) const |
Clone this Format object polymorphically. | |
TimeUnitFormat & | operator= (const TimeUnitFormat &other) |
Assignment operator. | |
virtual UBool | operator== (const Format &other) const |
Return true if the given Format objects are semantically equal. | |
UBool | operator!= (const Format &other) const |
Return true if the given Format objects are not semantically equal. | |
void | setLocale (const Locale &locale, UErrorCode &status) |
Set the locale used for formatting or parsing. | |
void | setNumberFormat (const NumberFormat &format, UErrorCode &status) |
Set the number format used for formatting or parsing. | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const |
Format a TimeUnitAmount. | |
virtual void | parseObject (const UnicodeString &source, Formattable &result, ParsePosition &pos) const |
Parse a TimeUnitAmount. | |
virtual UClassID | getDynamicClassID (void) const |
Returns a unique class ID POLYMORPHICALLY. | |
Static Public Member Functions | |
static UClassID | getStaticClassID (void) |
Return the class ID for this class. | |
Friends | |
UBool | hashTableValueComparator (UHashTok val1, UHashTok val2) |
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); } }
Definition at line 79 of file tmutfmt.h.
Constants for various styles.
There are 2 styles: full name and abbreviated name. For example, for English, the full name for hour duration is "3 hours", and the abbreviated name is "3 hrs".
TimeUnitFormat::TimeUnitFormat | ( | UErrorCode & | status | ) |
Create TimeUnitFormat with default locale, and full name style.
Use setLocale and/or setFormat to modify.
TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale, | |
UErrorCode & | status | |||
) |
Create TimeUnitFormat given locale, and full name style.
TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale, | |
EStyle | style, | |||
UErrorCode & | status | |||
) |
Create TimeUnitFormat given locale and style.
TimeUnitFormat::TimeUnitFormat | ( | const TimeUnitFormat & | ) |
Copy constructor.
virtual TimeUnitFormat::~TimeUnitFormat | ( | ) | [virtual] |
deconstructor
virtual Format* TimeUnitFormat::clone | ( | void | ) | const [virtual] |
virtual UnicodeString& TimeUnitFormat::format | ( | const Formattable & | obj, | |
UnicodeString & | toAppendTo, | |||
FieldPosition & | pos, | |||
UErrorCode & | status | |||
) | const [virtual] |
virtual UClassID TimeUnitFormat::getDynamicClassID | ( | void | ) | const [virtual] |
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.
Implements Format.
static UClassID TimeUnitFormat::getStaticClassID | ( | void | ) | [static] |
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()) ...
Return true if the given Format objects are not semantically equal.
Objects of different subclasses are considered unequal.
other | the object to be compared with. |
Definition at line 270 of file tmutfmt.h.
References operator==().
TimeUnitFormat& TimeUnitFormat::operator= | ( | const TimeUnitFormat & | other | ) |
Return true if the given Format objects are semantically equal.
Objects of different subclasses are considered unequal.
other | the object to be compared with. |
Referenced by operator!=().
virtual void TimeUnitFormat::parseObject | ( | const UnicodeString & | source, | |
Formattable & | result, | |||
ParsePosition & | pos | |||
) | const [virtual] |
Parse a TimeUnitAmount.
Implements Format.
void 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 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 |
UBool hashTableValueComparator | ( | UHashTok | val1, | |
UHashTok | val2 | |||
) | [friend] |