formattednumber.h
Go to the documentation of this file.
// © 2022 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef __FORMATTEDNUMBER_H__
#define __FORMATTEDNUMBER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/uobject.h"
#include "unicode/formattedvalue.h"
#include "unicode/measunit.h"
#include "unicode/udisplayoptions.h"
U_NAMESPACE_BEGIN
class FieldPositionIteratorHandler;
class SimpleDateFormat;
namespace number { // icu::number
namespace impl {
class DecimalQuantity;
class UFormattedNumberData;
struct UFormattedNumberImpl;
} // icu::number::impl
class U_I18N_API FormattedNumber : public UMemory, public FormattedValue {
public:
FormattedNumber()
: fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
FormattedNumber(FormattedNumber&& src) noexcept;
virtual ~FormattedNumber() override;
FormattedNumber(const FormattedNumber&) = delete;
FormattedNumber& operator=(const FormattedNumber&) = delete;
FormattedNumber& operator=(FormattedNumber&& src) noexcept;
// Copybrief: this method is older than the parent method
UnicodeString toString(UErrorCode& status) const override;
// Copydoc: this method is new in ICU 64
UnicodeString toTempString(UErrorCode& status) const override;
// Copybrief: this method is older than the parent method
Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override;
// Copydoc: this method is new in ICU 64
UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const override;
template<typename StringClass>
inline StringClass toDecimalNumber(UErrorCode& status) const;
MeasureUnit getOutputUnit(UErrorCode& status) const;
UDisplayOptionsNounClass getNounClass(UErrorCode &status) const;
#ifndef U_HIDE_INTERNAL_API
void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
#endif /* U_HIDE_INTERNAL_API */
private:
// Can't use LocalPointer because UFormattedNumberData is forward-declared
impl::UFormattedNumberData *fData;
// Error code for the terminal methods
UErrorCode fErrorCode;
explicit FormattedNumber(impl::UFormattedNumberData *results)
: fData(results), fErrorCode(U_ZERO_ERROR) {}
explicit FormattedNumber(UErrorCode errorCode)
: fData(nullptr), fErrorCode(errorCode) {}
void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
// To give LocalizedNumberFormatter format methods access to this class's constructor:
friend class LocalizedNumberFormatter;
friend class SimpleNumberFormatter;
// To give C API access to internals
friend struct impl::UFormattedNumberImpl;
// To give access to the data pointer for non-heap allocation
friend class icu::SimpleDateFormat;
};
template<typename StringClass>
StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
StringClass result;
StringByteSink<StringClass> sink(&result);
toDecimalNumber(sink, status);
return result;
}
} // namespace number
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __FORMATTEDNUMBER_H__
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition appendable.h:54
icu::ByteSink
A ByteSink can be filled with bytes.
Definition bytestream.h:53
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition formattedvalue.h:41
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition formattedvalue.h:241
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition measunit.h:409
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition smpdtfmt.h:385
icu::UMemory
UMemory is the common ICU base class.
Definition uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
icu::number::FormattedNumber
The result of a number formatting operation.
Definition formattednumber.h:48
icu::number::FormattedNumber::getDecimalQuantity
void getDecimalQuantity(impl::DecimalQuantity &output, UErrorCode &status) const
Gets the raw DecimalQuantity for plural rule selection.
icu::number::FormattedNumber::getNounClass
UDisplayOptionsNounClass getNounClass(UErrorCode &status) const
Gets the noun class of the formatted output.
icu::number::FormattedNumber::operator=
FormattedNumber & operator=(const FormattedNumber &)=delete
Copying not supported; use move assignment instead.
icu::number::FormattedNumber::FormattedNumber
FormattedNumber(const FormattedNumber &)=delete
Copying not supported; use move constructor instead.
icu::number::FormattedNumber::getOutputUnit
MeasureUnit getOutputUnit(UErrorCode &status) const
Gets the resolved output unit.
icu::number::FormattedNumber::FormattedNumber
FormattedNumber()
Default constructor; makes an empty FormattedNumber.
Definition formattednumber.h:55
icu::number::FormattedNumber::getAllFieldPositionsImpl
void getAllFieldPositionsImpl(FieldPositionIteratorHandler &fpih, UErrorCode &status) const
Populates the mutable builder type FieldPositionIteratorHandler.
icu::number::FormattedNumber::appendTo
Appendable & appendTo(Appendable &appendable, UErrorCode &status) const override
Appends the formatted string to an Appendable.
icu::number::FormattedNumber::~FormattedNumber
virtual ~FormattedNumber() override
Destruct an instance of FormattedNumber.
icu::number::FormattedNumber::toString
UnicodeString toString(UErrorCode &status) const override
Returns the formatted string as a self-contained UnicodeString.
icu::number::FormattedNumber::operator=
FormattedNumber & operator=(FormattedNumber &&src) noexcept
Move assignment: Leaves the source FormattedNumber in an undefined state.
icu::number::FormattedNumber::FormattedNumber
FormattedNumber(FormattedNumber &&src) noexcept
Move constructor: Leaves the source FormattedNumber in an undefined state.
icu::number::FormattedNumber::nextPosition
UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
Iterates over field positions in the FormattedValue.
icu::number::FormattedNumber::toTempString
UnicodeString toTempString(UErrorCode &status) const override
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
formattedvalue.h
C++ API: Abstract operations for localized strings.
measunit.h
C++ API: A unit for measuring a quantity.
udisplayoptions.h
C API: Display options (enum types, values, helper functions)
UDisplayOptionsNounClass
UDisplayOptionsNounClass
Represents all the grammatical noun classes that are supported by CLDR.
Definition udisplayoptions.h:134
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
uobject.h
C++ API: Common ICU base class UObject.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
U_INVALID_STATE_ERROR
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition utypes.h:494
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:465
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316