4 #ifndef __NUMBERFORMATTER_H__
5 #define __NUMBERFORMATTER_H__
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/unounclass.h"
89 class FieldPositionIteratorHandler;
90 class FormattedStringBuilder;
96 class NumberParserImpl;
97 class MultiplierParseHandler;
112 class UnlocalizedNumberFormatter;
113 class LocalizedNumberFormatter;
114 class FormattedNumber;
116 class ScientificNotation;
118 class FractionPrecision;
119 class CurrencyPrecision;
120 class IncrementPrecision;
131 typedef int16_t digits_t;
140 static constexpr int32_t kInternalDefaultThreshold = 3;
146 class DecimalQuantity;
147 class UFormattedNumberData;
148 class NumberFormatterImpl;
149 struct ParsedPatternInfo;
150 class ScientificModifier;
151 class MultiplierProducer;
153 class ScientificHandler;
155 class AffixPatternProvider;
156 class NumberPropertyMapper;
157 struct DecimalFormatProperties;
158 class MultiplierFormatHandler;
159 class CurrencySymbols;
160 class GeneratorHelpers;
162 class NumberRangeFormatterImpl;
163 struct RangeMacroProps;
164 struct UFormattedNumberImpl;
165 class MutablePatternModifier;
166 class ImmutablePatternModifier;
167 struct DecimalFormatWarehouse;
175 void touchRangeLocales(impl::RangeMacroProps& macros);
184 typedef Notation CompactNotation;
191 typedef Notation SimpleNotation;
345 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
348 union NotationUnion {
371 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
374 fUnion.errorCode = errorCode;
377 Notation() : fType(NTN_SIMPLE), fUnion() {}
380 if (fType == NTN_ERROR) {
381 status = fUnion.errorCode;
388 friend struct impl::MacroProps;
389 friend class ScientificNotation;
392 friend class impl::NumberFormatterImpl;
393 friend class impl::ScientificModifier;
394 friend class impl::ScientificHandler;
397 friend class impl::GeneratorHelpers;
442 using Notation::Notation;
445 ScientificNotation(int8_t fEngineeringInterval,
bool fRequireMinInt, impl::digits_t fMinExponentDigits,
451 friend class impl::NumberPropertyMapper;
568 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
621 int32_t maxSignificantDigits);
644 #ifndef U_HIDE_DRAFT_API
669 #endif // U_HIDE_DRAFT_API
705 RND_FRACTION_SIGNIFICANT,
722 union PrecisionUnion {
763 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
764 : fType(type), fUnion(union_) {}
767 fUnion.errorCode = errorCode;
770 Precision() : fType(RND_BOGUS) {}
772 bool isBogus()
const {
773 return fType == RND_BOGUS;
777 if (fType == RND_ERROR) {
778 status = fUnion.errorCode;
785 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
787 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
789 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
791 static Precision constructFractionSignificant(
792 const FractionPrecision &base,
798 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
803 friend struct impl::MacroProps;
804 friend struct impl::MicroProps;
807 friend class impl::NumberFormatterImpl;
810 friend class impl::NumberPropertyMapper;
813 friend class impl::RoundingImpl;
816 friend class FractionPrecision;
817 friend class CurrencyPrecision;
818 friend class IncrementPrecision;
821 friend class impl::GeneratorHelpers;
824 friend class units::UnitsRouter;
853 int32_t minSignificantDigits,
854 int32_t maxSignificantDigits,
874 Precision withMinDigits(int32_t minSignificantDigits)
const;
893 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
897 using Precision::Precision;
935 using Precision::Precision;
967 Precision withMinFraction(int32_t minFrac)
const;
971 using Precision::Precision;
1017 impl::digits_t fMinInt;
1018 impl::digits_t fMaxInt;
1019 bool fFormatFailIfMoreThanMaxDigits;
1023 bool fHasError =
false;
1025 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt,
bool formatFailIfMoreThanMaxDigits);
1028 fUnion.errorCode = errorCode;
1033 fUnion.minMaxInt.fMinInt = -1;
1038 return IntegerWidth::zeroFillTo(1);
1041 bool isBogus()
const {
1042 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1047 status = fUnion.errorCode;
1053 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1059 friend struct impl::MicroProps;
1062 friend class impl::NumberFormatterImpl;
1065 friend class impl::MutablePatternModifier;
1066 friend class impl::ImmutablePatternModifier;
1069 friend class impl::NumberPropertyMapper;
1072 friend class impl::GeneratorHelpers;
1091 static Scale none();
1103 static Scale powerOfTen(int32_t power);
1127 static Scale byDouble(
double multiplicand);
1135 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1155 #ifndef U_HIDE_INTERNAL_API
1157 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1162 impl::DecNum* fArbitrary;
1165 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1169 bool isValid()
const {
1170 return fMagnitude != 0 || fArbitrary !=
nullptr;
1181 void applyTo(impl::DecimalQuantity& quantity)
const;
1183 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1187 friend struct impl::MicroProps;
1190 friend class impl::NumberFormatterImpl;
1193 friend class impl::MultiplierFormatHandler;
1196 friend class impl::GeneratorHelpers;
1199 friend class ::icu::numparse::impl::NumberParserImpl;
1200 friend class ::icu::numparse::impl::MultiplierParseHandler;
1223 #ifndef U_HIDE_INTERNAL_API
1246 #endif // U_HIDE_INTERNAL_API
1266 friend class impl::NumberFormatterImpl;
1269 friend class impl::GeneratorHelpers;
1273 friend struct impl::MacroProps;
1284 SymbolsWrapper(
const SymbolsWrapper &other);
1287 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1290 SymbolsWrapper(SymbolsWrapper&& src)
U_NOEXCEPT;
1293 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
1298 #ifndef U_HIDE_INTERNAL_API
1316 bool isDecimalFormatSymbols()
const;
1322 bool isNumberingSystem()
const;
1336 #endif // U_HIDE_INTERNAL_API
1340 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1343 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1351 enum SymbolsPointerType {
1352 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1360 void doCopyFrom(
const SymbolsWrapper &other);
1362 void doMoveFrom(SymbolsWrapper&& src);
1371 #ifndef U_HIDE_INTERNAL_API
1379 static Grouper forProperties(
const DecimalFormatProperties& properties);
1385 : fGrouping1(grouping1),
1386 fGrouping2(grouping2),
1387 fMinGrouping(minGrouping),
1388 fStrategy(strategy) {}
1391 int16_t getPrimary()
const;
1394 int16_t getSecondary()
const;
1395 #endif // U_HIDE_INTERNAL_API
1416 int16_t fMinGrouping;
1426 bool isBogus()
const {
1427 return fGrouping1 == -3;
1431 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1433 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1436 friend struct MacroProps;
1437 friend struct MicroProps;
1440 friend class NumberFormatterImpl;
1443 friend class ::icu::numparse::impl::NumberParserImpl;
1446 friend class impl::GeneratorHelpers;
1453 #ifndef U_HIDE_INTERNAL_API
1461 static Padder forProperties(
const DecimalFormatProperties& properties);
1462 #endif // U_HIDE_INTERNAL_API
1479 fUnion.errorCode = errorCode;
1484 bool isBogus()
const {
1485 return fWidth == -2;
1490 status = fUnion.errorCode;
1496 bool isValid()
const {
1500 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1501 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1506 friend struct MicroProps;
1509 friend class impl::NumberFormatterImpl;
1512 friend class impl::GeneratorHelpers;
1554 bool approximately =
false;
1569 const AffixPatternProvider* affixProvider =
nullptr;
1575 int32_t threshold = kInternalDefaultThreshold;
1587 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1588 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1589 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1590 unitDisplayCase.copyErrorTo(status);
1596 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1602 #pragma warning(push)
1603 #pragma warning(disable: 4661)
1611 template<
typename Derived>
1642 Derived notation(
const Notation ¬ation)
const &;
1653 Derived notation(
const Notation ¬ation) &&;
1833 Derived precision(
const Precision& precision)
const &;
1844 Derived precision(
const Precision& precision) &&;
1940 Derived integerWidth(
const IntegerWidth &style)
const &;
2190 Derived scale(
const Scale &scale)
const &;
2201 Derived scale(
const Scale &scale) &&;
2256 #ifndef U_HIDE_DRAFT_API
2257 #ifndef U_HIDE_INTERNAL_API
2264 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2271 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2272 #endif // U_HIDE_INTERNAL_API
2273 #endif // U_HIDE_DRAFT_API
2275 #ifndef U_HIDE_INTERNAL_API
2293 Derived threshold(int32_t threshold)
const &;
2296 Derived threshold(int32_t threshold) &&;
2368 fMacros.copyErrorTo(outErrorCode);
2385 friend class impl::NumberRangeFormatterImpl;
2521 #ifndef U_HIDE_INTERNAL_API
2543 const impl::NumberFormatterImpl* getCompiled()
const;
2549 int32_t getCallCount()
const;
2601 #ifndef U_HIDE_INTERNAL_API
2615 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2628 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2629 char fUnsafeCallCount[8] {};
2633 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2643 void resetCompiled();
2652 bool computeCompiled(
UErrorCode& status)
const;
2659 friend class UnlocalizedNumberFormatter;
2662 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2664 #pragma warning(pop)
2755 template<typename StringClass>
2756 inline StringClass toDecimalNumber(
UErrorCode& status) const;
2771 #ifndef U_HIDE_DRAFT_API
2782 #endif // U_HIDE_DRAFT_API
2784 #ifndef U_HIDE_INTERNAL_API
2790 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2796 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2800 #ifndef U_HIDE_DEPRECATED_API
2808 const char *getGender(
UErrorCode &status)
const;
2814 const impl::UFormattedNumberData *fData;
2826 explicit FormattedNumber(
UErrorCode errorCode)
2827 : fData(nullptr), fErrorCode(errorCode) {}
2829 void toDecimalNumber(ByteSink& sink,
UErrorCode& status)
const;
2832 friend class LocalizedNumberFormatter;
2835 friend struct impl::UFormattedNumberImpl;
2838 template<
typename StringClass>
2839 StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2842 toDecimalNumber(sink, status);
2928 #endif // __NUMBERFORMATTER_H__
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
UNumberFormatRoundingMode
The possible number format rounding modes.
A unit such as length, mass, volume, currency, etc.
C++ API: Currency Unit Information.
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
#define U_FAILURE(x)
Does the error code indicate a failure?
A class that defines the strategy for padding and truncating integers before the decimal separator...
NounClass
Represents all the grammatical noun classes that are supported by CLDR.
C++ API: FieldPosition Iterator.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Defines numbering systems.
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
C++ API: units for percent and permille.
C++ API: PluralRules object.
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Defines rules for mapping non-negative numeric values onto a small set of keywords.
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
UNumberSignDisplay fExponentSignDisplay
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
StringProp unitDisplayCase
C++ API: FieldPosition identifies the fields in a formatted output.
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
impl::digits_t fMinExponentDigits
C++ API: Interface for writing bytes, and implementation classes.
IntegerWidth integerWidth
C++ API: A unit for measuring a quantity.
C API: Encapsulates information about a currency.
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
UCurrencyUsage
Currency Usage used for Decimal Format.
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
impl::digits_t fIncrementMagnitude
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
A unit of currency, such as USD (U.S.
UNumberFormatPadPosition
The possible number format pad positions.
C++ API: Common ICU base class UObject.
Represents a span of a string containing a given field.
UNumberCompactStyle
Constants for specifying short or long format.
C API: Parse Error Information.
UBool copyErrorTo(UErrorCode &status) const
A class that defines a quantity by which a number should be multiplied when formatting.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
C++ API: Symbols for formatting numbers.
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
A UParseError struct is used to returned detailed information about parsing errors.
Basic definitions for ICU, for both C and C++ APIs.
Implementation of ByteSink that writes to a "string".
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
UNumberRoundingPriority fPriority
A string-like object that points to a sized piece of memory.
UMemory is the common ICU base class.
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter...
Requested operation can not be completed with ICU in its current state.
int8_t fEngineeringInterval
int8_t UBool
The ICU boolean type, a signed-byte integer.
Base class for objects to which Unicode characters and strings can be appended.
C API: Compatibility APIs for number formatting.
A Locale object represents a specific geographical, political, or cultural region.