ICU 74.2 74.2
formattednumber.h
Go to the documentation of this file.
1// © 2022 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4#ifndef __FORMATTEDNUMBER_H__
5#define __FORMATTEDNUMBER_H__
6
7#include "unicode/utypes.h"
8
9#if U_SHOW_CPLUSPLUS_API
10
11#if !UCONFIG_NO_FORMATTING
12
13#include "unicode/uobject.h"
15#include "unicode/measunit.h"
17
25U_NAMESPACE_BEGIN
26
27class FieldPositionIteratorHandler;
28
29namespace number { // icu::number
30
31namespace impl {
32class DecimalQuantity;
33class UFormattedNumberData;
34struct UFormattedNumberImpl;
35} // icu::number::impl
36
37
38
48 public:
49
55 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
56
62
67 virtual ~FormattedNumber() override;
68
71
74
80
81 // Copybrief: this method is older than the parent method
90
91 // Copydoc: this method is new in ICU 64
94
95 // Copybrief: this method is older than the parent method
104
105 // Copydoc: this method is new in ICU 64
108
127 template<typename StringClass>
128 inline StringClass toDecimalNumber(UErrorCode& status) const;
129
142
151
152#ifndef U_HIDE_INTERNAL_API
153
158 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
159
164 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
165
166#endif /* U_HIDE_INTERNAL_API */
167
168 private:
169 // Can't use LocalPointer because UFormattedNumberData is forward-declared
170 impl::UFormattedNumberData *fData;
171
172 // Error code for the terminal methods
173 UErrorCode fErrorCode;
174
179 explicit FormattedNumber(impl::UFormattedNumberData *results)
180 : fData(results), fErrorCode(U_ZERO_ERROR) {}
181
182 explicit FormattedNumber(UErrorCode errorCode)
183 : fData(nullptr), fErrorCode(errorCode) {}
184
185 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
186
187 // To give LocalizedNumberFormatter format methods access to this class's constructor:
188 friend class LocalizedNumberFormatter;
189 friend class SimpleNumberFormatter;
190
191 // To give C API access to internals
192 friend struct impl::UFormattedNumberImpl;
193};
194
195template<typename StringClass>
196StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
199 toDecimalNumber(sink, status);
200 return result;
201}
202
203} // namespace number
205
206#endif /* #if !UCONFIG_NO_FORMATTING */
207
208#endif /* U_SHOW_CPLUSPLUS_API */
209
210#endif // __FORMATTEDNUMBER_H__
211
Base class for objects to which Unicode characters and strings can be appended.
Definition appendable.h:54
A ByteSink can be filled with bytes.
Definition bytestream.h:53
Represents a span of a string containing a given field.
An abstract formatted value: a string with associated field attributes.
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A unit such as length, mass, volume, currency, etc.
Definition measunit.h:369
UMemory is the common ICU base class.
Definition uobject.h:115
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
The result of a number formatting operation.
void getDecimalQuantity(impl::DecimalQuantity &output, UErrorCode &status) const
Gets the raw DecimalQuantity for plural rule selection.
UDisplayOptionsNounClass getNounClass(UErrorCode &status) const
Gets the noun class of the formatted output.
FormattedNumber & operator=(const FormattedNumber &)=delete
Copying not supported; use move assignment instead.
FormattedNumber(const FormattedNumber &)=delete
Copying not supported; use move constructor instead.
MeasureUnit getOutputUnit(UErrorCode &status) const
Gets the resolved output unit.
FormattedNumber()
Default constructor; makes an empty FormattedNumber.
void getAllFieldPositionsImpl(FieldPositionIteratorHandler &fpih, UErrorCode &status) const
Populates the mutable builder type FieldPositionIteratorHandler.
Appendable & appendTo(Appendable &appendable, UErrorCode &status) const override
Appends the formatted string to an Appendable.
virtual ~FormattedNumber() override
Destruct an instance of FormattedNumber.
UnicodeString toString(UErrorCode &status) const override
Returns the formatted string as a self-contained UnicodeString.
FormattedNumber & operator=(FormattedNumber &&src) noexcept
Move assignment: Leaves the source FormattedNumber in an undefined state.
FormattedNumber(FormattedNumber &&src) noexcept
Move constructor: Leaves the source FormattedNumber in an undefined state.
UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
Iterates over field positions in the FormattedValue.
UnicodeString toTempString(UErrorCode &status) const override
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
C++ API: Abstract operations for localized strings.
C++ API: A unit for measuring a quantity.
C API: Display options (enum types, values, helper functions)
UDisplayOptionsNounClass
Represents all the grammatical noun classes that are supported by CLDR.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition utypes.h:478
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:449
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301