4#ifndef __NUMBERFORMATTER_H__
5#define __NUMBERFORMATTER_H__
9#if U_SHOW_CPLUSPLUS_API
11#if !UCONFIG_NO_FORMATTING
90class FieldPositionIteratorHandler;
91class FormattedStringBuilder;
97class NumberParserImpl;
98class MultiplierParseHandler;
113class UnlocalizedNumberFormatter;
114class LocalizedNumberFormatter;
115class FormattedNumber;
117class ScientificNotation;
119class FractionPrecision;
120class CurrencyPrecision;
121class IncrementPrecision;
141static constexpr int32_t kInternalDefaultThreshold = 3;
147class DecimalQuantity;
148class UFormattedNumberData;
149class NumberFormatterImpl;
150struct ParsedPatternInfo;
151class ScientificModifier;
152class MultiplierProducer;
154class ScientificHandler;
156class AffixPatternProvider;
157class NumberPropertyMapper;
158struct DecimalFormatProperties;
159class MultiplierFormatHandler;
160class CurrencySymbols;
161class GeneratorHelpers;
163class NumberRangeFormatterImpl;
165struct UFormattedNumberImpl;
166class MutablePatternModifier;
167class ImmutablePatternModifier;
168struct DecimalFormatWarehouse;
346 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
349 union NotationUnion {
372 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
375 fUnion.errorCode = errorCode;
378 Notation() : fType(NTN_SIMPLE), fUnion() {}
381 if (fType == NTN_ERROR) {
382 status = fUnion.errorCode;
389 friend struct impl::MacroProps;
390 friend class ScientificNotation;
393 friend class impl::NumberFormatterImpl;
394 friend class impl::ScientificModifier;
395 friend class impl::ScientificHandler;
398 friend class impl::GeneratorHelpers;
443 using Notation::Notation;
452 friend class impl::NumberPropertyMapper;
622 int32_t maxSignificantDigits);
645#ifndef U_HIDE_DRAFT_API
706 RND_FRACTION_SIGNIFICANT,
723 union PrecisionUnion {
764 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
765 : fType(type), fUnion(union_) {}
768 fUnion.errorCode = errorCode;
771 Precision() : fType(RND_BOGUS) {}
773 bool isBogus()
const {
774 return fType == RND_BOGUS;
778 if (fType == RND_ERROR) {
779 status = fUnion.errorCode;
786 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
788 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
790 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
792 static Precision constructFractionSignificant(
793 const FractionPrecision &base,
799 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
804 friend struct impl::MacroProps;
805 friend struct impl::MicroProps;
808 friend class impl::NumberFormatterImpl;
811 friend class impl::NumberPropertyMapper;
814 friend class impl::RoundingImpl;
817 friend class FractionPrecision;
818 friend class CurrencyPrecision;
819 friend class IncrementPrecision;
822 friend class impl::GeneratorHelpers;
825 friend class units::UnitsRouter;
854 int32_t minSignificantDigits,
855 int32_t maxSignificantDigits,
898 using Precision::Precision;
936 using Precision::Precision;
972 using Precision::Precision;
1020 bool fFormatFailIfMoreThanMaxDigits;
1024 bool fHasError =
false;
1026 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt,
bool formatFailIfMoreThanMaxDigits);
1029 fUnion.errorCode = errorCode;
1034 fUnion.minMaxInt.fMinInt = -1;
1038 static IntegerWidth standard() {
1039 return IntegerWidth::zeroFillTo(1);
1042 bool isBogus()
const {
1043 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1048 status = fUnion.errorCode;
1054 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1056 bool operator==(
const IntegerWidth& other)
const;
1059 friend struct impl::MacroProps;
1060 friend struct impl::MicroProps;
1063 friend class impl::NumberFormatterImpl;
1066 friend class impl::MutablePatternModifier;
1067 friend class impl::ImmutablePatternModifier;
1070 friend class impl::NumberPropertyMapper;
1073 friend class impl::GeneratorHelpers;
1156#ifndef U_HIDE_INTERNAL_API
1158 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1163 impl::DecNum* fArbitrary;
1166 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1170 bool isValid()
const {
1171 return fMagnitude != 0 || fArbitrary !=
nullptr;
1182 void applyTo(impl::DecimalQuantity& quantity)
const;
1184 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1187 friend struct impl::MacroProps;
1188 friend struct impl::MicroProps;
1191 friend class impl::NumberFormatterImpl;
1194 friend class impl::MultiplierFormatHandler;
1197 friend class impl::GeneratorHelpers;
1200 friend class ::icu::numparse::impl::NumberParserImpl;
1201 friend class ::icu::numparse::impl::MultiplierParseHandler;
1224#ifndef U_HIDE_INTERNAL_API
1267 friend class impl::NumberFormatterImpl;
1270 friend class impl::GeneratorHelpers;
1274 friend struct impl::MacroProps;
1299#ifndef U_HIDE_INTERNAL_API
1341 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1344 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1352 enum SymbolsPointerType {
1353 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1361 void doCopyFrom(
const SymbolsWrapper &other);
1363 void doMoveFrom(SymbolsWrapper&& src);
1372#ifndef U_HIDE_INTERNAL_API
1386 : fGrouping1(grouping1),
1387 fGrouping2(grouping2),
1388 fMinGrouping(minGrouping),
1389 fStrategy(strategy) {}
1417 int16_t fMinGrouping;
1427 bool isBogus()
const {
1428 return fGrouping1 == -3;
1432 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1434 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1437 friend struct MacroProps;
1438 friend struct MicroProps;
1441 friend class NumberFormatterImpl;
1444 friend class ::icu::numparse::impl::NumberParserImpl;
1447 friend class impl::GeneratorHelpers;
1454#ifndef U_HIDE_INTERNAL_API
1477 Padder(int32_t width);
1480 fUnion.errorCode = errorCode;
1483 Padder() : fWidth(-2) {}
1485 bool isBogus()
const {
1486 return fWidth == -2;
1491 status = fUnion.errorCode;
1497 bool isValid()
const {
1501 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1502 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1506 friend struct MacroProps;
1507 friend struct MicroProps;
1510 friend class impl::NumberFormatterImpl;
1513 friend class impl::GeneratorHelpers;
1555 bool approximately =
false;
1570 const AffixPatternProvider* affixProvider =
nullptr;
1576 int32_t threshold = kInternalDefaultThreshold;
1588 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1589 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1590 symbols.
copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1591 unitDisplayCase.copyErrorTo(status);
1597#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1603#pragma warning(push)
1604#pragma warning(disable: 4661)
1612template<
typename Derived>
2257#ifndef U_HIDE_DRAFT_API
2278#ifndef U_HIDE_INTERNAL_API
2303#ifndef U_HIDE_INTERNAL_API
2396 fMacros.copyErrorTo(outErrorCode);
2413 friend class impl::NumberRangeFormatterImpl;
2549#ifndef U_HIDE_INTERNAL_API
2629#ifndef U_HIDE_INTERNAL_API
2656 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2657 char fUnsafeCallCount[8] {};
2661 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2663 explicit LocalizedNumberFormatter(
const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2665 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src)
U_NOEXCEPT;
2667 LocalizedNumberFormatter(
const impl::MacroProps ¯os,
const Locale &locale);
2669 LocalizedNumberFormatter(impl::MacroProps &¯os,
const Locale &locale);
2671 void resetCompiled();
2673 void lnfMoveHelper(LocalizedNumberFormatter&& src);
2675 void lnfCopyHelper(
const LocalizedNumberFormatter& src,
UErrorCode& status);
2680 bool computeCompiled(
UErrorCode& status)
const;
2683 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2684 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2687 friend class UnlocalizedNumberFormatter;
2690#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2783 template<typename StringClass>
2784 inline StringClass toDecimalNumber(
UErrorCode& status) const;
2799#ifndef U_HIDE_DRAFT_API
2812#ifndef U_HIDE_INTERNAL_API
2830 const impl::UFormattedNumberData *fData;
2843 : fData(nullptr), fErrorCode(errorCode) {}
2848 friend class LocalizedNumberFormatter;
2851 friend struct impl::UFormattedNumberImpl;
2854template<
typename StringClass>
2855StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2858 toDecimalNumber(sink, status);
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
C++ API: Interface for writing bytes, and implementation classes.
Base class for objects to which Unicode characters and strings can be appended.
A ByteSink can be filled with bytes.
Represents a span of a string containing a given field.
A unit of currency, such as USD (U.S.
Represents all the display options that are supported by CLDR such as grammatical case,...
"Smart pointer" class, deletes objects via the standard C++ delete operator.
A Locale object represents a specific geographical, political, or cultural region.
A unit such as length, mass, volume, currency, etc.
Defines numbering systems.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Implementation of ByteSink that writes to a "string".
A string-like object that points to a sized piece of memory.
UMemory is the common ICU base class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
Precision withCurrency(const CurrencyUnit ¤cy) const
Associates a currency with this rounding precision.
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
Precision withMinDigits(int32_t minSignificantDigits) const
Ensure that no less than this number of significant digits are retained when rounding according to fr...
Precision withSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const
Override maximum fraction digits with maximum significant digits depending on the magnitude of the nu...
Precision withMaxDigits(int32_t maxSignificantDigits) const
Ensure that no more than this number of significant digits are retained when rounding according to fr...
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Precision withMinFraction(int32_t minFrac) const
Specifies the minimum number of fraction digits to render after the decimal separator,...
A class that defines the strategy for padding and truncating integers before the decimal separator.
static IntegerWidth zeroFillTo(int32_t minInt)
Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal ...
IntegerWidth truncateAt(int32_t maxInt)
Truncate numbers exceeding a certain number of numerals before the decimal separator.
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
static CompactNotation compactShort()
Print the number using short-form compact notation.
static ScientificNotation engineering()
Print the number using engineering notation, a variant of scientific notation in which the exponent m...
static CompactNotation compactLong()
Print the number using long-form compact notation.
static SimpleNotation simple()
Print the number using simple notation without any scaling by powers of ten.
static ScientificNotation scientific()
Print the number using scientific notation (also known as scientific form, standard index form,...
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.
static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures.
static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits)
Always show at least a certain number of significant digits/figures, padding with zeros if necessary.
static FractionPrecision maxFraction(int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
static IncrementPrecision increment(double roundingIncrement)
Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
static CurrencyPrecision currency(UCurrencyUsage currencyUsage)
Show numbers rounded and padded according to the rules for the currency unit.
static FractionPrecision minFraction(int32_t minFractionPlaces)
Always show at least a certain number of fraction places after the decimal separator,...
Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const
Configure how trailing zeros are displayed on numbers.
static Precision unlimited()
Show all available digits to full precision.
static FractionPrecision integer()
Show numbers rounded if necessary to the nearest integer.
static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits or significant figures.
static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude)
Version of Precision::increment() that takes an integer at a particular power of 10.
static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures; in addition,...
A class that defines a quantity by which a number should be multiplied when formatting.
static Scale none()
Do not change the value of numbers when formatting or parsing.
Scale(Scale &&src) U_NOEXCEPT
static Scale powerOfTen(int32_t power)
Multiply numbers by a power of ten before formatting.
Scale(const Scale &other)
static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power)
Multiply a number by both a power of ten and by an arbitrary double value.
static Scale byDecimal(StringPiece multiplicand)
Multiply numbers by an arbitrary value before formatting.
Scale(int32_t magnitude, impl::DecNum *arbitraryToAdopt)
Scale & operator=(const Scale &other)
Scale & operator=(Scale &&src) U_NOEXCEPT
static Scale byDouble(double multiplicand)
Multiply numbers by an arbitrary value before formatting.
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const
Sets whether to show the sign on positive and negative exponents in scientific notation.
ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const
Sets the minimum number of digits to show in the exponent of scientific notation, padding with zeros ...
static Grouper forStrategy(UNumberGroupingStrategy grouping)
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
int16_t getSecondary() const
static Grouper forProperties(const DecimalFormatProperties &properties)
Resolve the values in Properties to a Grouper object.
int16_t getPrimary() const
static Padder forProperties(const DecimalFormatProperties &properties)
static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position)
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
StringProp(const StringProp &other)
StringProp & operator=(StringProp &&src) U_NOEXCEPT
StringProp & operator=(const StringProp &other)
void set(StringPiece value)
StringProp(StringProp &&src) U_NOEXCEPT
SymbolsWrapper & operator=(const SymbolsWrapper &other)
bool isNumberingSystem() const
Whether the object is currently holding a NumberingSystem.
SymbolsWrapper(SymbolsWrapper &&src) U_NOEXCEPT
SymbolsWrapper & operator=(SymbolsWrapper &&src) U_NOEXCEPT
const DecimalFormatSymbols * getDecimalFormatSymbols() const
Get the DecimalFormatSymbols pointer.
SymbolsWrapper(const SymbolsWrapper &other)
void setTo(const DecimalFormatSymbols &dfs)
The provided object is copied, but we do not adopt it.
const NumberingSystem * getNumberingSystem() const
Get the NumberingSystem pointer.
void setTo(const NumberingSystem *ns)
Adopt the provided object.
UBool copyErrorTo(UErrorCode &status) const
bool isDecimalFormatSymbols() const
Whether the object is currently holding a DecimalFormatSymbols.
C++ API: Currency Unit Information.
C++ API: Symbols for formatting numbers.
C++ API: Display options class.
C++ API: FieldPosition identifies the fields in a formatted output.
C++ API: FieldPosition Iterator.
C++ API: A unit for measuring a quantity.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: units for percent and permille.
C API: Parse Error Information.
C++ API: PluralRules object.
A UParseError struct is used to returned detailed information about parsing errors.
impl::digits_t fMinExponentDigits
UNumberSignDisplay fExponentSignDisplay
int8_t fEngineeringInterval
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
UNumberRoundingPriority fPriority
impl::digits_t fIncrementMagnitude
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
StringProp unitDisplayCase
IntegerWidth integerWidth
C API: Encapsulates information about a currency.
UCurrencyUsage
Currency Usage used for Decimal Format.
C API: Display options (enum types, values, helper functions)
UDisplayOptionsNounClass
Represents all the grammatical noun classes that are supported by CLDR.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
int8_t UBool
The ICU boolean type, a signed-byte integer.
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
C API: Compatibility APIs for number formatting.
UNumberFormatRoundingMode
The possible number format rounding modes.
@ UNUM_ROUND_HALFEVEN
Half-even rounding.
UNumberCompactStyle
Constants for specifying short or long format.
UNumberFormatPadPosition
The possible number format pad positions.
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.
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
@ U_ZERO_ERROR
No error, no warning.
#define U_FAILURE(x)
Does the error code indicate a failure?
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.