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;
100 class NumberParserImpl;
101 class MultiplierParseHandler;
116 class UnlocalizedNumberFormatter;
117 class LocalizedNumberFormatter;
118 class SimpleNumberFormatter;
119 class FormattedNumber;
121 class ScientificNotation;
123 class FractionPrecision;
124 class CurrencyPrecision;
125 class IncrementPrecision;
145 static constexpr int32_t kInternalDefaultThreshold = 3;
151 class DecimalQuantity;
152 class UFormattedNumberData;
153 class NumberFormatterImpl;
154 struct ParsedPatternInfo;
155 class ScientificModifier;
156 class MultiplierProducer;
158 class ScientificHandler;
160 class AffixPatternProvider;
161 class NumberPropertyMapper;
162 struct DecimalFormatProperties;
163 class MultiplierFormatHandler;
164 class CurrencySymbols;
165 class GeneratorHelpers;
167 class NumberRangeFormatterImpl;
169 struct UFormattedNumberImpl;
170 class MutablePatternModifier;
171 class ImmutablePatternModifier;
172 struct DecimalFormatWarehouse;
173 struct SimpleMicroProps;
174 class AdoptingSignumModifierStore;
352 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
355 union NotationUnion {
378 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
381 fUnion.errorCode = errorCode;
384 Notation() : fType(NTN_SIMPLE), fUnion() {}
387 if (fType == NTN_ERROR) {
388 status = fUnion.errorCode;
395 friend struct impl::MacroProps;
396 friend class ScientificNotation;
399 friend class impl::NumberFormatterImpl;
400 friend class impl::ScientificModifier;
401 friend class impl::ScientificHandler;
404 friend class impl::GeneratorHelpers;
449 using Notation::Notation;
458 friend class impl::NumberPropertyMapper;
575 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
628 int32_t maxSignificantDigits);
710 RND_FRACTION_SIGNIFICANT,
727 union PrecisionUnion {
768 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
769 : fType(type), fUnion(union_) {}
772 fUnion.errorCode = errorCode;
775 Precision() : fType(RND_BOGUS) {}
777 bool isBogus()
const {
778 return fType == RND_BOGUS;
782 if (fType == RND_ERROR) {
783 status = fUnion.errorCode;
790 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
792 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
794 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
796 static Precision constructFractionSignificant(
797 const FractionPrecision &base,
803 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
808 friend struct impl::MacroProps;
809 friend struct impl::MicroProps;
812 friend class impl::NumberFormatterImpl;
815 friend class impl::NumberPropertyMapper;
818 friend class impl::RoundingImpl;
821 friend class FractionPrecision;
822 friend class CurrencyPrecision;
823 friend class IncrementPrecision;
826 friend class impl::GeneratorHelpers;
829 friend class units::UnitsRouter;
858 int32_t minSignificantDigits,
859 int32_t maxSignificantDigits,
879 Precision withMinDigits(int32_t minSignificantDigits)
const;
898 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
902 using Precision::Precision;
940 using Precision::Precision;
972 Precision withMinFraction(int32_t minFrac)
const;
976 using Precision::Precision;
1024 bool fFormatFailIfMoreThanMaxDigits;
1028 bool fHasError =
false;
1033 fUnion.errorCode = errorCode;
1038 fUnion.minMaxInt.fMinInt = -1;
1043 return IntegerWidth::zeroFillTo(1);
1046 bool isBogus()
const {
1047 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1052 status = fUnion.errorCode;
1058 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1064 friend struct impl::MicroProps;
1067 friend class impl::NumberFormatterImpl;
1070 friend class impl::MutablePatternModifier;
1071 friend class impl::ImmutablePatternModifier;
1074 friend class impl::NumberPropertyMapper;
1077 friend class impl::GeneratorHelpers;
1096 static Scale none();
1108 static Scale powerOfTen(int32_t power);
1132 static Scale byDouble(
double multiplicand);
1140 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1160 #ifndef U_HIDE_INTERNAL_API 1162 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1167 impl::DecNum* fArbitrary;
1170 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1174 bool isValid()
const {
1175 return fMagnitude != 0 || fArbitrary !=
nullptr;
1186 void applyTo(impl::DecimalQuantity& quantity)
const;
1188 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1192 friend struct impl::MicroProps;
1195 friend class impl::NumberFormatterImpl;
1198 friend class impl::MultiplierFormatHandler;
1201 friend class impl::GeneratorHelpers;
1204 friend class ::icu::numparse::impl::NumberParserImpl;
1205 friend class ::icu::numparse::impl::MultiplierParseHandler;
1228 #ifndef U_HIDE_INTERNAL_API 1251 #endif // U_HIDE_INTERNAL_API 1271 friend class impl::NumberFormatterImpl;
1274 friend class impl::GeneratorHelpers;
1278 friend struct impl::MacroProps;
1289 SymbolsWrapper(
const SymbolsWrapper &other);
1292 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1295 SymbolsWrapper(SymbolsWrapper&& src) noexcept;
1298 SymbolsWrapper &operator=(SymbolsWrapper&& src) noexcept;
1303 #ifndef U_HIDE_INTERNAL_API 1321 bool isDecimalFormatSymbols()
const;
1327 bool isNumberingSystem()
const;
1341 #endif // U_HIDE_INTERNAL_API 1345 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1348 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1356 enum SymbolsPointerType {
1357 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1365 void doCopyFrom(
const SymbolsWrapper &other);
1367 void doMoveFrom(SymbolsWrapper&& src);
1376 #ifndef U_HIDE_INTERNAL_API 1384 static Grouper forProperties(
const DecimalFormatProperties& properties);
1390 : fGrouping1(grouping1),
1391 fGrouping2(grouping2),
1392 fMinGrouping(minGrouping),
1393 fStrategy(strategy) {}
1396 int16_t getPrimary()
const;
1399 int16_t getSecondary()
const;
1400 #endif // U_HIDE_INTERNAL_API 1421 int16_t fMinGrouping;
1431 bool isBogus()
const {
1432 return fGrouping1 == -3;
1436 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1438 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1441 friend struct MacroProps;
1442 friend struct MicroProps;
1443 friend struct SimpleMicroProps;
1446 friend class NumberFormatterImpl;
1447 friend class ::icu::number::SimpleNumberFormatter;
1450 friend class ::icu::numparse::impl::NumberParserImpl;
1453 friend class impl::GeneratorHelpers;
1460 #ifndef U_HIDE_INTERNAL_API 1468 static Padder forProperties(
const DecimalFormatProperties& properties);
1469 #endif // U_HIDE_INTERNAL_API 1486 fUnion.errorCode = errorCode;
1491 bool isBogus()
const {
1492 return fWidth == -2;
1497 status = fUnion.errorCode;
1503 bool isValid()
const {
1507 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1508 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1513 friend struct MicroProps;
1516 friend class impl::NumberFormatterImpl;
1519 friend class impl::GeneratorHelpers;
1561 bool approximately =
false;
1576 const AffixPatternProvider* affixProvider =
nullptr;
1582 int32_t threshold = kInternalDefaultThreshold;
1594 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1595 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1596 symbols.
copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1597 unitDisplayCase.copyErrorTo(status);
1603 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) 1609 #pragma warning(push) 1610 #pragma warning(disable: 4661) 1618 template<
typename Derived>
1649 Derived notation(
const Notation ¬ation)
const &;
1660 Derived notation(
const Notation ¬ation) &&;
1840 Derived precision(
const Precision& precision)
const &;
1851 Derived precision(
const Precision& precision) &&;
1947 Derived integerWidth(
const IntegerWidth &style)
const &;
2197 Derived scale(
const Scale &scale)
const &;
2208 Derived scale(
const Scale &scale) &&;
2271 Derived displayOptions(
const DisplayOptions &displayOptions)
const &;
2282 #ifndef U_HIDE_INTERNAL_API 2293 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2304 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2305 #endif // U_HIDE_INTERNAL_API 2307 #ifndef U_HIDE_INTERNAL_API 2325 Derived threshold(int32_t threshold)
const &;
2328 Derived threshold(int32_t threshold) &&;
2400 fMacros.copyErrorTo(outErrorCode);
2417 friend class impl::NumberRangeFormatterImpl;
2423 extern template class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2424 extern template class NumberFormatterSettings<LocalizedNumberFormatter>;
2560 #ifndef U_HIDE_INTERNAL_API 2582 const impl::NumberFormatterImpl* getCompiled()
const;
2588 int32_t getCallCount()
const;
2640 #ifndef U_HIDE_INTERNAL_API 2654 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2667 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2668 char fUnsafeCallCount[8] {};
2672 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2682 void resetCompiled();
2691 bool computeCompiled(
UErrorCode& status)
const;
2701 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) 2703 #pragma warning(pop) 2788 #endif // __NUMBERFORMATTER_H__
C++ API: Display options class.
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.
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i.e., the separator, often a comma or period, after every 2-3 powers of ten).
"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.
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
UNumberSignDisplay fExponentSignDisplay
C API: Header-only input options for various number formatting APIs.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
StringProp unitDisplayCase
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.
impl::digits_t fMinExponentDigits
C++ API: Interface for writing bytes, and implementation classes.
IntegerWidth integerWidth
C++ API: A unit for measuring a quantity.
C API: Encapsulates information about a currency.
Represents all the display options that are supported by CLDR such as grammatical case...
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
UCurrencyUsage
Currency Usage used for Decimal Format.
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
impl::digits_t fIncrementMagnitude
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
A unit of currency, such as USD (U.S.
UNumberFormatPadPosition
The possible number format pad positions.
C++ API: Common ICU base class UObject.
UNumberCompactStyle
Constants for specifying short or long format.
C API: Parse Error Information.
UNumberFormatRoundingMode
The possible number format rounding modes.
A class that defines a quantity by which a number should be multiplied when formatting.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
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.
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)
UNumberRoundingPriority fPriority
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, a signed-byte integer.
C API: Compatibility APIs for number formatting.
UBool copyErrorTo(UErrorCode &status) const
A Locale object represents a specific geographical, political, or cultural region.