4 #ifndef __NUMBERFORMATTER_H__
5 #define __NUMBERFORMATTER_H__
9 #if U_SHOW_CPLUSPLUS_API
11 #if !UCONFIG_NO_FORMATTING
88 class FieldPositionIteratorHandler;
89 class FormattedStringBuilder;
95 class NumberParserImpl;
96 class MultiplierParseHandler;
111 class UnlocalizedNumberFormatter;
112 class LocalizedNumberFormatter;
113 class FormattedNumber;
115 class ScientificNotation;
117 class FractionPrecision;
118 class CurrencyPrecision;
119 class IncrementPrecision;
130 typedef int16_t digits_t;
139 static constexpr int32_t kInternalDefaultThreshold = 3;
145 class DecimalQuantity;
146 class UFormattedNumberData;
147 class NumberFormatterImpl;
148 struct ParsedPatternInfo;
149 class ScientificModifier;
150 class MultiplierProducer;
152 class ScientificHandler;
154 class AffixPatternProvider;
155 class NumberPropertyMapper;
156 struct DecimalFormatProperties;
157 class MultiplierFormatHandler;
158 class CurrencySymbols;
159 class GeneratorHelpers;
161 class NumberRangeFormatterImpl;
162 struct RangeMacroProps;
163 struct UFormattedNumberImpl;
164 class MutablePatternModifier;
165 class ImmutablePatternModifier;
166 struct DecimalFormatWarehouse;
174 void touchRangeLocales(impl::RangeMacroProps& macros);
183 typedef Notation CompactNotation;
190 typedef Notation SimpleNotation;
344 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
347 union NotationUnion {
370 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
373 fUnion.errorCode = errorCode;
376 Notation() : fType(NTN_SIMPLE), fUnion() {}
379 if (fType == NTN_ERROR) {
380 status = fUnion.errorCode;
387 friend struct impl::MacroProps;
388 friend class ScientificNotation;
391 friend class impl::NumberFormatterImpl;
392 friend class impl::ScientificModifier;
393 friend class impl::ScientificHandler;
396 friend class impl::GeneratorHelpers;
441 using Notation::Notation;
444 ScientificNotation(int8_t fEngineeringInterval,
bool fRequireMinInt, impl::digits_t fMinExponentDigits,
450 friend class impl::NumberPropertyMapper;
567 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
620 int32_t maxSignificantDigits);
662 #ifndef U_HIDE_DRAFT_API
671 #endif // U_HIDE_DRAFT_API
679 RND_FRACTION_SIGNIFICANT,
696 union PrecisionUnion {
730 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
731 : fType(type), fUnion(union_) {}
734 fUnion.errorCode = errorCode;
737 Precision() : fType(RND_BOGUS) {}
739 bool isBogus()
const {
740 return fType == RND_BOGUS;
744 if (fType == RND_ERROR) {
745 status = fUnion.errorCode;
752 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
754 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
756 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
758 static Precision constructFractionSignificant(
759 const FractionPrecision &base,
764 static IncrementPrecision constructIncrement(
double increment, int32_t minFrac);
769 friend struct impl::MacroProps;
770 friend struct impl::MicroProps;
773 friend class impl::NumberFormatterImpl;
776 friend class impl::NumberPropertyMapper;
779 friend class impl::RoundingImpl;
782 friend class FractionPrecision;
783 friend class CurrencyPrecision;
784 friend class IncrementPrecision;
787 friend class impl::GeneratorHelpers;
790 friend class units::UnitsRouter;
804 #ifndef U_HIDE_DRAFT_API
820 int32_t minSignificantDigits,
821 int32_t maxSignificantDigits,
823 #endif // U_HIDE_DRAFT_API
842 Precision withMinDigits(int32_t minSignificantDigits)
const;
861 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
865 using Precision::Precision;
903 using Precision::Precision;
935 Precision withMinFraction(int32_t minFrac)
const;
939 using Precision::Precision;
985 impl::digits_t fMinInt;
986 impl::digits_t fMaxInt;
987 bool fFormatFailIfMoreThanMaxDigits;
991 bool fHasError =
false;
993 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt,
bool formatFailIfMoreThanMaxDigits);
996 fUnion.errorCode = errorCode;
1001 fUnion.minMaxInt.fMinInt = -1;
1006 return IntegerWidth::zeroFillTo(1);
1009 bool isBogus()
const {
1010 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1015 status = fUnion.errorCode;
1021 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1027 friend struct impl::MicroProps;
1030 friend class impl::NumberFormatterImpl;
1033 friend class impl::MutablePatternModifier;
1034 friend class impl::ImmutablePatternModifier;
1037 friend class impl::NumberPropertyMapper;
1040 friend class impl::GeneratorHelpers;
1059 static Scale none();
1071 static Scale powerOfTen(int32_t power);
1095 static Scale byDouble(
double multiplicand);
1103 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1123 #ifndef U_HIDE_INTERNAL_API
1125 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1130 impl::DecNum* fArbitrary;
1133 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1137 bool isValid()
const {
1138 return fMagnitude != 0 || fArbitrary !=
nullptr;
1149 void applyTo(impl::DecimalQuantity& quantity)
const;
1151 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1155 friend struct impl::MicroProps;
1158 friend class impl::NumberFormatterImpl;
1161 friend class impl::MultiplierFormatHandler;
1164 friend class impl::GeneratorHelpers;
1167 friend class ::icu::numparse::impl::NumberParserImpl;
1168 friend class ::icu::numparse::impl::MultiplierParseHandler;
1180 #ifndef U_HIDE_INTERNAL_API
1213 #endif // U_HIDE_INTERNAL_API
1233 friend class impl::NumberFormatterImpl;
1236 friend class impl::GeneratorHelpers;
1240 friend struct impl::MacroProps;
1251 SymbolsWrapper(
const SymbolsWrapper &other);
1254 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1257 SymbolsWrapper(SymbolsWrapper&& src)
U_NOEXCEPT;
1260 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
1265 #ifndef U_HIDE_INTERNAL_API
1283 bool isDecimalFormatSymbols()
const;
1289 bool isNumberingSystem()
const;
1303 #endif // U_HIDE_INTERNAL_API
1307 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1310 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1318 enum SymbolsPointerType {
1319 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1327 void doCopyFrom(
const SymbolsWrapper &other);
1329 void doMoveFrom(SymbolsWrapper&& src);
1338 #ifndef U_HIDE_INTERNAL_API
1346 static Grouper forProperties(
const DecimalFormatProperties& properties);
1352 : fGrouping1(grouping1),
1353 fGrouping2(grouping2),
1354 fMinGrouping(minGrouping),
1355 fStrategy(strategy) {}
1358 int16_t getPrimary()
const;
1361 int16_t getSecondary()
const;
1362 #endif // U_HIDE_INTERNAL_API
1383 int16_t fMinGrouping;
1393 bool isBogus()
const {
1394 return fGrouping1 == -3;
1398 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1400 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1403 friend struct MacroProps;
1404 friend struct MicroProps;
1407 friend class NumberFormatterImpl;
1410 friend class ::icu::numparse::impl::NumberParserImpl;
1413 friend class impl::GeneratorHelpers;
1420 #ifndef U_HIDE_INTERNAL_API
1428 static Padder forProperties(
const DecimalFormatProperties& properties);
1429 #endif // U_HIDE_INTERNAL_API
1446 fUnion.errorCode = errorCode;
1451 bool isBogus()
const {
1452 return fWidth == -2;
1457 status = fUnion.errorCode;
1463 bool isValid()
const {
1467 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1468 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1473 friend struct MicroProps;
1476 friend class impl::NumberFormatterImpl;
1479 friend class impl::GeneratorHelpers;
1533 const AffixPatternProvider* affixProvider =
nullptr;
1539 int32_t threshold = kInternalDefaultThreshold;
1551 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1552 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1553 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1554 unitDisplayCase.copyErrorTo(status);
1560 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1566 #pragma warning(push)
1567 #pragma warning(disable: 4661)
1575 template<
typename Derived>
1606 Derived notation(
const Notation ¬ation)
const &;
1617 Derived notation(
const Notation ¬ation) &&;
1797 Derived precision(
const Precision& precision)
const &;
1808 Derived precision(
const Precision& precision) &&;
1904 Derived integerWidth(
const IntegerWidth &style)
const &;
2154 Derived scale(
const Scale &scale)
const &;
2165 Derived scale(
const Scale &scale) &&;
2167 #ifndef U_HIDE_DRAFT_API
2220 #endif // U_HIDE_DRAFT_API
2222 #ifndef U_HIDE_DRAFT_API
2223 #ifndef U_HIDE_INTERNAL_API
2230 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2237 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2238 #endif // U_HIDE_INTERNAL_API
2239 #endif // U_HIDE_DRAFT_API
2241 #ifndef U_HIDE_INTERNAL_API
2259 Derived threshold(int32_t threshold)
const &;
2262 Derived threshold(int32_t threshold) &&;
2334 fMacros.copyErrorTo(outErrorCode);
2351 friend class impl::NumberRangeFormatterImpl;
2487 #ifndef U_HIDE_INTERNAL_API
2503 const impl::NumberFormatterImpl* getCompiled()
const;
2509 int32_t getCallCount()
const;
2561 #ifndef U_HIDE_INTERNAL_API
2575 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2588 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2589 char fUnsafeCallCount[8] {};
2593 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2603 void resetCompiled();
2612 bool computeCompiled(
UErrorCode& status)
const;
2619 friend class UnlocalizedNumberFormatter;
2622 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2624 #pragma warning(pop)
2715 template<typename StringClass>
2716 inline StringClass toDecimalNumber(
UErrorCode& status) const;
2718 #ifndef U_HIDE_DRAFT_API
2738 const char *getGender(
UErrorCode& status)
const;
2739 #endif // U_HIDE_DRAFT_API
2741 #ifndef U_HIDE_INTERNAL_API
2747 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2753 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2759 const impl::UFormattedNumberData *fData;
2771 explicit FormattedNumber(
UErrorCode errorCode)
2772 : fData(nullptr), fErrorCode(errorCode) {}
2774 void toDecimalNumber(ByteSink& sink,
UErrorCode& status)
const;
2777 friend class LocalizedNumberFormatter;
2780 friend struct impl::UFormattedNumberImpl;
2783 template<
typename StringClass>
2784 StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2787 toDecimalNumber(sink, status);
2873 #endif // __NUMBERFORMATTER_H__
#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.
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
#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.
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.
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.
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.
UBool copyErrorTo(UErrorCode &status) const
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.
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
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.
A Locale object represents a specific geographical, political, or cultural region.