4 #ifndef __NUMBERFORMATTER_H__ 5 #define __NUMBERFORMATTER_H__ 9 #if U_SHOW_CPLUSPLUS_API 11 #if !UCONFIG_NO_FORMATTING 90 class FieldPositionIteratorHandler;
91 class FormattedStringBuilder;
97 class NumberParserImpl;
98 class MultiplierParseHandler;
113 class UnlocalizedNumberFormatter;
114 class LocalizedNumberFormatter;
115 class FormattedNumber;
117 class ScientificNotation;
119 class FractionPrecision;
120 class CurrencyPrecision;
121 class IncrementPrecision;
141 static constexpr int32_t kInternalDefaultThreshold = 3;
147 class DecimalQuantity;
148 class UFormattedNumberData;
149 class NumberFormatterImpl;
150 struct ParsedPatternInfo;
151 class ScientificModifier;
152 class MultiplierProducer;
154 class ScientificHandler;
156 class AffixPatternProvider;
157 class NumberPropertyMapper;
158 struct DecimalFormatProperties;
159 class MultiplierFormatHandler;
160 class CurrencySymbols;
161 class GeneratorHelpers;
163 class NumberRangeFormatterImpl;
165 struct UFormattedNumberImpl;
166 class MutablePatternModifier;
167 class ImmutablePatternModifier;
168 struct DecimalFormatWarehouse;
346 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
349 union NotationUnion {
372 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
375 fUnion.errorCode = errorCode;
378 Notation() : fType(NTN_SIMPLE), fUnion() {}
381 if (fType == NTN_ERROR) {
382 status = fUnion.errorCode;
389 friend struct impl::MacroProps;
390 friend class ScientificNotation;
393 friend class impl::NumberFormatterImpl;
394 friend class impl::ScientificModifier;
395 friend class impl::ScientificHandler;
398 friend class impl::GeneratorHelpers;
443 using Notation::Notation;
452 friend class impl::NumberPropertyMapper;
569 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
622 int32_t maxSignificantDigits);
645 #ifndef U_HIDE_DRAFT_API 670 #endif // U_HIDE_DRAFT_API 706 RND_FRACTION_SIGNIFICANT,
723 union PrecisionUnion {
764 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
765 : fType(type), fUnion(union_) {}
768 fUnion.errorCode = errorCode;
771 Precision() : fType(RND_BOGUS) {}
773 bool isBogus()
const {
774 return fType == RND_BOGUS;
778 if (fType == RND_ERROR) {
779 status = fUnion.errorCode;
786 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
788 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
790 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
792 static Precision constructFractionSignificant(
793 const FractionPrecision &base,
799 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
804 friend struct impl::MacroProps;
805 friend struct impl::MicroProps;
808 friend class impl::NumberFormatterImpl;
811 friend class impl::NumberPropertyMapper;
814 friend class impl::RoundingImpl;
817 friend class FractionPrecision;
818 friend class CurrencyPrecision;
819 friend class IncrementPrecision;
822 friend class impl::GeneratorHelpers;
825 friend class units::UnitsRouter;
854 int32_t minSignificantDigits,
855 int32_t maxSignificantDigits,
875 Precision withMinDigits(int32_t minSignificantDigits)
const;
894 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
898 using Precision::Precision;
936 using Precision::Precision;
968 Precision withMinFraction(int32_t minFrac)
const;
972 using Precision::Precision;
1020 bool fFormatFailIfMoreThanMaxDigits;
1024 bool fHasError =
false;
1029 fUnion.errorCode = errorCode;
1034 fUnion.minMaxInt.fMinInt = -1;
1039 return IntegerWidth::zeroFillTo(1);
1042 bool isBogus()
const {
1043 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1048 status = fUnion.errorCode;
1054 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1060 friend struct impl::MicroProps;
1063 friend class impl::NumberFormatterImpl;
1066 friend class impl::MutablePatternModifier;
1067 friend class impl::ImmutablePatternModifier;
1070 friend class impl::NumberPropertyMapper;
1073 friend class impl::GeneratorHelpers;
1092 static Scale none();
1104 static Scale powerOfTen(int32_t power);
1128 static Scale byDouble(
double multiplicand);
1136 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1156 #ifndef U_HIDE_INTERNAL_API 1158 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1163 impl::DecNum* fArbitrary;
1166 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1170 bool isValid()
const {
1171 return fMagnitude != 0 || fArbitrary !=
nullptr;
1182 void applyTo(impl::DecimalQuantity& quantity)
const;
1184 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1188 friend struct impl::MicroProps;
1191 friend class impl::NumberFormatterImpl;
1194 friend class impl::MultiplierFormatHandler;
1197 friend class impl::GeneratorHelpers;
1200 friend class ::icu::numparse::impl::NumberParserImpl;
1201 friend class ::icu::numparse::impl::MultiplierParseHandler;
1224 #ifndef U_HIDE_INTERNAL_API 1247 #endif // U_HIDE_INTERNAL_API 1267 friend class impl::NumberFormatterImpl;
1270 friend class impl::GeneratorHelpers;
1274 friend struct impl::MacroProps;
1285 SymbolsWrapper(
const SymbolsWrapper &other);
1288 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1291 SymbolsWrapper(SymbolsWrapper&& src)
U_NOEXCEPT;
1294 SymbolsWrapper &operator=(SymbolsWrapper&& src)
U_NOEXCEPT;
1299 #ifndef U_HIDE_INTERNAL_API 1317 bool isDecimalFormatSymbols()
const;
1323 bool isNumberingSystem()
const;
1337 #endif // U_HIDE_INTERNAL_API 1341 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1344 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1352 enum SymbolsPointerType {
1353 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1361 void doCopyFrom(
const SymbolsWrapper &other);
1363 void doMoveFrom(SymbolsWrapper&& src);
1372 #ifndef U_HIDE_INTERNAL_API 1380 static Grouper forProperties(
const DecimalFormatProperties& properties);
1386 : fGrouping1(grouping1),
1387 fGrouping2(grouping2),
1388 fMinGrouping(minGrouping),
1389 fStrategy(strategy) {}
1392 int16_t getPrimary()
const;
1395 int16_t getSecondary()
const;
1396 #endif // U_HIDE_INTERNAL_API 1417 int16_t fMinGrouping;
1427 bool isBogus()
const {
1428 return fGrouping1 == -3;
1432 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1434 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1437 friend struct MacroProps;
1438 friend struct MicroProps;
1441 friend class NumberFormatterImpl;
1444 friend class ::icu::numparse::impl::NumberParserImpl;
1447 friend class impl::GeneratorHelpers;
1454 #ifndef U_HIDE_INTERNAL_API 1462 static Padder forProperties(
const DecimalFormatProperties& properties);
1463 #endif // U_HIDE_INTERNAL_API 1480 fUnion.errorCode = errorCode;
1485 bool isBogus()
const {
1486 return fWidth == -2;
1491 status = fUnion.errorCode;
1497 bool isValid()
const {
1501 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1502 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1507 friend struct MicroProps;
1510 friend class impl::NumberFormatterImpl;
1513 friend class impl::GeneratorHelpers;
1555 bool approximately =
false;
1570 const AffixPatternProvider* affixProvider =
nullptr;
1576 int32_t threshold = kInternalDefaultThreshold;
1588 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1589 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1590 symbols.
copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1591 unitDisplayCase.copyErrorTo(status);
1597 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) 1603 #pragma warning(push) 1604 #pragma warning(disable: 4661) 1612 template<
typename Derived>
1643 Derived notation(
const Notation ¬ation)
const &;
1654 Derived notation(
const Notation ¬ation) &&;
1834 Derived precision(
const Precision& precision)
const &;
1845 Derived precision(
const Precision& precision) &&;
1941 Derived integerWidth(
const IntegerWidth &style)
const &;
2191 Derived scale(
const Scale &scale)
const &;
2202 Derived scale(
const Scale &scale) &&;
2257 #ifndef U_HIDE_DRAFT_API 2266 Derived displayOptions(
const DisplayOptions &displayOptions)
const &;
2276 #endif // U_HIDE_DRAFT_API 2278 #ifndef U_HIDE_INTERNAL_API 2289 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2300 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2301 #endif // U_HIDE_INTERNAL_API 2303 #ifndef U_HIDE_INTERNAL_API 2321 Derived threshold(int32_t threshold)
const &;
2324 Derived threshold(int32_t threshold) &&;
2396 fMacros.copyErrorTo(outErrorCode);
2413 friend class impl::NumberRangeFormatterImpl;
2549 #ifndef U_HIDE_INTERNAL_API 2571 const impl::NumberFormatterImpl* getCompiled()
const;
2577 int32_t getCallCount()
const;
2629 #ifndef U_HIDE_INTERNAL_API 2643 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2656 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2657 char fUnsafeCallCount[8] {};
2661 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2671 void resetCompiled();
2680 bool computeCompiled(
UErrorCode& status)
const;
2690 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) 2692 #pragma warning(pop) 2783 template<typename StringClass>
2784 inline StringClass toDecimalNumber(
UErrorCode& status) const;
2799 #ifndef U_HIDE_DRAFT_API 2810 #endif // U_HIDE_DRAFT_API 2812 #ifndef U_HIDE_INTERNAL_API 2818 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2824 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2830 const impl::UFormattedNumberData *fData;
2842 explicit FormattedNumber(
UErrorCode errorCode)
2843 : fData(nullptr), fErrorCode(errorCode) {}
2845 void toDecimalNumber(ByteSink& sink,
UErrorCode& status)
const;
2848 friend class LocalizedNumberFormatter;
2851 friend struct impl::UFormattedNumberImpl;
2854 template<
typename StringClass>
2855 StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2858 toDecimalNumber(sink, status);
2944 #endif // __NUMBERFORMATTER_H__
C++ API: Display options class.
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
UNumberFormatRoundingMode
The possible number format rounding modes.
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.
"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
#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.
C API: Display options (enum types, values, helper functions)
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.
Represents a span of a string containing a given field.
UNumberCompactStyle
Constants for specifying short or long format.
C API: Parse Error Information.
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.
UDisplayOptionsNounClass
Represents all the grammatical noun classes that are supported by CLDR.
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.
Implementation of ByteSink that writes to a "string".
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...
Requested operation can not be completed with ICU in its current state.
int8_t fEngineeringInterval
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
int8_t UBool
The ICU boolean type, a signed-byte integer.
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.