6 #if !UCONFIG_NO_FORMATTING 7 #ifndef __NUMBERFORMATTER_H__ 8 #define __NUMBERFORMATTER_H__ 25 #ifndef U_HIDE_DRAFT_API 87 class FieldPositionIteratorHandler;
93 class NumberParserImpl;
94 class MultiplierParseHandler;
102 class UnlocalizedNumberFormatter;
103 class LocalizedNumberFormatter;
104 class FormattedNumber;
106 class ScientificNotation;
108 class FractionPrecision;
109 class CurrencyPrecision;
110 class IncrementPrecision;
130 static constexpr int32_t kInternalDefaultThreshold = 3;
136 class DecimalQuantity;
137 class UFormattedNumberData;
138 class NumberFormatterImpl;
139 struct ParsedPatternInfo;
140 class ScientificModifier;
141 class MultiplierProducer;
143 class ScientificHandler;
145 class NumberStringBuilder;
146 class AffixPatternProvider;
147 class NumberPropertyMapper;
148 struct DecimalFormatProperties;
149 class MultiplierFormatHandler;
150 class CurrencySymbols;
151 class GeneratorHelpers;
153 class NumberRangeFormatterImpl;
155 struct UFormattedNumberImpl;
279 static CompactNotation compactShort();
303 static CompactNotation compactLong();
329 static SimpleNotation simple();
333 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
336 union NotationUnion {
359 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
362 fUnion.errorCode = errorCode;
365 Notation() : fType(NTN_SIMPLE), fUnion() {}
368 if (fType == NTN_ERROR) {
369 status = fUnion.errorCode;
380 friend class impl::NumberFormatterImpl;
381 friend class impl::ScientificModifier;
382 friend class impl::ScientificHandler;
385 friend class impl::GeneratorHelpers;
430 using Notation::Notation;
439 friend class impl::NumberPropertyMapper;
556 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
571 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
585 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
595 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
608 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
609 int32_t maxSignificantDigits);
657 RND_FRACTION_SIGNIFICANT,
674 union PrecisionUnion {
707 Precision(
const PrecisionType& type,
const PrecisionUnion& union_,
709 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
712 fUnion.errorCode = errorCode;
717 bool isBogus()
const {
718 return fType == RND_BOGUS;
722 if (fType == RND_ERROR) {
723 status = fUnion.errorCode;
734 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
737 constructFractionSignificant(
const FractionPrecision &base, int32_t minSig, int32_t maxSig);
747 friend struct impl::MicroProps;
750 friend class impl::NumberFormatterImpl;
753 friend class impl::NumberPropertyMapper;
756 friend class impl::RoundingImpl;
764 friend class impl::GeneratorHelpers;
794 Precision withMinDigits(int32_t minSignificantDigits)
const;
813 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
817 using Precision::Precision;
855 using Precision::Precision;
887 Precision withMinFraction(int32_t minFrac)
const;
891 using Precision::Precision;
939 bool fFormatFailIfMoreThanMaxDigits;
943 bool fHasError =
false;
948 fUnion.errorCode = errorCode;
953 fUnion.minMaxInt.fMinInt = -1;
958 return IntegerWidth::zeroFillTo(1);
961 bool isBogus()
const {
962 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
967 status = fUnion.errorCode;
973 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
979 friend struct impl::MicroProps;
982 friend class impl::NumberFormatterImpl;
985 friend class impl::NumberPropertyMapper;
988 friend class impl::GeneratorHelpers;
1007 static Scale none();
1019 static Scale powerOfTen(int32_t power);
1043 static Scale byDouble(
double multiplicand);
1051 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1071 #ifndef U_HIDE_INTERNAL_API 1073 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1078 impl::DecNum* fArbitrary;
1081 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1085 bool isValid()
const {
1086 return fMagnitude != 0 || fArbitrary !=
nullptr;
1097 void applyTo(impl::DecimalQuantity& quantity)
const;
1099 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1103 friend struct impl::MicroProps;
1106 friend class impl::NumberFormatterImpl;
1109 friend class impl::MultiplierFormatHandler;
1112 friend class impl::GeneratorHelpers;
1115 friend class ::icu::numparse::impl::NumberParserImpl;
1116 friend class ::icu::numparse::impl::MultiplierParseHandler;
1143 #ifndef U_HIDE_INTERNAL_API 1161 bool isDecimalFormatSymbols()
const;
1167 bool isNumberingSystem()
const;
1181 #endif // U_HIDE_INTERNAL_API 1185 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1188 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1196 enum SymbolsPointerType {
1197 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1216 #ifndef U_HIDE_INTERNAL_API 1224 static Grouper forProperties(
const DecimalFormatProperties& properties);
1230 : fGrouping1(grouping1),
1231 fGrouping2(grouping2),
1232 fMinGrouping(minGrouping),
1233 fStrategy(strategy) {}
1234 #endif // U_HIDE_INTERNAL_API 1237 int16_t getPrimary()
const;
1240 int16_t getSecondary()
const;
1261 int16_t fMinGrouping;
1271 bool isBogus()
const {
1272 return fGrouping1 == -3;
1276 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1278 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1282 friend struct MicroProps;
1285 friend class NumberFormatterImpl;
1288 friend class ::icu::numparse::impl::NumberParserImpl;
1291 friend class impl::GeneratorHelpers;
1298 #ifndef U_HIDE_INTERNAL_API 1304 #endif // U_HIDE_INTERNAL_API 1307 static Padder forProperties(
const DecimalFormatProperties& properties);
1324 fUnion.errorCode = errorCode;
1329 bool isBogus()
const {
1330 return fWidth == -2;
1335 status = fUnion.errorCode;
1341 bool isValid()
const {
1345 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1346 impl::NumberStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1351 friend struct MicroProps;
1354 friend class impl::NumberFormatterImpl;
1357 friend class impl::GeneratorHelpers;
1405 const AffixPatternProvider* affixProvider =
nullptr;
1411 const CurrencySymbols* currencySymbols =
nullptr;
1414 int32_t threshold = kInternalDefaultThreshold;
1426 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1427 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1428 symbols.
copyErrorTo(status) || scale.copyErrorTo(status);
1439 template<
typename Derived>
1470 Derived notation(
const Notation ¬ation)
const &;
1481 Derived notation(
const Notation ¬ation) &&;
1656 Derived precision(
const Precision& precision)
const &;
1667 Derived precision(
const Precision& precision) &&;
1763 Derived integerWidth(
const IntegerWidth &style)
const &;
2013 Derived scale(
const Scale &scale)
const &;
2024 Derived scale(
const Scale &scale) &&;
2026 #ifndef U_HIDE_INTERNAL_API 2044 Derived threshold(int32_t threshold)
const &;
2047 Derived threshold(int32_t threshold) &&;
2116 fMacros.copyErrorTo(outErrorCode);
2133 friend class impl::NumberRangeFormatterImpl;
2269 #ifndef U_HIDE_INTERNAL_API 2285 const impl::NumberFormatterImpl* getCompiled()
const;
2291 int32_t getCallCount()
const;
2343 #ifndef U_HIDE_INTERNAL_API 2357 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2370 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2371 char fUnsafeCallCount[8] {};
2388 bool computeCompiled(
UErrorCode& status)
const;
2395 friend class UnlocalizedNumberFormatter;
2520 #ifndef U_HIDE_INTERNAL_API 2526 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2532 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2538 const impl::UFormattedNumberData *fData;
2551 : fData(
nullptr), fErrorCode(errorCode) {}
2557 friend struct impl::UFormattedNumberImpl;
2632 #endif // U_HIDE_DRAFT_API 2634 #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.
#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...
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.
UNumberSignDisplay fExponentSignDisplay
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
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.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
impl::digits_t fMinExponentDigits
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
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.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
#define TRUE
The TRUE value of a UBool.
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.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
UNumberCompactStyle
Constants for specifying short or long format.
C API: Parse Error Information.
A class that defines a quantity by which a number should be multiplied when formatting.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
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.
#define FALSE
The FALSE value of a UBool.
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)
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
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
int8_t UBool
The ICU boolean type.
Base class for objects to which Unicode characters and strings can be appended.
C API: Compatibility APIs for number formatting.
UBool copyErrorTo(UErrorCode &status) const
A Locale object represents a specific geographical, political, or cultural region.