6 #if !UCONFIG_NO_FORMATTING 7 #ifndef __NUMBERFORMATTER_H__ 8 #define __NUMBERFORMATTER_H__ 21 #ifndef U_HIDE_DRAFT_API 277 class UnlocalizedNumberFormatter;
278 class LocalizedNumberFormatter;
279 class FormattedNumber;
281 class ScientificNotation;
283 class FractionRounder;
284 class CurrencyRounder;
285 class IncrementRounder;
295 class DecimalQuantity;
296 struct NumberFormatterResults;
297 class NumberFormatterImpl;
298 struct ParsedPatternInfo;
299 class ScientificModifier;
300 class MultiplierProducer;
301 class MutablePatternModifier;
302 class LongNameHandler;
303 class ScientificHandler;
304 class CompactHandler;
306 class NumberStringBuilder;
311 typedef Notation CompactNotation;
312 typedef Notation SimpleNotation;
466 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
469 union NotationUnion {
472 int8_t fEngineeringInterval;
474 int8_t fMinExponentDigits;
487 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
490 fUnion.errorCode = errorCode;
493 Notation() : fType(NTN_SIMPLE), fUnion() {}
496 if (fType == NTN_ERROR) {
497 status = fUnion.errorCode;
504 friend struct impl::MacroProps;
505 friend class ScientificNotation;
508 friend class impl::NumberFormatterImpl;
509 friend class impl::ScientificModifier;
510 friend class impl::ScientificHandler;
555 using Notation::Notation;
669 static FractionRounder minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
684 static DigitRounder fixedDigits(int32_t minMaxSignificantDigits);
698 static DigitRounder minDigits(int32_t minSignificantDigits);
708 static DigitRounder maxDigits(int32_t maxSignificantDigits);
721 static DigitRounder minMaxDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits);
779 RND_FRACTION_SIGNIFICANT,
808 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
811 fUnion.errorCode = errorCode;
814 Rounder() : fType(RND_BOGUS) {}
816 bool isBogus()
const {
817 return fType == RND_BOGUS;
821 if (fType == RND_ERROR) {
822 status = fUnion.errorCode;
829 Rounder withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
832 void setLocaleData(
const CurrencyUnit ¤cy,
UErrorCode &status);
834 void apply(impl::DecimalQuantity &value,
UErrorCode &status)
const;
837 void apply(impl::DecimalQuantity &value, int32_t minInt,
UErrorCode status);
840 chooseMultiplierAndApply(impl::DecimalQuantity &input,
const impl::MultiplierProducer &producer,
843 static FractionRounder constructFraction(int32_t minFrac, int32_t maxFrac);
845 static Rounder constructSignificant(int32_t minSig, int32_t maxSig);
848 constructFractionSignificant(
const FractionRounder &base, int32_t minSig, int32_t maxSig);
850 static IncrementRounder constructIncrement(
double increment, int32_t minFrac);
854 static Rounder constructPassThrough();
857 friend struct impl::MacroProps;
858 friend struct impl::MicroProps;
861 friend class impl::NumberFormatterImpl;
864 friend class impl::MutablePatternModifier;
865 friend class impl::LongNameHandler;
866 friend class impl::ScientificHandler;
867 friend class impl::CompactHandler;
870 friend class FractionRounder;
871 friend class CurrencyRounder;
872 friend class IncrementRounder;
902 Rounder withMinDigits(int32_t minSignificantDigits)
const;
921 Rounder withMaxDigits(int32_t maxSignificantDigits)
const;
925 using Rounder::Rounder;
963 using Rounder::Rounder;
995 Rounder withMinFraction(int32_t minFrac)
const;
999 using Rounder::Rounder;
1018 static Grouper minTwoDigits();
1030 Grouper(int8_t grouping1, int8_t grouping2,
bool min2)
1031 : fGrouping1(grouping1), fGrouping2(grouping2), fMin2(min2) {}
1033 Grouper() : fGrouping1(-3) {};
1035 bool isBogus()
const {
1036 return fGrouping1 == -3;
1040 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo);
1042 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1046 friend struct impl::MicroProps;
1049 friend class impl::NumberFormatterImpl;
1098 bool fHasError =
false;
1103 fUnion.errorCode = errorCode;
1108 fUnion.minMaxInt.fMinInt = -1;
1111 bool isBogus()
const {
1112 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1117 status = fUnion.errorCode;
1123 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1127 friend struct impl::MicroProps;
1130 friend class impl::NumberFormatterImpl;
1141 static constexpr int32_t DEFAULT_THRESHOLD = 3;
1150 SymbolsWrapper(
const SymbolsWrapper &other);
1156 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1174 bool isDecimalFormatSymbols()
const;
1180 bool isNumberingSystem()
const;
1196 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1199 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1207 enum SymbolsPointerType {
1208 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1216 void doCopyFrom(
const SymbolsWrapper &other);
1245 fUnion.errorCode = errorCode;
1250 bool isBogus()
const {
1251 return fWidth == -2;
1256 status = fUnion.errorCode;
1262 bool isValid()
const {
1266 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1267 impl::NumberStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1272 friend struct MicroProps;
1275 friend class impl::NumberFormatterImpl;
1316 int32_t threshold = DEFAULT_THRESHOLD;
1324 return notation.copyErrorTo(status) || rounder.copyErrorTo(status) ||
1325 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1336 template<
typename Derived>
1367 Derived notation(
const Notation ¬ation)
const;
1457 Derived rounding(
const Rounder &rounder)
const;
1459 #ifndef U_HIDE_INTERNAL_API 1490 Derived grouping(
const Grouper &grouper)
const;
1680 #ifndef U_HIDE_INTERNAL_API 1695 Derived threshold(int32_t threshold)
const;
1710 fMacros.copyErrorTo(outErrorCode);
1840 const impl::NumberFormatterImpl* fCompiled {
nullptr};
1841 char fUnsafeCallCount[8] {};
1843 LocalizedNumberFormatter() =
default;
1845 explicit LocalizedNumberFormatter(
const NumberFormatterSettings<LocalizedNumberFormatter> &other);
1847 LocalizedNumberFormatter(
const impl::MacroProps ¯os,
const Locale &locale);
1860 FormattedNumber formatImpl(impl::NumberFormatterResults *results,
UErrorCode &status)
const;
1863 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
1864 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
1867 friend class UnlocalizedNumberFormatter;
1942 const impl::NumberFormatterResults *fResults;
1951 : fResults(
nullptr), fErrorCode(errorCode) {};
1994 #endif // U_HIDE_DRAFT_API 1996 #endif // __NUMBERFORMATTER_H__
UNumberFormatRoundingMode
The possible number format rounding modes.
A class that defines a rounding strategy parameterized by a rounding increment to be used when format...
A unit such as length, mass, volume, currency, etc.
C++ API: Currency Unit Information.
A class that defines a rounding strategy based on a number of fraction places and optionally signific...
#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.
A class that defines the rounding strategy to be used when formatting numbers in NumberFormatter.
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.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
#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.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
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.
UCurrencyUsage
Currency Usage used for Decimal Format.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
#define TRUE
The TRUE value of a UBool.
A unit of currency, such as USD (U.S.
UNumberFormatPadPosition
The possible number format pad positions.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
UNumberCompactStyle
Constants for specifying short or long format.
A class that defines a rounding strategy parameterized by a currency to be used when formatting numbe...
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
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...
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
A string-like object that points to a sized piece of memory.
UMemory is the common ICU base class.
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.
UBool copyErrorTo(UErrorCode &status) const
A Locale object represents a specific geographical, political, or cultural region.