ICU 78.2 78.2
Loading...
Searching...
No Matches
icu::message2::Formattable Class Reference

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>

Inheritance diagram for icu::message2::Formattable:
icu::UObject icu::UMemory

Public Member Functions

U_I18N_API UFormattableType getType () const
 Gets the data type of this Formattable object.
U_I18N_API double getDouble (UErrorCode &status) const
 Gets the double value of this object.
U_I18N_API int32_t getLong (UErrorCode &status) const
 Gets the long value of this object.
U_I18N_API int64_t getInt64Value (UErrorCode &status) const
 Gets the int64 value of this object.
U_I18N_API int64_t getInt64 (UErrorCode &status) const
 Gets the int64 value of this object.
U_I18N_API const UnicodeStringgetString (UErrorCode &status) const
 Gets the string value of this object.
U_I18N_API const DateInfogetDate (UErrorCode &status) const
 Gets the struct representing the date value of this object.
U_I18N_API UBool isNumeric () const
 Returns true if the data type of this Formattable object is kDouble.
U_I18N_API const FormattablegetArray (int32_t &count, UErrorCode &status) const
 Gets the array value and count of this object.
U_I18N_API const FormattableObjectgetObject (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.
U_I18N_API Formattable (const Formattable &)
 Copy constructor.
U_I18N_API Formattableoperator= (Formattable) noexcept
 Assignment operator.
U_I18N_API Formattable ()
 Default constructor.
U_I18N_API Formattable (const UnicodeString &s)
 String constructor.
U_I18N_API Formattable (double d)
 Double constructor.
U_I18N_API Formattable (int64_t i)
 Int64 constructor.
U_I18N_API Formattable (DateInfo &&d)
 Date constructor.
U_I18N_API Formattable (const Formattable *arr, int32_t len)
 Array constructor.
U_I18N_API Formattable (const FormattableObject *obj)
 Object constructor.
virtual U_I18N_API ~Formattable ()
 Destructor.
U_I18N_API icu::Formattable asICUFormattable (UErrorCode &status) const
 Converts the Formattable object to an ICU Formattable object.
Public Member Functions inherited from icu::UObject
virtual ~UObject ()
 Destructor.
virtual UClassID getDynamicClassID () const
 ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.

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.

Friends

U_I18N_API friend void swap (Formattable &f1, Formattable &f2) noexcept
 Non-member swap function.

Detailed Description

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.)

Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 113 of file messageformat2_formattable.h.

Constructor & Destructor Documentation

◆ Formattable() [1/8]

U_I18N_API icu::message2::Formattable::Formattable ( const Formattable & )

Copy constructor.

Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References Formattable(), and U_I18N_API.

Referenced by forDecimal(), Formattable(), Formattable(), getArray(), operator=(), and swap.

◆ Formattable() [2/8]

U_I18N_API icu::message2::Formattable::Formattable ( )
inline

Default constructor.

Leaves the Formattable in a valid but undefined state.

Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 323 of file messageformat2_formattable.h.

References U_I18N_API.

◆ Formattable() [3/8]

U_I18N_API icu::message2::Formattable::Formattable ( const UnicodeString & s)
inline

String constructor.

Parameters
sA string to wrap as a Formattable.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 332 of file messageformat2_formattable.h.

References U_I18N_API.

◆ Formattable() [4/8]

U_I18N_API icu::message2::Formattable::Formattable ( double d)
inline

Double constructor.

Parameters
dA double value to wrap as a Formattable.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 341 of file messageformat2_formattable.h.

References U_I18N_API.

◆ Formattable() [5/8]

U_I18N_API icu::message2::Formattable::Formattable ( int64_t i)
inline

Int64 constructor.

Parameters
iAn int64 value to wrap as a Formattable.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 350 of file messageformat2_formattable.h.

References U_I18N_API.

◆ Formattable() [6/8]

U_I18N_API icu::message2::Formattable::Formattable ( DateInfo && d)
inline

Date constructor.

Parameters
dA DateInfo struct representing a date, to wrap as a Formattable. Passed by move
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 360 of file messageformat2_formattable.h.

References U_I18N_API.

◆ Formattable() [7/8]

U_I18N_API icu::message2::Formattable::Formattable ( const Formattable * arr,
int32_t len )
inline

Array constructor.

Parameters
arrAn array of Formattables, which is adopted.
lenThe length of the array.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 385 of file messageformat2_formattable.h.

References Formattable(), and U_I18N_API.

◆ Formattable() [8/8]

U_I18N_API icu::message2::Formattable::Formattable ( const FormattableObject * obj)
inline

Object constructor.

Parameters
objA FormattableObject (not adopted).
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 394 of file messageformat2_formattable.h.

References U_I18N_API.

◆ ~Formattable()

virtual U_I18N_API icu::message2::Formattable::~Formattable ( )
virtual

Destructor.

Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References U_I18N_API.

Member Function Documentation

◆ asICUFormattable()

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.

Parameters
statusInput/output error code.
Returns
An icu::Formattable value with the same value as this.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References U_I18N_API.

◆ forDecimal()

U_I18N_API Formattable icu::message2::Formattable::forDecimal ( std::string_view number,
UErrorCode & status )
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.

Parameters
numberthe unformatted (not localized) string representation of the Decimal number.
statusthe error code. Possible errors include U_INVALID_FORMAT_ERROR if the format of the string does not conform to that of a decimal number.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References Formattable(), and U_I18N_API.

◆ getArray()

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.

Parameters
countfill-in with the count of this object.
statusInput/output error code.
Returns
the array value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References Formattable(), and U_I18N_API.

◆ getDate()

U_I18N_API const DateInfo * icu::message2::Formattable::getDate ( UErrorCode & status) const
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.

Parameters
statusInput/output error code.
Returns
A non-owned pointer to a DateInfo object representing the underlying date of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 236 of file messageformat2_formattable.h.

References U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, and U_SUCCESS.

◆ getDouble()

U_I18N_API double icu::message2::Formattable::getDouble ( UErrorCode & status) const
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.

Parameters
statusInput/output error code.
Returns
the double value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 133 of file messageformat2_formattable.h.

References getType(), U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_DOUBLE.

◆ getInt64()

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.

Parameters
statusthe error code
Returns
the int64 value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References U_I18N_API.

◆ getInt64Value()

U_I18N_API int64_t icu::message2::Formattable::getInt64Value ( UErrorCode & status) const
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()

Parameters
statusInput/output error code.
Returns
the int64 value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 178 of file messageformat2_formattable.h.

References getType(), U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_INT64.

◆ getLong()

U_I18N_API int32_t icu::message2::Formattable::getLong ( UErrorCode & status) const
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.

Parameters
statusInput/output error code.
Returns
the long value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 155 of file messageformat2_formattable.h.

References getType(), U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_LONG.

◆ getObject()

U_I18N_API const FormattableObject * icu::message2::Formattable::getObject ( UErrorCode & status) const
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.

Parameters
statusInput/output error code.
Returns
a FormattableObject pointer, or nullptr
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 277 of file messageformat2_formattable.h.

References getType(), U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, U_SUCCESS, and UFMT_OBJECT.

◆ getString()

U_I18N_API const UnicodeString & icu::message2::Formattable::getString ( UErrorCode & status) const
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.

Parameters
statusInput/output error code.
Returns
A reference to the string value of this object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 215 of file messageformat2_formattable.h.

References U_I18N_API, U_ILLEGAL_ARGUMENT_ERROR, and U_SUCCESS.

◆ getType()

U_I18N_API UFormattableType icu::message2::Formattable::getType ( ) const

Gets the data type of this Formattable object.

Returns
the data type of this Formattable object.
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References U_I18N_API.

Referenced by getDouble(), getInt64Value(), getLong(), getObject(), and isNumeric().

◆ isNumeric()

U_I18N_API UBool icu::message2::Formattable::isNumeric ( ) const
inline

Returns true if the data type of this Formattable object is kDouble.

Returns
true if this is a pure numeric object
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 253 of file messageformat2_formattable.h.

References getType(), U_I18N_API, UFMT_DOUBLE, UFMT_INT64, and UFMT_LONG.

◆ operator=()

U_I18N_API Formattable & icu::message2::Formattable::operator= ( Formattable )
noexcept

Assignment operator.

Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

References Formattable(), and U_I18N_API.

◆ swap

U_I18N_API friend void swap ( Formattable & f1,
Formattable & f2 )
friend

Non-member swap function.

Parameters
f1will get f2's contents
f2will get f1's contents
Internal
Do not use. This API is for internal use only. ICU 75 technology preview
Deprecated
This API is for technology preview only.

Definition at line 297 of file messageformat2_formattable.h.

References Formattable(), swap, and U_I18N_API.

Referenced by swap.


The documentation for this class was generated from the following file: