6 #if !UCONFIG_NO_FORMATTING 7 #ifndef __NUMBERFORMATTER_H__ 8 #define __NUMBERFORMATTER_H__ 23 #ifndef U_HIDE_DRAFT_API 83 class FieldPositionIteratorHandler;
89 class NumberParserImpl;
90 class MultiplierParseHandler;
98 class UnlocalizedNumberFormatter;
99 class LocalizedNumberFormatter;
100 class FormattedNumber;
102 class ScientificNotation;
104 class FractionPrecision;
105 class CurrencyPrecision;
106 class IncrementPrecision;
124 static constexpr int32_t DEFAULT_THRESHOLD = 3;
130 class DecimalQuantity;
131 struct UFormattedNumberData;
132 class NumberFormatterImpl;
133 struct ParsedPatternInfo;
134 class ScientificModifier;
135 class MultiplierProducer;
137 class ScientificHandler;
139 class NumberStringBuilder;
140 class AffixPatternProvider;
141 class NumberPropertyMapper;
142 struct DecimalFormatProperties;
143 class MultiplierFormatHandler;
144 class CurrencySymbols;
145 class GeneratorHelpers;
147 class NumberRangeFormatterImpl;
272 static CompactNotation compactShort();
296 static CompactNotation compactLong();
322 static SimpleNotation simple();
326 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
329 union NotationUnion {
352 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
355 fUnion.errorCode = errorCode;
358 Notation() : fType(NTN_SIMPLE), fUnion() {}
361 if (fType == NTN_ERROR) {
362 status = fUnion.errorCode;
373 friend class impl::NumberFormatterImpl;
374 friend class impl::ScientificModifier;
375 friend class impl::ScientificHandler;
378 friend class impl::GeneratorHelpers;
423 using Notation::Notation;
432 friend class impl::NumberPropertyMapper;
576 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
591 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
605 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
615 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
628 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
629 int32_t maxSignificantDigits);
631 #ifndef U_HIDE_DEPRECATED_API 637 return fixedSignificantDigits(a);
641 static inline SignificantDigitsPrecision
minDigits(int32_t a) {
642 return minSignificantDigits(a);
646 static inline SignificantDigitsPrecision
maxDigits(int32_t a) {
647 return maxSignificantDigits(a);
651 static inline SignificantDigitsPrecision
minMaxDigits(int32_t a, int32_t b) {
652 return minMaxSignificantDigits(a, b);
696 #ifndef U_HIDE_DEPRECATED_API 717 RND_FRACTION_SIGNIFICANT,
723 union PrecisionUnion {
755 Precision(
const PrecisionType& type,
const PrecisionUnion& union_,
757 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
760 fUnion.errorCode = errorCode;
765 bool isBogus()
const {
766 return fType == RND_BOGUS;
770 if (fType == RND_ERROR) {
771 status = fUnion.errorCode;
782 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
785 constructFractionSignificant(
const FractionPrecision &base, int32_t minSig, int32_t maxSig);
795 friend struct impl::MicroProps;
798 friend class impl::NumberFormatterImpl;
801 friend class impl::NumberPropertyMapper;
804 friend class impl::RoundingImpl;
812 friend class impl::GeneratorHelpers;
842 Precision withMinDigits(int32_t minSignificantDigits)
const;
861 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
865 using Precision::Precision;
903 using Precision::Precision;
935 Precision withMinFraction(int32_t minFrac)
const;
939 using Precision::Precision;
987 bool fFormatFailIfMoreThanMaxDigits;
991 bool fHasError =
false;
996 fUnion.errorCode = errorCode;
1001 fUnion.minMaxInt.fMinInt = -1;
1006 return IntegerWidth::zeroFillTo(1);
1009 bool isBogus()
const {
1010 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1015 status = fUnion.errorCode;
1021 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1027 friend struct impl::MicroProps;
1030 friend class impl::NumberFormatterImpl;
1033 friend class impl::NumberPropertyMapper;
1036 friend class impl::GeneratorHelpers;
1055 static Scale none();
1067 static Scale powerOfTen(int32_t power);
1091 static Scale byDouble(
double multiplicand);
1099 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1119 #ifndef U_HIDE_INTERNAL_API 1121 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1126 impl::DecNum* fArbitrary;
1129 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1133 bool isValid()
const {
1134 return fMagnitude != 0 || fArbitrary !=
nullptr;
1145 void applyTo(impl::DecimalQuantity& quantity)
const;
1147 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1151 friend struct impl::MicroProps;
1154 friend class impl::NumberFormatterImpl;
1157 friend class impl::MultiplierFormatHandler;
1160 friend class impl::GeneratorHelpers;
1163 friend class ::icu::numparse::impl::NumberParserImpl;
1164 friend class ::icu::numparse::impl::MultiplierParseHandler;
1191 #ifndef U_HIDE_INTERNAL_API 1209 bool isDecimalFormatSymbols()
const;
1215 bool isNumberingSystem()
const;
1229 #endif // U_HIDE_INTERNAL_API 1233 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1236 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1244 enum SymbolsPointerType {
1245 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1264 #ifndef U_HIDE_INTERNAL_API 1272 static Grouper forProperties(
const DecimalFormatProperties& properties);
1278 : fGrouping1(grouping1),
1279 fGrouping2(grouping2),
1280 fMinGrouping(minGrouping),
1281 fStrategy(strategy) {}
1282 #endif // U_HIDE_INTERNAL_API 1285 int16_t getPrimary()
const;
1288 int16_t getSecondary()
const;
1309 int16_t fMinGrouping;
1317 Grouper() : fGrouping1(-3) {};
1319 bool isBogus()
const {
1320 return fGrouping1 == -3;
1324 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1326 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1330 friend struct MicroProps;
1333 friend class NumberFormatterImpl;
1336 friend class ::icu::numparse::impl::NumberParserImpl;
1339 friend class impl::GeneratorHelpers;
1346 #ifndef U_HIDE_INTERNAL_API 1352 #endif // U_HIDE_INTERNAL_API 1355 static Padder forProperties(
const DecimalFormatProperties& properties);
1372 fUnion.errorCode = errorCode;
1377 bool isBogus()
const {
1378 return fWidth == -2;
1383 status = fUnion.errorCode;
1389 bool isValid()
const {
1393 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1394 impl::NumberStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1399 friend struct MicroProps;
1402 friend class impl::NumberFormatterImpl;
1405 friend class impl::GeneratorHelpers;
1453 const AffixPatternProvider* affixProvider =
nullptr;
1459 const CurrencySymbols* currencySymbols =
nullptr;
1462 int32_t threshold = DEFAULT_THRESHOLD;
1474 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1475 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1476 symbols.
copyErrorTo(status) || scale.copyErrorTo(status);
1487 template<
typename Derived>
1518 Derived notation(
const Notation ¬ation)
const &;
1529 Derived notation(
const Notation ¬ation) &&;
1706 Derived precision(
const Precision& precision)
const &;
1717 Derived precision(
const Precision& precision) &&;
1719 #ifndef U_HIDE_DEPRECATED_API 1725 return precision(rounder);
1823 Derived integerWidth(
const IntegerWidth &style)
const &;
2073 Derived scale(
const Scale &scale)
const &;
2084 Derived scale(
const Scale &scale) &&;
2086 #ifndef U_HIDE_INTERNAL_API 2104 Derived threshold(int32_t threshold)
const &;
2107 Derived threshold(int32_t threshold) &&;
2154 fMacros.copyErrorTo(outErrorCode);
2171 friend class impl::NumberRangeFormatterImpl;
2303 #ifndef U_HIDE_INTERNAL_API 2319 const impl::NumberFormatterImpl* getCompiled()
const;
2325 int32_t getCallCount()
const;
2377 #ifndef U_HIDE_INTERNAL_API 2391 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2404 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2405 char fUnsafeCallCount[8] {};
2422 bool computeCompiled(
UErrorCode& status)
const;
2429 friend class UnlocalizedNumberFormatter;
2440 #ifndef U_HIDE_DEPRECATED_API 2462 #ifndef U_HIDE_DEPRECATED_API 2490 #ifndef U_HIDE_DEPRECATED_API 2547 #ifndef U_HIDE_DEPRECATED_API 2581 #ifndef U_HIDE_INTERNAL_API 2587 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2593 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2629 const impl::UFormattedNumberData *fResults;
2642 : fResults(
nullptr), fErrorCode(errorCode) {};
2697 #endif // U_HIDE_DRAFT_API 2699 #endif // __NUMBERFORMATTER_H__
UNumberFormatRoundingMode
The possible number format rounding modes.
static SignificantDigitsPrecision minDigits(int32_t a)
A unit such as length, mass, volume, currency, etc.
C++ API: Currency Unit Information.
static SignificantDigitsPrecision fixedDigits(int32_t a)
#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.
static SignificantDigitsPrecision minMaxDigits(int32_t a, int32_t b)
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.
static SignificantDigitsPrecision maxDigits(int32_t a)
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.
#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.
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...
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...
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.