ICU 65.1  65.1
Public Member Functions
icu::FormattedValue Class Referenceabstract

An abstract formatted value: a string with associated field attributes. More...

#include <formattedvalue.h>

Inheritance diagram for icu::FormattedValue:
icu::FormattedDateInterval icu::FormattedList icu::FormattedRelativeDateTime icu::number::FormattedNumber icu::number::FormattedNumberRange

Public Member Functions

virtual ~FormattedValue ()
 
virtual UnicodeString toString (UErrorCode &status) const =0
 Returns the formatted string as a self-contained UnicodeString. More...
 
virtual UnicodeString toTempString (UErrorCode &status) const =0
 Returns the formatted string as a read-only alias to memory owned by the FormattedValue. More...
 
virtual AppendableappendTo (Appendable &appendable, UErrorCode &status) const =0
 Appends the formatted string to an Appendable. More...
 
virtual UBool nextPosition (ConstrainedFieldPosition &cfpos, UErrorCode &status) const =0
 Iterates over field positions in the FormattedValue. More...
 

Detailed Description

An abstract formatted value: a string with associated field attributes.

Many formatters format to classes implementing FormattedValue.

Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 254 of file formattedvalue.h.

Constructor & Destructor Documentation

◆ ~FormattedValue()

virtual icu::FormattedValue::~FormattedValue ( )
virtual
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Member Function Documentation

◆ appendTo()

virtual Appendable& icu::FormattedValue::appendTo ( Appendable appendable,
UErrorCode status 
) const
pure virtual

Appends the formatted string to an Appendable.

Parameters
appendableThe Appendable to which to append the string output.
statusSet if an error occurs.
Returns
The same Appendable, for chaining.
Draft:
This API may be changed in the future versions and was introduced in ICU 64
See also
Appendable

Implemented in icu::number::FormattedNumber, icu::number::FormattedNumberRange, icu::FormattedRelativeDateTime, icu::FormattedList, and icu::FormattedDateInterval.

Referenced by icu::FormattedDateInterval::FormattedDateInterval(), and icu::FormattedRelativeDateTime::FormattedRelativeDateTime().

◆ nextPosition()

virtual UBool icu::FormattedValue::nextPosition ( ConstrainedFieldPosition cfpos,
UErrorCode status 
) const
pure virtual

Iterates over field positions in the FormattedValue.

This lets you determine the position of specific types of substrings, like a month or a decimal separator.

To loop over all field positions:

ConstrainedFieldPosition cfpos;
while (fmtval.nextPosition(cfpos, status)) {
    // handle the field position; get information from cfpos
}
Parameters
cfposThe object used for iteration state. This can provide constraints to iterate over only one specific category or field; see ConstrainedFieldPosition::constrainCategory and ConstrainedFieldPosition::constrainField.
statusSet if an error occurs.
Returns
TRUE if a new occurrence of the field was found; FALSE otherwise or if an error was set.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Implemented in icu::number::FormattedNumber, icu::number::FormattedNumberRange, icu::FormattedRelativeDateTime, icu::FormattedList, and icu::FormattedDateInterval.

Referenced by icu::FormattedDateInterval::FormattedDateInterval(), and icu::FormattedRelativeDateTime::FormattedRelativeDateTime().

◆ toString()

virtual UnicodeString icu::FormattedValue::toString ( UErrorCode status) const
pure virtual

Returns the formatted string as a self-contained UnicodeString.

If you need the string within the current scope only, consider toTempString.

Parameters
statusSet if an error occurs.
Returns
a UnicodeString containing the formatted string.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Implemented in icu::number::FormattedNumber, icu::number::FormattedNumberRange, icu::FormattedRelativeDateTime, icu::FormattedList, and icu::FormattedDateInterval.

Referenced by icu::FormattedDateInterval::FormattedDateInterval(), and icu::FormattedRelativeDateTime::FormattedRelativeDateTime().

◆ toTempString()

virtual UnicodeString icu::FormattedValue::toTempString ( UErrorCode status) const
pure virtual

Returns the formatted string as a read-only alias to memory owned by the FormattedValue.

The return value is valid only as long as this FormattedValue is present and unchanged in memory. If you need the string outside the current scope, consider toString.

The buffer returned by calling UnicodeString::getBuffer() on the return value is guaranteed to be NUL-terminated.

Parameters
statusSet if an error occurs.
Returns
a temporary UnicodeString containing the formatted string.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Implemented in icu::number::FormattedNumber, icu::number::FormattedNumberRange, icu::FormattedRelativeDateTime, icu::FormattedList, and icu::FormattedDateInterval.

Referenced by icu::FormattedDateInterval::FormattedDateInterval(), and icu::FormattedRelativeDateTime::FormattedRelativeDateTime().


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