4 #ifndef __NUMBERFORMATTER_H__
5 #define __NUMBERFORMATTER_H__
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_FORMATTING
89 class FieldPositionIteratorHandler;
90 class FormattedStringBuilder;
96 class NumberParserImpl;
97 class MultiplierParseHandler;
105 class UnlocalizedNumberFormatter;
106 class LocalizedNumberFormatter;
107 class FormattedNumber;
109 class ScientificNotation;
111 class FractionPrecision;
112 class CurrencyPrecision;
113 class IncrementPrecision;
133 static constexpr int32_t kInternalDefaultThreshold = 3;
139 class DecimalQuantity;
140 class UFormattedNumberData;
141 class NumberFormatterImpl;
142 struct ParsedPatternInfo;
143 class ScientificModifier;
144 class MultiplierProducer;
146 class ScientificHandler;
148 class AffixPatternProvider;
149 class NumberPropertyMapper;
150 struct DecimalFormatProperties;
151 class MultiplierFormatHandler;
152 class CurrencySymbols;
153 class GeneratorHelpers;
155 class NumberRangeFormatterImpl;
157 struct UFormattedNumberImpl;
158 class MutablePatternModifier;
159 class ImmutablePatternModifier;
337 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
340 union NotationUnion {
363 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
366 fUnion.errorCode = errorCode;
369 Notation() : fType(NTN_SIMPLE), fUnion() {}
372 if (fType == NTN_ERROR) {
373 status = fUnion.errorCode;
380 friend struct impl::MacroProps;
381 friend class ScientificNotation;
384 friend class impl::NumberFormatterImpl;
385 friend class impl::ScientificModifier;
386 friend class impl::ScientificHandler;
389 friend class impl::GeneratorHelpers;
434 using Notation::Notation;
443 friend class impl::NumberPropertyMapper;
560 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
613 int32_t maxSignificantDigits);
661 RND_FRACTION_SIGNIFICANT,
678 union PrecisionUnion {
711 Precision(
const PrecisionType& type,
const PrecisionUnion& union_,
713 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
716 fUnion.errorCode = errorCode;
719 Precision() : fType(RND_BOGUS) {}
721 bool isBogus()
const {
722 return fType == RND_BOGUS;
726 if (fType == RND_ERROR) {
727 status = fUnion.errorCode;
734 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
736 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
738 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
741 constructFractionSignificant(
const FractionPrecision &base, int32_t minSig, int32_t maxSig);
743 static IncrementPrecision constructIncrement(
double increment, int32_t minFrac);
747 static Precision constructPassThrough();
750 friend struct impl::MacroProps;
751 friend struct impl::MicroProps;
754 friend class impl::NumberFormatterImpl;
757 friend class impl::NumberPropertyMapper;
760 friend class impl::RoundingImpl;
763 friend class FractionPrecision;
764 friend class CurrencyPrecision;
765 friend class IncrementPrecision;
768 friend class impl::GeneratorHelpers;
798 Precision withMinDigits(int32_t minSignificantDigits)
const;
817 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
821 using Precision::Precision;
859 using Precision::Precision;
891 Precision withMinFraction(int32_t minFrac)
const;
895 using Precision::Precision;
943 bool fFormatFailIfMoreThanMaxDigits;
947 bool fHasError =
false;
952 fUnion.errorCode = errorCode;
957 fUnion.minMaxInt.fMinInt = -1;
962 return IntegerWidth::zeroFillTo(1);
965 bool isBogus()
const {
966 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
971 status = fUnion.errorCode;
977 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
983 friend struct impl::MicroProps;
986 friend class impl::NumberFormatterImpl;
989 friend class impl::MutablePatternModifier;
990 friend class impl::ImmutablePatternModifier;
993 friend class impl::NumberPropertyMapper;
996 friend class impl::GeneratorHelpers;
1015 static Scale none();
1027 static Scale powerOfTen(int32_t power);
1051 static Scale byDouble(
double multiplicand);
1059 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1079 #ifndef U_HIDE_INTERNAL_API
1081 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1086 impl::DecNum* fArbitrary;
1089 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1093 bool isValid()
const {
1094 return fMagnitude != 0 || fArbitrary !=
nullptr;
1105 void applyTo(impl::DecimalQuantity& quantity)
const;
1107 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1111 friend struct impl::MicroProps;
1114 friend class impl::NumberFormatterImpl;
1117 friend class impl::MultiplierFormatHandler;
1120 friend class impl::GeneratorHelpers;
1123 friend class ::icu::numparse::impl::NumberParserImpl;
1124 friend class ::icu::numparse::impl::MultiplierParseHandler;
1137 SymbolsWrapper(
const SymbolsWrapper &other);
1140 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1143 SymbolsWrapper(SymbolsWrapper&& src)
U_NOEXCEPT;
1146 SymbolsWrapper &operator=(SymbolsWrapper&& src)
U_NOEXCEPT;
1151 #ifndef U_HIDE_INTERNAL_API
1169 bool isDecimalFormatSymbols()
const;
1175 bool isNumberingSystem()
const;
1189 #endif // U_HIDE_INTERNAL_API
1193 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1196 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1204 enum SymbolsPointerType {
1205 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1213 void doCopyFrom(
const SymbolsWrapper &other);
1215 void doMoveFrom(SymbolsWrapper&& src);
1224 #ifndef U_HIDE_INTERNAL_API
1232 static Grouper forProperties(
const DecimalFormatProperties& properties);
1238 : fGrouping1(grouping1),
1239 fGrouping2(grouping2),
1240 fMinGrouping(minGrouping),
1241 fStrategy(strategy) {}
1242 #endif // U_HIDE_INTERNAL_API
1245 int16_t getPrimary()
const;
1248 int16_t getSecondary()
const;
1269 int16_t fMinGrouping;
1279 bool isBogus()
const {
1280 return fGrouping1 == -3;
1284 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1286 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1289 friend struct MacroProps;
1290 friend struct MicroProps;
1293 friend class NumberFormatterImpl;
1296 friend class ::icu::numparse::impl::NumberParserImpl;
1299 friend class impl::GeneratorHelpers;
1306 #ifndef U_HIDE_INTERNAL_API
1312 #endif // U_HIDE_INTERNAL_API
1315 static Padder forProperties(
const DecimalFormatProperties& properties);
1332 fUnion.errorCode = errorCode;
1337 bool isBogus()
const {
1338 return fWidth == -2;
1343 status = fUnion.errorCode;
1349 bool isValid()
const {
1353 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1354 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1359 friend struct MicroProps;
1362 friend class impl::NumberFormatterImpl;
1365 friend class impl::GeneratorHelpers;
1413 const AffixPatternProvider* affixProvider =
nullptr;
1419 int32_t threshold = kInternalDefaultThreshold;
1431 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1432 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1433 symbols.
copyErrorTo(status) || scale.copyErrorTo(status);
1439 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1445 #pragma warning(push)
1446 #pragma warning(disable: 4661)
1454 template<
typename Derived>
1485 Derived notation(
const Notation ¬ation)
const &;
1496 Derived notation(
const Notation ¬ation) &&;
1671 Derived precision(
const Precision& precision)
const &;
1682 Derived precision(
const Precision& precision) &&;
1778 Derived integerWidth(
const IntegerWidth &style)
const &;
2028 Derived scale(
const Scale &scale)
const &;
2039 Derived scale(
const Scale &scale) &&;
2041 #ifndef U_HIDE_INTERNAL_API
2059 Derived threshold(int32_t threshold)
const &;
2062 Derived threshold(int32_t threshold) &&;
2131 fMacros.copyErrorTo(outErrorCode);
2148 friend class impl::NumberRangeFormatterImpl;
2284 #ifndef U_HIDE_INTERNAL_API
2300 const impl::NumberFormatterImpl* getCompiled()
const;
2306 int32_t getCallCount()
const;
2358 #ifndef U_HIDE_INTERNAL_API
2372 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2385 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2386 char fUnsafeCallCount[8] {};
2403 bool computeCompiled(
UErrorCode& status)
const;
2413 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2415 #pragma warning(pop)
2488 #ifndef U_HIDE_DRAFT_API
2507 template<
typename StringClass>
2508 inline StringClass toDecimalNumber(
UErrorCode& status)
const;
2509 #endif // U_HIDE_DRAFT_API
2511 #ifndef U_HIDE_INTERNAL_API
2517 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2523 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2529 const impl::UFormattedNumberData *fData;
2541 explicit FormattedNumber(
UErrorCode errorCode)
2542 : fData(nullptr), fErrorCode(errorCode) {}
2545 void toDecimalNumber(ByteSink& sink,
UErrorCode& status)
const;
2548 friend class LocalizedNumberFormatter;
2551 friend struct impl::UFormattedNumberImpl;
2554 #ifndef U_HIDE_DRAFT_API
2556 template<
typename StringClass>
2557 StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2560 toDecimalNumber(sink, status);
2563 #endif // U_HIDE_DRAFT_API
2641 #endif // __NUMBERFORMATTER_H__