ICU 74.1 74.1
Public Member Functions | Friends
icu::number::FormattedNumberRange Class Reference

The result of a number range formatting operation. More...

#include <numberrangeformatter.h>

Inheritance diagram for icu::number::FormattedNumberRange:
icu::UMemory icu::FormattedValue

Public Member Functions

UnicodeString toString (UErrorCode &status) const override
 Returns the formatted string as a self-contained UnicodeString. More...
 
UnicodeString toTempString (UErrorCode &status) const override
 Returns the formatted string as a read-only alias to memory owned by the FormattedValue. More...
 
AppendableappendTo (Appendable &appendable, UErrorCode &status) const override
 Appends the formatted string to an Appendable. More...
 
UBool nextPosition (ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
 Iterates over field positions in the FormattedValue. More...
 
template<typename StringClass >
std::pair< StringClass, StringClass > getDecimalNumbers (UErrorCode &status) const
 Extracts the formatted range as a pair of decimal numbers. More...
 
UNumberRangeIdentityResult getIdentityResult (UErrorCode &status) const
 Returns whether the pair of numbers was successfully formatted as a range or whether an identity fallback was used. More...
 
 FormattedNumberRange ()
 Default constructor; makes an empty FormattedNumberRange. More...
 
 FormattedNumberRange (const FormattedNumberRange &)=delete
 Copying not supported; use move constructor instead.
 
FormattedNumberRangeoperator= (const FormattedNumberRange &)=delete
 Copying not supported; use move assignment instead.
 
 FormattedNumberRange (FormattedNumberRange &&src) noexcept
 Move constructor: Leaves the source FormattedNumberRange in an undefined state. More...
 
FormattedNumberRangeoperator= (FormattedNumberRange &&src) noexcept
 Move assignment: Leaves the source FormattedNumberRange in an undefined state. More...
 
 ~FormattedNumberRange ()
 Destruct an instance of FormattedNumberRange, cleaning up any memory it might own. More...
 
- Public Member Functions inherited from icu::FormattedValue
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...
 

Friends

class ::icu::PluralRules
 
class LocalizedNumberRangeFormatter
 
struct impl::UFormattedNumberRangeImpl
 

Detailed Description

The result of a number range 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.

Stable:
ICU 63

Definition at line 586 of file numberrangeformatter.h.

Constructor & Destructor Documentation

◆ FormattedNumberRange() [1/2]

icu::number::FormattedNumberRange::FormattedNumberRange ( )
inline

Default constructor; makes an empty FormattedNumberRange.

Stable:
ICU 70

Definition at line 653 of file numberrangeformatter.h.

◆ FormattedNumberRange() [2/2]

icu::number::FormattedNumberRange::FormattedNumberRange ( FormattedNumberRange &&  src)
noexcept

Move constructor: Leaves the source FormattedNumberRange in an undefined state.

Stable:
ICU 63

◆ ~FormattedNumberRange()

icu::number::FormattedNumberRange::~FormattedNumberRange ( )

Destruct an instance of FormattedNumberRange, cleaning up any memory it might own.

Stable:
ICU 63

Member Function Documentation

◆ appendTo()

Appendable & icu::number::FormattedNumberRange::appendTo ( Appendable appendable,
UErrorCode status 
) const
overridevirtual

Appends the formatted string to an Appendable.

For more information, see FormattedValue::appendTo()

Stable:
ICU 63

Implements icu::FormattedValue.

◆ getDecimalNumbers()

template<typename StringClass >
std::pair< StringClass, StringClass > icu::number::FormattedNumberRange::getDecimalNumbers ( UErrorCode status) const
inline

Extracts the formatted range as a pair of decimal numbers.

This endpoint is useful for obtaining the exact number being printed after scaling and rounding have been applied by the number range formatting pipeline.

The syntax of the unformatted numbers is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal

Example C++17 call site:

auto [ first, second ] = range.getDecimalNumbers<std::string>(status);
Template Parameters
StringClassA string class compatible with StringByteSink; for example, std::string.
Parameters
statusSet if an error occurs.
Returns
A pair of StringClasses containing the numeric strings.
Stable:
ICU 68

Definition at line 718 of file numberrangeformatter.h.

◆ getIdentityResult()

UNumberRangeIdentityResult icu::number::FormattedNumberRange::getIdentityResult ( UErrorCode status) const

Returns whether the pair of numbers was successfully formatted as a range or whether an identity fallback was used.

For example, if the first and second number were the same either before or after rounding occurred, an identity fallback was used.

Returns
An indication the resulting identity situation in the formatted number range.
Stable:
ICU 63
See also
UNumberRangeIdentityFallback

◆ nextPosition()

UBool icu::number::FormattedNumberRange::nextPosition ( ConstrainedFieldPosition cfpos,
UErrorCode status 
) const
overridevirtual

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.
Stable:
ICU 64

Implements icu::FormattedValue.

◆ operator=()

FormattedNumberRange & icu::number::FormattedNumberRange::operator= ( FormattedNumberRange &&  src)
noexcept

Move assignment: Leaves the source FormattedNumberRange in an undefined state.

Stable:
ICU 63

◆ toString()

UnicodeString icu::number::FormattedNumberRange::toString ( UErrorCode status) const
overridevirtual

Returns the formatted string as a self-contained UnicodeString.

For more information, see FormattedValue::toString()

Stable:
ICU 63

Implements icu::FormattedValue.

◆ toTempString()

UnicodeString icu::number::FormattedNumberRange::toTempString ( UErrorCode status) const
overridevirtual

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.
Stable:
ICU 64

Implements icu::FormattedValue.

Friends And Related Function Documentation

◆ ::icu::PluralRules

friend class ::icu::PluralRules
friend

Definition at line 707 of file numberrangeformatter.h.

◆ impl::UFormattedNumberRangeImpl

friend struct impl::UFormattedNumberRangeImpl
friend

Definition at line 713 of file numberrangeformatter.h.

◆ LocalizedNumberRangeFormatter

friend class LocalizedNumberRangeFormatter
friend

Definition at line 710 of file numberrangeformatter.h.


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