ICU 78.1
78.1
|
The Formattable
class represents a typed value that can be formatted, originating either from a message argument or a literal in the code.
More...
#include <messageformat2_formattable.h>
Public Member Functions | |
U_I18N_API UFormattableType | getType () const |
Gets the data type of this Formattable object. More... | |
U_I18N_API double | getDouble (UErrorCode &status) const |
Gets the double value of this object. More... | |
U_I18N_API int32_t | getLong (UErrorCode &status) const |
Gets the long value of this object. More... | |
U_I18N_API int64_t | getInt64Value (UErrorCode &status) const |
Gets the int64 value of this object. More... | |
U_I18N_API int64_t | getInt64 (UErrorCode &status) const |
Gets the int64 value of this object. More... | |
U_I18N_API const UnicodeString & | getString (UErrorCode &status) const |
Gets the string value of this object. More... | |
U_I18N_API const DateInfo * | getDate (UErrorCode &status) const |
Gets the struct representing the date value of this object. More... | |
U_I18N_API UBool | isNumeric () const |
Returns true if the data type of this Formattable object is kDouble. More... | |
U_I18N_API const Formattable * | getArray (int32_t &count, UErrorCode &status) const |
Gets the array value and count of this object. More... | |
U_I18N_API const FormattableObject * | getObject (UErrorCode &status) const |
Returns a pointer to the FormattableObject contained within this formattable, or if this object does not contain a FormattableObject, returns nullptr and sets the error code. More... | |
U_I18N_API | Formattable (const Formattable &) |
Copy constructor. More... | |
U_I18N_API Formattable & | operator= (Formattable) noexcept |
Assignment operator. More... | |
U_I18N_API | Formattable () |
Default constructor. More... | |
U_I18N_API | Formattable (const UnicodeString &s) |
String constructor. More... | |
U_I18N_API | Formattable (double d) |
Double constructor. More... | |
U_I18N_API | Formattable (int64_t i) |
Int64 constructor. More... | |
U_I18N_API | Formattable (DateInfo &&d) |
Date constructor. More... | |
U_I18N_API | Formattable (const Formattable *arr, int32_t len) |
Array constructor. More... | |
U_I18N_API | Formattable (const FormattableObject *obj) |
Object constructor. More... | |
virtual U_I18N_API | ~Formattable () |
Destructor. More... | |
U_I18N_API icu::Formattable | asICUFormattable (UErrorCode &status) const |
Converts the Formattable object to an ICU Formattable object. More... | |
![]() | |
virtual | ~UObject () |
Destructor. More... | |
virtual UClassID | getDynamicClassID () const |
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More... | |
Static Public Member Functions | |
static U_I18N_API Formattable | forDecimal (std::string_view number, UErrorCode &status) |
Creates a Formattable object of an appropriate numeric type from a a decimal number in string form. More... | |
Friends | |
U_I18N_API friend void | swap (Formattable &f1, Formattable &f2) noexcept |
Non-member swap function. More... | |
The Formattable
class represents a typed value that can be formatted, originating either from a message argument or a literal in the code.
ICU's Formattable class is not used in MessageFormat 2 because it's unsafe to copy an icu::Formattable value that contains an object. (See ICU-20275).
Formattable
is immutable (not deeply immutable) and is movable and copyable. (Copying does not do a deep copy when the wrapped value is an array or object. Likewise, while a pointer to a wrapped array or object is const
, the referents of the pointers may be mutated by other code.)
Definition at line 113 of file messageformat2_formattable.h.
U_I18N_API icu::message2::Formattable::Formattable | ( | const Formattable & | ) |
Copy constructor.
|
inline |
Default constructor.
Leaves the Formattable in a valid but undefined state.
Definition at line 323 of file messageformat2_formattable.h.
|
inline |
String constructor.
s | A string to wrap as a Formattable. |
Definition at line 332 of file messageformat2_formattable.h.
|
inline |
Double constructor.
d | A double value to wrap as a Formattable. |
Definition at line 341 of file messageformat2_formattable.h.
|
inline |
Int64 constructor.
i | An int64 value to wrap as a Formattable. |
Definition at line 350 of file messageformat2_formattable.h.
|
inline |
Date constructor.
d | A DateInfo struct representing a date, to wrap as a Formattable. Passed by move |
Definition at line 360 of file messageformat2_formattable.h.
|
inline |
Array constructor.
arr | An array of Formattables, which is adopted. |
len | The length of the array. |
Definition at line 385 of file messageformat2_formattable.h.
|
inline |
Object constructor.
obj | A FormattableObject (not adopted). |
Definition at line 394 of file messageformat2_formattable.h.
|
virtual |
Destructor.
U_I18N_API icu::Formattable icu::message2::Formattable::asICUFormattable | ( | UErrorCode & | status | ) | const |
Converts the Formattable object to an ICU Formattable object.
If this has type UFMT_OBJECT or kArray, then status
is set to U_ILLEGAL_ARGUMENT_ERROR.
status | Input/output error code. |
|
static |
Creates a Formattable object of an appropriate numeric type from a a decimal number in string form.
The Formattable will retain the full precision of the input in decimal format, even when it exceeds what can be represented by a double or int64_t.
number | the unformatted (not localized) string representation of the Decimal number. |
status | the error code. Possible errors include U_INVALID_FORMAT_ERROR if the format of the string does not conform to that of a decimal number. |
U_I18N_API const Formattable* icu::message2::Formattable::getArray | ( | int32_t & | count, |
UErrorCode & | status | ||
) | const |
Gets the array value and count of this object.
If this object is not of type kArray then the result is undefined and the error code is set.
count | fill-in with the count of this object. |
status | Input/output error code. |
|
inline |
Gets the struct representing the date value of this object.
If this object is not of type kDate then the result is undefined and the error code is set.
status | Input/output error code. |
Definition at line 236 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, and U_SUCCESS.
|
inline |
Gets the double value of this object.
If this object is not of type UFMT_DOUBLE, then the result is undefined and the error code is set.
status | Input/output error code. |
Definition at line 133 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_DOUBLE.
U_I18N_API int64_t icu::message2::Formattable::getInt64 | ( | UErrorCode & | status | ) | const |
Gets the int64 value of this object.
If this object is of a numeric type and the magnitude is too large to fit in an int64, then the maximum or minimum int64 value, as appropriate, is returned and the status is set to U_INVALID_FORMAT_ERROR. If the magnitude fits in an int64, then a casting conversion is performed, with truncation of any fractional part. If this object is not a numeric type, then 0 is returned and the status is set to U_INVALID_FORMAT_ERROR.
status | the error code |
|
inline |
Gets the int64 value of this object.
If this object is not of type kInt64 then the result is undefined and the error code is set. If conversion to int64 is desired, call getInt64()
status | Input/output error code. |
Definition at line 178 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_INT64.
|
inline |
Gets the long value of this object.
If this object is not of type UFMT_LONG then the result is undefined and the error code is set.
status | Input/output error code. |
Definition at line 155 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_LONG.
|
inline |
Returns a pointer to the FormattableObject contained within this formattable, or if this object does not contain a FormattableObject, returns nullptr and sets the error code.
status | Input/output error code. |
Definition at line 277 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_OBJECT.
|
inline |
Gets the string value of this object.
If this object is not of type kString then the result is undefined and the error code is set.
status | Input/output error code. |
Definition at line 215 of file messageformat2_formattable.h.
References U_ILLEGAL_ARGUMENT_ERROR, and U_SUCCESS.
U_I18N_API UFormattableType icu::message2::Formattable::getType | ( | ) | const |
Gets the data type of this Formattable object.
|
inline |
Returns true if the data type of this Formattable object is kDouble.
Definition at line 253 of file messageformat2_formattable.h.
References UFMT_DOUBLE, UFMT_INT64, and UFMT_LONG.
|
noexcept |
Assignment operator.
|
friend |
Non-member swap function.
f1 | will get f2's contents |
f2 | will get f1's contents |
Definition at line 297 of file messageformat2_formattable.h.