ICU 65.1
65.1
|
The result of a number formatting operation. More...
#include <numberformatter.h>
Public Member Functions | |
FormattedNumber () | |
Default constructor; makes an empty FormattedNumber. More... | |
FormattedNumber (FormattedNumber &&src) U_NOEXCEPT | |
Move constructor: Leaves the source FormattedNumber in an undefined state. More... | |
virtual | ~FormattedNumber () U_OVERRIDE |
Destruct an instance of FormattedNumber. More... | |
FormattedNumber (const FormattedNumber &)=delete | |
Copying not supported; use move constructor instead. More... | |
FormattedNumber & | operator= (const FormattedNumber &)=delete |
Copying not supported; use move assignment instead. More... | |
FormattedNumber & | operator= (FormattedNumber &&src) U_NOEXCEPT |
Move assignment: Leaves the source FormattedNumber in an undefined state. More... | |
UnicodeString | toString (UErrorCode &status) const U_OVERRIDE |
Returns the formatted string as a self-contained UnicodeString. More... | |
UnicodeString | toTempString (UErrorCode &status) const U_OVERRIDE |
Returns the formatted string as a read-only alias to memory owned by the FormattedValue. More... | |
Appendable & | appendTo (Appendable &appendable, UErrorCode &status) const U_OVERRIDE |
Appends the formatted string to an Appendable. More... | |
UBool | nextPosition (ConstrainedFieldPosition &cfpos, UErrorCode &status) const U_OVERRIDE |
Iterates over field positions in the FormattedValue. More... | |
UBool | nextFieldPosition (FieldPosition &fieldPosition, UErrorCode &status) const |
Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given field in the output string. More... | |
void | getAllFieldPositions (FieldPositionIterator &iterator, UErrorCode &status) const |
Export the formatted number to a FieldPositionIterator. More... | |
template<typename StringClass > | |
StringClass | toDecimalNumber (UErrorCode &status) const |
Export the formatted number as a "numeric string" conforming to the syntax defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal. More... | |
void | getDecimalQuantity (impl::DecimalQuantity &output, UErrorCode &status) const |
Gets the raw DecimalQuantity for plural rule selection. More... | |
void | getAllFieldPositionsImpl (FieldPositionIteratorHandler &fpih, UErrorCode &status) const |
Populates the mutable builder type FieldPositionIteratorHandler. More... | |
Public Member Functions inherited from icu::FormattedValue | |
virtual | ~FormattedValue () |
Friends | |
class | LocalizedNumberFormatter |
struct | impl::UFormattedNumberImpl |
The result of a number formatting operation.
This class allows the result to be exported in several data types, including a UnicodeString and a FieldPositionIterator.
Instances of this class are immutable and thread-safe.
Definition at line 2410 of file numberformatter.h.
|
inline |
Default constructor; makes an empty FormattedNumber.
Definition at line 2419 of file numberformatter.h.
References U_NOEXCEPT, U_OVERRIDE, and U_ZERO_ERROR.
icu::number::FormattedNumber::FormattedNumber | ( | FormattedNumber && | src | ) |
Move constructor: Leaves the source FormattedNumber in an undefined state.
|
virtual |
Destruct an instance of FormattedNumber.
|
delete |
Copying not supported; use move constructor instead.
|
virtual |
Appends the formatted string to an Appendable.
For more information, see FormattedValue::appendTo()
Implements icu::FormattedValue.
void icu::number::FormattedNumber::getAllFieldPositions | ( | FieldPositionIterator & | iterator, |
UErrorCode & | status | ||
) | const |
Export the formatted number to a FieldPositionIterator.
This allows you to determine which characters in the output string correspond to which fields, such as the integer part, fraction part, and sign.
This is an alternative to the more powerful nextPosition() API.
If information on only one field is needed, use nextPosition() or nextFieldPosition() instead.
iterator | The FieldPositionIterator to populate with all of the fields present in the formatted number. |
status | Set if an error occurs while populating the FieldPositionIterator. |
void icu::number::FormattedNumber::getAllFieldPositionsImpl | ( | FieldPositionIteratorHandler & | fpih, |
UErrorCode & | status | ||
) | const |
Populates the mutable builder type FieldPositionIteratorHandler.
void icu::number::FormattedNumber::getDecimalQuantity | ( | impl::DecimalQuantity & | output, |
UErrorCode & | status | ||
) | const |
Gets the raw DecimalQuantity for plural rule selection.
UBool icu::number::FormattedNumber::nextFieldPosition | ( | FieldPosition & | fieldPosition, |
UErrorCode & | status | ||
) | const |
Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given field in the output string.
This allows you to determine the locations of, for example, the integer part, fraction part, or symbols.
This is a simpler but less powerful alternative to nextPosition.
If a field occurs just once, calling this method will find that occurrence and return it. If a field occurs multiple times, this method may be called repeatedly with the following pattern:
FieldPosition fpos(UNUM_GROUPING_SEPARATOR_FIELD); while (formattedNumber.nextFieldPosition(fpos, status)) { // do something with fpos. }
This method is useful if you know which field to query. If you want all available field position information, use nextPosition or getAllFieldPositions.
fieldPosition | Input+output variable. On input, the "field" property determines which field to look up, and the "beginIndex" and "endIndex" properties determine where to begin the search. On output, the "beginIndex" is set to the beginning of the first occurrence of the field with either begin or end indices after the input indices; "endIndex" is set to the end of that occurrence of the field (exclusive index). If a field position is not found, the method returns FALSE and the FieldPosition may or may not be changed. |
status | Set if an error occurs while populating the FieldPosition. |
|
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 }
cfpos | The object used for iteration state. This can provide constraints to iterate over only one specific category or field; see ConstrainedFieldPosition::constrainCategory and ConstrainedFieldPosition::constrainField. |
status | Set if an error occurs. |
Implements icu::FormattedValue.
|
delete |
Copying not supported; use move assignment instead.
FormattedNumber& icu::number::FormattedNumber::operator= | ( | FormattedNumber && | src | ) |
Move assignment: Leaves the source FormattedNumber in an undefined state.
|
inline |
Export the formatted number as a "numeric string" conforming to the syntax defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal.
This endpoint is useful for obtaining the exact number being printed after scaling and rounding have been applied by the number formatter.
Example call site:
auto decimalNumber = fn.toDecimalNumber<std::string>(status);
StringClass | A string class compatible with StringByteSink; for example, std::string. |
status | Set if an error occurs. |
Definition at line 2598 of file numberformatter.h.
|
virtual |
Returns the formatted string as a self-contained UnicodeString.
For more information, see FormattedValue::toString()
Implements icu::FormattedValue.
|
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.
status | Set if an error occurs. |
Implements icu::FormattedValue.