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;
281 static CompactNotation compactShort();
305 static CompactNotation compactLong();
331 static SimpleNotation simple();
335 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
338 union NotationUnion {
361 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
364 fUnion.errorCode = errorCode;
367 Notation() : fType(NTN_SIMPLE), fUnion() {}
370 if (fType == NTN_ERROR) {
371 status = fUnion.errorCode;
382 friend class impl::NumberFormatterImpl;
383 friend class impl::ScientificModifier;
384 friend class impl::ScientificHandler;
387 friend class impl::GeneratorHelpers;
432 using Notation::Notation;
441 friend class impl::NumberPropertyMapper;
558 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
573 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
587 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
597 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
610 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
611 int32_t maxSignificantDigits);
659 RND_FRACTION_SIGNIFICANT,
676 union PrecisionUnion {
709 Precision(
const PrecisionType& type,
const PrecisionUnion& union_,
711 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
714 fUnion.errorCode = errorCode;
719 bool isBogus()
const {
720 return fType == RND_BOGUS;
724 if (fType == RND_ERROR) {
725 status = fUnion.errorCode;
736 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
739 constructFractionSignificant(
const FractionPrecision &base, int32_t minSig, int32_t maxSig);
749 friend struct impl::MicroProps;
752 friend class impl::NumberFormatterImpl;
755 friend class impl::NumberPropertyMapper;
758 friend class impl::RoundingImpl;
766 friend class impl::GeneratorHelpers;
796 Precision withMinDigits(int32_t minSignificantDigits)
const;
815 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
819 using Precision::Precision;
857 using Precision::Precision;
889 Precision withMinFraction(int32_t minFrac)
const;
893 using Precision::Precision;
941 bool fFormatFailIfMoreThanMaxDigits;
945 bool fHasError =
false;
950 fUnion.errorCode = errorCode;
955 fUnion.minMaxInt.fMinInt = -1;
960 return IntegerWidth::zeroFillTo(1);
963 bool isBogus()
const {
964 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
969 status = fUnion.errorCode;
975 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
981 friend struct impl::MicroProps;
984 friend class impl::NumberFormatterImpl;
987 friend class impl::NumberPropertyMapper;
990 friend class impl::GeneratorHelpers;
1009 static Scale none();
1021 static Scale powerOfTen(int32_t power);
1045 static Scale byDouble(
double multiplicand);
1053 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1073 #ifndef U_HIDE_INTERNAL_API 1075 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1080 impl::DecNum* fArbitrary;
1083 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1087 bool isValid()
const {
1088 return fMagnitude != 0 || fArbitrary !=
nullptr;
1099 void applyTo(impl::DecimalQuantity& quantity)
const;
1101 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1105 friend struct impl::MicroProps;
1108 friend class impl::NumberFormatterImpl;
1111 friend class impl::MultiplierFormatHandler;
1114 friend class impl::GeneratorHelpers;
1117 friend class ::icu::numparse::impl::NumberParserImpl;
1118 friend class ::icu::numparse::impl::MultiplierParseHandler;
1145 #ifndef U_HIDE_INTERNAL_API 1163 bool isDecimalFormatSymbols()
const;
1169 bool isNumberingSystem()
const;
1183 #endif // U_HIDE_INTERNAL_API 1187 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1190 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1198 enum SymbolsPointerType {
1199 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1218 #ifndef U_HIDE_INTERNAL_API 1226 static Grouper forProperties(
const DecimalFormatProperties& properties);
1232 : fGrouping1(grouping1),
1233 fGrouping2(grouping2),
1234 fMinGrouping(minGrouping),
1235 fStrategy(strategy) {}
1236 #endif // U_HIDE_INTERNAL_API 1239 int16_t getPrimary()
const;
1242 int16_t getSecondary()
const;
1263 int16_t fMinGrouping;
1273 bool isBogus()
const {
1274 return fGrouping1 == -3;
1278 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1280 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1284 friend struct MicroProps;
1287 friend class NumberFormatterImpl;
1290 friend class ::icu::numparse::impl::NumberParserImpl;
1293 friend class impl::GeneratorHelpers;
1300 #ifndef U_HIDE_INTERNAL_API 1306 #endif // U_HIDE_INTERNAL_API 1309 static Padder forProperties(
const DecimalFormatProperties& properties);
1326 fUnion.errorCode = errorCode;
1331 bool isBogus()
const {
1332 return fWidth == -2;
1337 status = fUnion.errorCode;
1343 bool isValid()
const {
1347 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1348 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1353 friend struct MicroProps;
1356 friend class impl::NumberFormatterImpl;
1359 friend class impl::GeneratorHelpers;
1407 const AffixPatternProvider* affixProvider =
nullptr;
1413 const CurrencySymbols* currencySymbols =
nullptr;
1416 int32_t threshold = kInternalDefaultThreshold;
1428 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1429 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1430 symbols.
copyErrorTo(status) || scale.copyErrorTo(status);
1441 template<
typename Derived>
1472 Derived notation(
const Notation ¬ation)
const &;
1483 Derived notation(
const Notation ¬ation) &&;
1658 Derived precision(
const Precision& precision)
const &;
1669 Derived precision(
const Precision& precision) &&;
1765 Derived integerWidth(
const IntegerWidth &style)
const &;
2015 Derived scale(
const Scale &scale)
const &;
2026 Derived scale(
const Scale &scale) &&;
2028 #ifndef U_HIDE_INTERNAL_API 2046 Derived threshold(int32_t threshold)
const &;
2049 Derived threshold(int32_t threshold) &&;
2085 #ifndef U_HIDE_DRAFT_API 2120 fMacros.copyErrorTo(outErrorCode);
2137 friend class impl::NumberRangeFormatterImpl;
2273 #ifndef U_HIDE_INTERNAL_API 2289 const impl::NumberFormatterImpl* getCompiled()
const;
2295 int32_t getCallCount()
const;
2347 #ifndef U_HIDE_INTERNAL_API 2361 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2374 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2375 char fUnsafeCallCount[8] {};
2392 bool computeCompiled(
UErrorCode& status)
const;
2399 friend class UnlocalizedNumberFormatter;
2414 #ifndef U_FORCE_HIDE_DRAFT_API 2421 #endif // U_FORCE_HIDE_DRAFT_API 2475 #ifndef U_HIDE_DRAFT_API 2529 #ifndef U_HIDE_DRAFT_API 2548 template<
typename StringClass>
2549 inline StringClass toDecimalNumber(
UErrorCode& status)
const;
2550 #endif // U_HIDE_DRAFT_API 2552 #ifndef U_HIDE_INTERNAL_API 2558 void getDecimalQuantity(impl::DecimalQuantity& output,
UErrorCode& status)
const;
2564 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
UErrorCode& status)
const;
2570 const impl::UFormattedNumberData *fData;
2583 : fData(
nullptr), fErrorCode(errorCode) {}
2592 friend struct impl::UFormattedNumberImpl;
2595 #ifndef U_HIDE_DRAFT_API 2597 template<
typename StringClass>
2598 StringClass FormattedNumber::toDecimalNumber(
UErrorCode& status)
const {
2601 toDecimalNumber(sink, status);
2604 #endif // U_HIDE_DRAFT_API 2649 #ifndef U_HIDE_DRAFT_API 2684 #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.
#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...
A ByteSink can be filled with bytes.
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...
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.
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
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.
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...
#define TRUE
The TRUE value of a UBool.
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.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
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".
#define FALSE
The FALSE value of a UBool.
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)
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.
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.