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;
306 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
309 union NotationUnion {
312 int8_t fEngineeringInterval;
327 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
330 fUnion.errorCode = errorCode;
333 Notation() : fType(NTN_SIMPLE), fUnion() {}
336 if (fType == NTN_ERROR) {
337 status = fUnion.errorCode;
344 friend struct impl::MacroProps;
345 friend class ScientificNotation;
348 friend class impl::NumberFormatterImpl;
349 friend class impl::ScientificModifier;
350 friend class impl::ScientificHandler;
353 friend class impl::GeneratorHelpers;
398 using Notation::Notation;
407 friend class impl::NumberPropertyMapper;
527 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
580 int32_t maxSignificantDigits);
582 #ifndef U_HIDE_DEPRECATED_API 588 return fixedSignificantDigits(a);
593 return minSignificantDigits(a);
598 return maxSignificantDigits(a);
603 return minMaxSignificantDigits(a, b);
647 #ifndef U_HIDE_DEPRECATED_API 668 RND_FRACTION_SIGNIFICANT,
674 union PrecisionUnion {
697 Precision(
const PrecisionType& type,
const PrecisionUnion& union_,
699 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
702 fUnion.errorCode = errorCode;
705 Precision() : fType(RND_BOGUS) {}
707 bool isBogus()
const {
708 return fType == RND_BOGUS;
712 if (fType == RND_ERROR) {
713 status = fUnion.errorCode;
720 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
722 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
724 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
727 constructFractionSignificant(
const FractionPrecision &base, int32_t minSig, int32_t maxSig);
729 static IncrementPrecision constructIncrement(
double increment, int32_t minFrac);
733 static Precision constructPassThrough();
736 friend struct impl::MacroProps;
737 friend struct impl::MicroProps;
740 friend class impl::NumberFormatterImpl;
743 friend class impl::NumberPropertyMapper;
746 friend class impl::RoundingImpl;
749 friend class FractionPrecision;
750 friend class CurrencyPrecision;
751 friend class IncrementPrecision;
754 friend class impl::GeneratorHelpers;
784 Precision withMinDigits(int32_t minSignificantDigits)
const;
803 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
807 using Precision::Precision;
845 using Precision::Precision;
877 Precision withMinFraction(int32_t minFrac)
const;
881 using Precision::Precision;
929 bool fFormatFailIfMoreThanMaxDigits;
933 bool fHasError =
false;
938 fUnion.errorCode = errorCode;
943 fUnion.minMaxInt.fMinInt = -1;
948 return IntegerWidth::zeroFillTo(1);
951 bool isBogus()
const {
952 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
957 status = fUnion.errorCode;
963 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
969 friend struct impl::MicroProps;
972 friend class impl::NumberFormatterImpl;
975 friend class impl::NumberPropertyMapper;
978 friend class impl::GeneratorHelpers;
1009 static Scale powerOfTen(int32_t power);
1033 static Scale byDouble(
double multiplicand);
1041 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1061 #ifndef U_HIDE_INTERNAL_API 1063 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1068 impl::DecNum* fArbitrary;
1071 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1075 bool isValid()
const {
1076 return fMagnitude != 0 || fArbitrary !=
nullptr;
1087 void applyTo(impl::DecimalQuantity& quantity)
const;
1089 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1093 friend struct impl::MicroProps;
1096 friend class impl::NumberFormatterImpl;
1099 friend class impl::MultiplierFormatHandler;
1102 friend class impl::GeneratorHelpers;
1105 friend class ::icu::numparse::impl::NumberParserImpl;
1106 friend class ::icu::numparse::impl::MultiplierParseHandler;
1119 SymbolsWrapper(
const SymbolsWrapper &other);
1122 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1125 SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
1128 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
1133 #ifndef U_HIDE_INTERNAL_API 1151 bool isDecimalFormatSymbols()
const;
1157 bool isNumberingSystem()
const;
1171 #endif // U_HIDE_INTERNAL_API 1175 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1178 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1186 enum SymbolsPointerType {
1187 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1195 void doCopyFrom(
const SymbolsWrapper &other);
1197 void doMoveFrom(SymbolsWrapper&& src);
1206 #ifndef U_HIDE_INTERNAL_API 1214 static Grouper forProperties(
const DecimalFormatProperties& properties);
1220 : fGrouping1(grouping1),
1221 fGrouping2(grouping2),
1222 fMinGrouping(minGrouping),
1223 fStrategy(strategy) {}
1224 #endif // U_HIDE_INTERNAL_API 1227 int16_t getPrimary()
const;
1230 int16_t getSecondary()
const;
1251 int16_t fMinGrouping;
1259 Grouper() : fGrouping1(-3) {};
1261 bool isBogus()
const {
1262 return fGrouping1 == -3;
1266 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1268 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1271 friend struct MacroProps;
1272 friend struct MicroProps;
1275 friend class NumberFormatterImpl;
1278 friend class ::icu::numparse::impl::NumberParserImpl;
1281 friend class impl::GeneratorHelpers;
1288 #ifndef U_HIDE_INTERNAL_API 1294 #endif // U_HIDE_INTERNAL_API 1297 static Padder forProperties(
const DecimalFormatProperties& properties);
1314 fUnion.errorCode = errorCode;
1319 bool isBogus()
const {
1320 return fWidth == -2;
1325 status = fUnion.errorCode;
1331 bool isValid()
const {
1335 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1336 impl::NumberStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1341 friend struct MicroProps;
1344 friend class impl::NumberFormatterImpl;
1347 friend class impl::GeneratorHelpers;
1395 const AffixPatternProvider* affixProvider =
nullptr;
1401 const CurrencySymbols* currencySymbols =
nullptr;
1404 int32_t threshold = DEFAULT_THRESHOLD;
1416 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1417 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1418 symbols.
copyErrorTo(status) || scale.copyErrorTo(status);
1428 template<
typename Derived>
1459 Derived notation(
const Notation ¬ation)
const &;
1470 Derived notation(
const Notation ¬ation) &&;
1647 Derived precision(
const Precision& precision)
const &;
1658 Derived precision(
const Precision& precision) &&;
1660 #ifndef U_HIDE_DEPRECATED_API 1666 return precision(rounder);
1765 Derived integerWidth(
const IntegerWidth &style)
const &;
2015 Derived scale(
const Scale &scale)
const &;
2026 Derived scale(
const Scale &scale) &&;
2028 #ifndef U_HIDE_INTERNAL_API 2046 Derived threshold(int32_t threshold)
const &;
2049 Derived threshold(int32_t threshold) &&;
2096 fMacros.copyErrorTo(outErrorCode);
2250 #ifndef U_HIDE_INTERNAL_API 2266 const impl::NumberFormatterImpl* getCompiled()
const;
2272 int32_t getCallCount()
const;
2325 #ifndef U_HIDE_INTERNAL_API 2338 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2351 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2352 char fUnsafeCallCount[8] {};
2367 bool computeCompiled(
UErrorCode& status)
const;
2385 #ifndef U_HIDE_DEPRECATED_API 2407 #ifndef U_HIDE_DEPRECATED_API 2435 #ifndef U_HIDE_DEPRECATED_API 2492 #ifndef U_HIDE_DEPRECATED_API 2526 #ifndef U_HIDE_INTERNAL_API 2532 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2538 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2574 const impl::UFormattedNumberData *fResults;
2587 : fResults(
nullptr), fErrorCode(errorCode) {};
2642 #endif // U_HIDE_DRAFT_API 2644 #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)
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UGroupingStrategy strategy)
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.
#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.
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...
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...
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.