4 #ifndef __NUMBERFORMATTER_H__
5 #define __NUMBERFORMATTER_H__
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_FORMATTING
93 class FieldPositionIteratorHandler;
94 class FormattedStringBuilder;
96 namespace numparse::impl {
99 class NumberParserImpl;
100 class MultiplierParseHandler;
114 class UnlocalizedNumberFormatter;
115 class LocalizedNumberFormatter;
116 class SimpleNumberFormatter;
117 class FormattedNumber;
119 class ScientificNotation;
121 class FractionPrecision;
122 class CurrencyPrecision;
123 class IncrementPrecision;
143 static constexpr int32_t kInternalDefaultThreshold = 3;
149 class DecimalQuantity;
150 class UFormattedNumberData;
151 class NumberFormatterImpl;
152 struct ParsedPatternInfo;
153 class ScientificModifier;
154 class MultiplierProducer;
156 class ScientificHandler;
158 class AffixPatternProvider;
159 class NumberPropertyMapper;
160 struct DecimalFormatProperties;
161 class MultiplierFormatHandler;
162 class CurrencySymbols;
163 class GeneratorHelpers;
165 class NumberRangeFormatterImpl;
167 struct UFormattedNumberImpl;
168 class MutablePatternModifier;
169 class ImmutablePatternModifier;
170 struct DecimalFormatWarehouse;
171 struct SimpleMicroProps;
172 class AdoptingSignumModifierStore;
350 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
353 union NotationUnion {
376 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
379 fUnion.errorCode = errorCode;
382 Notation() : fType(NTN_SIMPLE), fUnion() {}
385 if (fType == NTN_ERROR) {
386 status = fUnion.errorCode;
393 friend struct impl::MacroProps;
394 friend class ScientificNotation;
397 friend class impl::NumberFormatterImpl;
398 friend class impl::ScientificModifier;
399 friend class impl::ScientificHandler;
402 friend class impl::GeneratorHelpers;
447 using Notation::Notation;
456 friend class impl::NumberPropertyMapper;
573 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
626 int32_t maxSignificantDigits);
708 RND_FRACTION_SIGNIFICANT,
725 union PrecisionUnion {
766 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
767 : fType(type), fUnion(union_) {}
770 fUnion.errorCode = errorCode;
773 Precision() : fType(RND_BOGUS) {}
775 bool isBogus()
const {
776 return fType == RND_BOGUS;
780 if (fType == RND_ERROR) {
781 status = fUnion.errorCode;
788 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
790 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
792 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
794 static Precision constructFractionSignificant(
795 const FractionPrecision &base,
801 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
806 friend struct impl::MacroProps;
807 friend struct impl::MicroProps;
810 friend class impl::NumberFormatterImpl;
813 friend class impl::NumberPropertyMapper;
816 friend class impl::RoundingImpl;
819 friend class FractionPrecision;
820 friend class CurrencyPrecision;
821 friend class IncrementPrecision;
824 friend class impl::GeneratorHelpers;
827 friend class units::UnitsRouter;
856 int32_t minSignificantDigits,
857 int32_t maxSignificantDigits,
877 Precision withMinDigits(int32_t minSignificantDigits)
const;
896 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
900 using Precision::Precision;
938 using Precision::Precision;
970 Precision withMinFraction(int32_t minFrac)
const;
974 using Precision::Precision;
1022 bool fFormatFailIfMoreThanMaxDigits;
1026 bool fHasError =
false;
1031 fUnion.errorCode = errorCode;
1036 fUnion.minMaxInt.fMinInt = -1;
1041 return IntegerWidth::zeroFillTo(1);
1044 bool isBogus()
const {
1045 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1050 status = fUnion.errorCode;
1056 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1062 friend struct impl::MicroProps;
1065 friend class impl::NumberFormatterImpl;
1068 friend class impl::MutablePatternModifier;
1069 friend class impl::ImmutablePatternModifier;
1072 friend class impl::NumberPropertyMapper;
1075 friend class impl::GeneratorHelpers;
1094 static Scale none();
1106 static Scale powerOfTen(int32_t power);
1130 static Scale byDouble(
double multiplicand);
1138 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1158 #ifndef U_HIDE_INTERNAL_API
1160 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1165 impl::DecNum* fArbitrary;
1168 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1172 bool isValid()
const {
1173 return fMagnitude != 0 || fArbitrary !=
nullptr;
1184 void applyTo(impl::DecimalQuantity& quantity)
const;
1186 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1190 friend struct impl::MicroProps;
1193 friend class impl::NumberFormatterImpl;
1196 friend class impl::MultiplierFormatHandler;
1199 friend class impl::GeneratorHelpers;
1202 friend class ::icu::numparse::impl::NumberParserImpl;
1203 friend class ::icu::numparse::impl::MultiplierParseHandler;
1226 #ifndef U_HIDE_INTERNAL_API
1249 #endif // U_HIDE_INTERNAL_API
1268 friend class impl::NumberFormatterImpl;
1271 friend class impl::GeneratorHelpers;
1275 friend struct impl::MacroProps;
1286 SymbolsWrapper(
const SymbolsWrapper &other);
1289 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1292 SymbolsWrapper(SymbolsWrapper&& src) noexcept;
1295 SymbolsWrapper &operator=(SymbolsWrapper&& src) noexcept;
1300 #ifndef U_HIDE_INTERNAL_API
1318 bool isDecimalFormatSymbols()
const;
1324 bool isNumberingSystem()
const;
1338 #endif // U_HIDE_INTERNAL_API
1342 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1345 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1353 enum SymbolsPointerType {
1354 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1362 void doCopyFrom(
const SymbolsWrapper &other);
1364 void doMoveFrom(SymbolsWrapper&& src);
1373 #ifndef U_HIDE_INTERNAL_API
1381 static Grouper forProperties(
const DecimalFormatProperties& properties);
1387 : fGrouping1(grouping1),
1388 fGrouping2(grouping2),
1389 fMinGrouping(minGrouping),
1390 fStrategy(strategy) {}
1393 int16_t getPrimary()
const;
1396 int16_t getSecondary()
const;
1397 #endif // U_HIDE_INTERNAL_API
1418 int16_t fMinGrouping;
1428 bool isBogus()
const {
1429 return fGrouping1 == -3;
1433 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1435 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1438 friend struct MacroProps;
1439 friend struct MicroProps;
1440 friend struct SimpleMicroProps;
1443 friend class NumberFormatterImpl;
1444 friend class ::icu::number::SimpleNumberFormatter;
1447 friend class ::icu::numparse::impl::NumberParserImpl;
1450 friend class impl::GeneratorHelpers;
1457 #ifndef U_HIDE_INTERNAL_API
1465 static Padder forProperties(
const DecimalFormatProperties& properties);
1466 #endif // U_HIDE_INTERNAL_API
1483 fUnion.errorCode = errorCode;
1488 bool isBogus()
const {
1489 return fWidth == -2;
1494 status = fUnion.errorCode;
1500 bool isValid()
const {
1504 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1505 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1510 friend struct MicroProps;
1513 friend class impl::NumberFormatterImpl;
1516 friend class impl::GeneratorHelpers;
1559 bool approximately =
false;
1574 const AffixPatternProvider* affixProvider =
nullptr;
1580 int32_t threshold = kInternalDefaultThreshold;
1592 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1593 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1594 symbols.
copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1595 unitDisplayCase.copyErrorTo(status);
1601 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1607 #pragma warning(push)
1608 #pragma warning(disable: 4661)
1616 template<
typename Derived>
1647 Derived notation(
const Notation ¬ation)
const &;
1658 Derived notation(
const Notation ¬ation) &&;
1838 Derived precision(
const Precision& precision)
const &;
1849 Derived precision(
const Precision& precision) &&;
1945 Derived integerWidth(
const IntegerWidth &style)
const &;
2195 Derived scale(
const Scale &scale)
const &;
2206 Derived scale(
const Scale &scale) &&;
2269 Derived displayOptions(
const DisplayOptions &displayOptions)
const &;
2280 #ifndef U_HIDE_INTERNAL_API
2291 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2302 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2303 #endif // U_HIDE_INTERNAL_API
2305 #ifndef U_HIDE_INTERNAL_API
2323 Derived threshold(int32_t threshold)
const &;
2326 Derived threshold(int32_t threshold) &&;
2398 fMacros.copyErrorTo(outErrorCode);
2415 friend class impl::NumberRangeFormatterImpl;
2421 extern template class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2422 extern template class NumberFormatterSettings<LocalizedNumberFormatter>;
2565 #ifndef U_HIDE_INTERNAL_API
2587 const impl::NumberFormatterImpl* getCompiled()
const;
2593 int32_t getCallCount()
const;
2662 #ifndef U_HIDE_INTERNAL_API
2676 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2689 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2690 char fUnsafeCallCount[8] {};
2694 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2704 void resetCompiled();
2713 bool computeCompiled(
UErrorCode& status)
const;
2723 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2725 #pragma warning(pop)
2810 #endif // __NUMBERFORMATTER_H__