class Formattable

Defined at line 63 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

Formattable objects can be passed to the Format class or

its subclasses for formatting. Formattable is a thin wrapper

class which interconverts between the primitive numeric types

(double, long, etc.) as well as UDate and UnicodeString.

Internally, a Formattable object is a union of primitive types.

As such, it can only store one flavor of data at a time. To

determine what flavor of data it contains, use the getType method.

As of ICU 3.0, Formattable may also wrap a UObject pointer,

which it owns. This allows an instance of any ICU class to be

encapsulated in a Formattable. For legacy reasons and for

efficiency, primitive numeric types are still stored directly

within a Formattable.

The Formattable class is not suitable for subclassing.

See UFormattable for a C wrapper.

Public Methods

void Formattable ()

Default constructor

ICU 2.4

void Formattable (UDate d, ISDATE flag)

Creates a Formattable object with a UDate instance.

Parameters

d the UDate instance.
flag the flag to indicate this is a date. Always set it to kIsDate ICU 2.0
void Formattable (double d)

Creates a Formattable object with a double number.

Parameters

d the double number. ICU 2.0
void Formattable (int32_t l)

Creates a Formattable object with a long number.

Parameters

l the long number. ICU 2.0
void Formattable (int64_t ll)

Creates a Formattable object with an int64_t number

Parameters

ll the int64_t number. ICU 2.8
void Formattable (const char * strToCopy)

Creates a Formattable object with a char string pointer.

Assumes that the char string is null terminated.

Parameters

strToCopy the char string. ICU 2.0
void Formattable (StringPiece number, UErrorCode & status)

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

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. ICU 4.4
void Formattable (const UnicodeString & strToCopy)

Creates a Formattable object with a UnicodeString object to copy from.

Parameters

strToCopy the UnicodeString string. ICU 2.0
void Formattable (UnicodeString * strToAdopt)

Creates a Formattable object with a UnicodeString object to adopt from.

Parameters

strToAdopt the UnicodeString string. ICU 2.0
void Formattable (const Formattable * arrayToCopy, int32_t count)

Creates a Formattable object with an array of Formattable objects.

Parameters

arrayToCopy the Formattable object array.
count the array count. ICU 2.0
void Formattable (UObject * objectToAdopt)

Creates a Formattable object that adopts the given UObject.

Parameters

objectToAdopt the UObject to set this object to ICU 3.0
void Formattable (const Formattable & )

Copy constructor.

ICU 2.0

Formattable * clone ()

Clone this object.

Clones can be used concurrently in multiple threads.

If an error occurs, then nullptr is returned.

The caller must delete the clone.

Returns

a clone of this object

bool operator!= (const Formattable & other)

Equality operator.

Parameters

other the object to be compared with.

Returns

true if other are unequal to this, false otherwise.

ICU 2.0

Defined at line 192 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

double getDouble ()

Gets the double value of this object. If this object is not of type

kDouble then the result is undefined.

Returns

the double value of this object.

ICU 2.0

Defined at line 292 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

int32_t getLong ()

Gets the long value of this object. If this object is not of type

kLong then the result is undefined.

Returns

the long value of this object.

ICU 2.0

Defined at line 314 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

int64_t getInt64 ()

Gets the int64 value of this object. If this object is not of type

kInt64 then the result is undefined.

Returns

the int64 value of this object.

ICU 2.8

Defined at line 340 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

UDate getDate ()

Gets the Date value of this object. If this object is not of type

kDate then the result is undefined.

Returns

the Date value of this object.

ICU 2.0

Defined at line 365 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

UnicodeString & getString (UnicodeString & result)

Gets the string value of this object. If this object is not of type

kString then the result is undefined.

Parameters

result Output param to receive the Date value of this object.

Returns

A reference to 'result'.

ICU 2.0

Defined at line 384 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

const Formattable * getArray (int32_t & count)

Gets the array value and count of this object. If this object

is not of type kArray then the result is undefined.

Parameters

count fill-in with the count of this object.

Returns

the array value of this object.

ICU 2.0

Defined at line 442 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

number::impl::DecimalQuantity * getDecimalQuantity ()

Internal function, do not use.

TODO: figure out how to make this be non-public.

NumberFormat::format(Formattable, ...

needs to get at the DecimalQuantity, if it exists, for

big decimal formatting.

Defined at line 651 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

Formattable & operator= (const Formattable & rhs)

Assignment operator.

Parameters

rhs The Formattable object to copy into this object. ICU 2.0
bool operator== (const Formattable & other)

Equality comparison.

Parameters

other the object to be compared with.

Returns

true if other are equal to this, false otherwise.

ICU 2.0

void ~Formattable ()

Destructor.

ICU 2.0

Type getType ()

Gets the data type of this Formattable object.

Returns

the data type of this Formattable object.

ICU 2.0

UBool isNumeric ()

Returns true if the data type of this Formattable object

is kDouble, kLong, or kInt64

Returns

true if this is a pure numeric object

ICU 3.0

double getDouble (UErrorCode & status)

Gets the double value of this object. If this object is of type

long, int64 or Decimal Number then a conversion is performed, with

possible loss of precision. If the type is kObject and the

object is a Measure, then the result of

getNumber().getDouble(status) is returned. If this object is

neither a numeric type nor a Measure, then 0 is returned and

the status is set to U_INVALID_FORMAT_ERROR.

Parameters

status the error code

Returns

the double value of this object.

ICU 3.0

int32_t getLong (UErrorCode & status)

Gets the long value of this object. If the magnitude is too

large to fit in a long, then the maximum or minimum long value,

as appropriate, is returned and the status is set to

U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and

it fits within a long, then no precision is lost. If it is of

type kDouble, then a conversion is performed, with

truncation of any fractional part. If the type is kObject and

the object is a Measure, then the result of

getNumber().getLong(status) is returned. If this object is

neither a numeric type nor a Measure, then 0 is returned and

the status is set to U_INVALID_FORMAT_ERROR.

Parameters

status the error code

Returns

the long value of this object.

ICU 3.0

int64_t getInt64 (UErrorCode & status)

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 the type

is kObject and the object is a Measure, then the result of

getNumber().getDouble(status) is returned. If this object is

neither a numeric type nor a Measure, then 0 is returned and

the status is set to U_INVALID_FORMAT_ERROR.

Parameters

status the error code

Returns

the int64 value of this object.

ICU 3.0

UDate getDate (UErrorCode & status)

Gets the Date value of this object. If the type is not a date,

status is set to U_INVALID_FORMAT_ERROR and the return value is

undefined.

Parameters

status the error code.

Returns

the Date value of this object.

ICU 3.0

Defined at line 711 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

UnicodeString & getString (UnicodeString & result, UErrorCode & status)

Gets the string value of this object. If the type is not a

string, status is set to U_INVALID_FORMAT_ERROR and a bogus

string is returned.

Parameters

result Output param to receive the Date value of this object.
status the error code.

Returns

A reference to 'result'.

ICU 3.0

Formattable & operator[] (int32_t index)

Accesses the specified element in the array value of this

Formattable object. If this object is not of type kArray then

the result is undefined.

Parameters

index the specified index.

Returns

the accessed element in the array.

ICU 2.0

Defined at line 464 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

const UnicodeString & getString ()

Gets a const reference to the string value of this object. If

this object is not of type kString then the result is

undefined.

Returns

a const reference to the string value of this object.

ICU 2.0

Defined at line 721 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

const UnicodeString & getString (UErrorCode & status)

Gets a const reference to the string value of this object. If

the type is not a string, status is set to

U_INVALID_FORMAT_ERROR and the result is a bogus string.

Parameters

status the error code.

Returns

a const reference to the string value of this object.

ICU 3.0

UnicodeString & getString ()

Gets a reference to the string value of this object. If this

object is not of type kString then the result is undefined.

Returns

a reference to the string value of this object.

ICU 2.0

Defined at line 725 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

UnicodeString & getString (UErrorCode & status)

Gets a reference to the string value of this object. If the

type is not a string, status is set to U_INVALID_FORMAT_ERROR

and the result is a bogus string.

Parameters

status the error code.

Returns

a reference to the string value of this object.

ICU 3.0

const Formattable * getArray (int32_t & count, UErrorCode & status)

Gets the array value and count of this object. If the type is

not an array, status is set to U_INVALID_FORMAT_ERROR, count is

set to 0, and the result is nullptr.

Parameters

count fill-in with the count of this object.
status the error code.

Returns

the array value of this object.

ICU 3.0

const UObject * getObject ()

Returns a pointer to the UObject contained within this

formattable, or nullptr if this object does not contain a UObject.

Returns

a UObject pointer, or nullptr

ICU 3.0

StringPiece getDecimalNumber (UErrorCode & status)

Returns a numeric string representation of the number contained within this

formattable, or nullptr if this object does not contain numeric type.

For values obtained by parsing, the returned decimal number retains

the full precision and range of the original input, unconstrained by

the limits of a double floating point or a 64 bit int.

This function is not thread safe, and therefore is not declared const,

even though it is logically const.

Possible errors include U_MEMORY_ALLOCATION_ERROR, and

U_INVALID_STATE if the formattable object has not been set to

a numeric type.

Parameters

status the error code.

Returns

the unformatted string representation of a number.

ICU 4.4

void setDouble (double d)

Sets the double value of this object and changes the type to

kDouble.

Parameters

d the new double value to be set. ICU 2.0
void setLong (int32_t l)

Sets the long value of this object and changes the type to

kLong.

Parameters

l the new long value to be set. ICU 2.0
void setInt64 (int64_t ll)

Sets the int64 value of this object and changes the type to

kInt64.

Parameters

ll the new int64 value to be set. ICU 2.8
void setDate (UDate d)

Sets the Date value of this object and changes the type to

kDate.

Parameters

d the new Date value to be set. ICU 2.0
void setString (const UnicodeString & stringToCopy)

Sets the string value of this object and changes the type to

kString.

Parameters

stringToCopy the new string value to be set. ICU 2.0
void setArray (const Formattable * array, int32_t count)

Sets the array value and count of this object and changes the

type to kArray.

Parameters

array the array value.
count the number of array elements to be copied. ICU 2.0
void adoptString (UnicodeString * stringToAdopt)

Sets and adopts the string value and count of this object and

changes the type to kArray.

Parameters

stringToAdopt the new string value to be adopted. ICU 2.0
void adoptArray (Formattable * array, int32_t count)

Sets and adopts the array value and count of this object and

changes the type to kArray.

ICU 2.0

void adoptObject (UObject * objectToAdopt)

Sets and adopts the UObject value of this object and changes

the type to kObject. After this call, the caller must not

delete the given object.

Parameters

objectToAdopt the UObject value to be adopted ICU 3.0
void setDecimalNumber (StringPiece numberString, UErrorCode & status)

Sets the the numeric value from a decimal number string, and changes

the type to to a numeric type appropriate for the number.

The syntax of the number is a "numeric string"

as defined in the Decimal Arithmetic Specification, available at

http://speleotrove.com/decimal

The full precision and range of the input number will be retained,

even when it exceeds what can be represented by a double or an int64.

Parameters

numberString a string representation of the unformatted decimal number.
status the error code. Set to U_INVALID_FORMAT_ERROR if the incoming string is not a valid decimal number. ICU 4.4
UClassID getDynamicClassID ()

ICU "poor man's RTTI", returns a UClassID for the actual class.

ICU 2.2

UClassID getStaticClassID ()

ICU "poor man's RTTI", returns a UClassID for this class.

ICU 2.2

Formattable * fromUFormattable (UFormattable * fmt)

Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast.

Parameters

fmt a valid UFormattable

Returns

the UFormattable as a Formattable object pointer. This is an alias to the original

UFormattable, and so is only valid while the original argument remains in scope.

ICU 52

Defined at line 743 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

const Formattable * fromUFormattable (const UFormattable * fmt)

Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast.

Parameters

fmt a valid UFormattable

Returns

the UFormattable as a Formattable object pointer. This is an alias to the original

UFormattable, and so is only valid while the original argument remains in scope.

ICU 52

Defined at line 747 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

UFormattable * toUFormattable ()

Convert this object pointer to a UFormattable.

Returns

this object as a UFormattable pointer. This is an alias to this object,

and so is only valid while this object remains in scope.

ICU 52

Defined at line 735 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

const UFormattable * toUFormattable ()

Convert this object pointer to a UFormattable.

Returns

this object as a UFormattable pointer. This is an alias to this object,

and so is only valid while this object remains in scope.

ICU 52

Defined at line 739 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

int32_t getLong (UErrorCode * status)

Deprecated variant of getLong(UErrorCode

&

).

Parameters

status the error code

Returns

the long value of this object.

Defined at line 730 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

void populateDecimalQuantity (number::impl::DecimalQuantity & output, UErrorCode & status)

Export the value of this Formattable to a DecimalQuantity.

void adoptDecimalQuantity (number::impl::DecimalQuantity * dq)

Adopt, and set value from, a DecimalQuantity

Internal Function, do not use.

Parameters

dq the DecimalQuantity to be adopted
CharString * internalGetCharString (UErrorCode & status)

Internal function to return the CharString pointer.

Parameters

status error code

Returns

pointer to the CharString - may become invalid if the object is modified

Enumerations

enum ISDATE
Name Value
kIsDate 0

This enum is only used to let callers distinguish between

the Formattable(UDate) constructor and the Formattable(double)

constructor; the compiler cannot distinguish the signatures,

since UDate is currently typedefed to be either double or long.

If UDate is changed later to be a bonafide class

or struct, then we no longer need this enum.

ICU 2.4

Defined at line 74 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h

enum Type
Name Value
kDate 0
kDouble 1
kLong 2
kString 3
kArray 4
kInt64 5
kObject 6

Selector for flavor of data type contained within a

Formattable object. Formattable is a union of several

different types, and at any time contains exactly one type.

ICU 2.4

Defined at line 220 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h