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 SimpleNumberFormatter;
116 class FormattedNumber;
118 class ScientificNotation;
120 class FractionPrecision;
121 class CurrencyPrecision;
122 class IncrementPrecision;
133 typedef int16_t digits_t;
142 static constexpr int32_t kInternalDefaultThreshold = 3;
148 class DecimalQuantity;
149 class UFormattedNumberData;
150 class NumberFormatterImpl;
151 struct ParsedPatternInfo;
152 class ScientificModifier;
153 class MultiplierProducer;
155 class ScientificHandler;
157 class AffixPatternProvider;
158 class NumberPropertyMapper;
159 struct DecimalFormatProperties;
160 class MultiplierFormatHandler;
161 class CurrencySymbols;
162 class GeneratorHelpers;
164 class NumberRangeFormatterImpl;
165 struct RangeMacroProps;
166 struct UFormattedNumberImpl;
167 class MutablePatternModifier;
168 class ImmutablePatternModifier;
169 struct DecimalFormatWarehouse;
170 struct SimpleMicroProps;
171 class AdoptingSignumModifierStore;
179 void touchRangeLocales(impl::RangeMacroProps& macros);
188 typedef Notation CompactNotation;
195 typedef Notation SimpleNotation;
349 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
352 union NotationUnion {
375 Notation(
const NotationType &type,
const NotationUnion &union_) : fType(type), fUnion(union_) {}
378 fUnion.errorCode = errorCode;
381 Notation() : fType(NTN_SIMPLE), fUnion() {}
384 if (fType == NTN_ERROR) {
385 status = fUnion.errorCode;
392 friend struct impl::MacroProps;
393 friend class ScientificNotation;
396 friend class impl::NumberFormatterImpl;
397 friend class impl::ScientificModifier;
398 friend class impl::ScientificHandler;
401 friend class impl::GeneratorHelpers;
446 using Notation::Notation;
449 ScientificNotation(int8_t fEngineeringInterval,
bool fRequireMinInt, impl::digits_t fMinExponentDigits,
455 friend class impl::NumberPropertyMapper;
572 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
625 int32_t maxSignificantDigits);
707 RND_FRACTION_SIGNIFICANT,
724 union PrecisionUnion {
765 Precision(
const PrecisionType& type,
const PrecisionUnion& union_)
766 : fType(type), fUnion(union_) {}
769 fUnion.errorCode = errorCode;
772 Precision() : fType(RND_BOGUS) {}
774 bool isBogus()
const {
775 return fType == RND_BOGUS;
779 if (fType == RND_ERROR) {
780 status = fUnion.errorCode;
787 Precision withCurrency(
const CurrencyUnit ¤cy,
UErrorCode &status)
const;
789 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
791 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
793 static Precision constructFractionSignificant(
794 const FractionPrecision &base,
800 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
805 friend struct impl::MacroProps;
806 friend struct impl::MicroProps;
809 friend class impl::NumberFormatterImpl;
812 friend class impl::NumberPropertyMapper;
815 friend class impl::RoundingImpl;
818 friend class FractionPrecision;
819 friend class CurrencyPrecision;
820 friend class IncrementPrecision;
823 friend class impl::GeneratorHelpers;
826 friend class units::UnitsRouter;
855 int32_t minSignificantDigits,
856 int32_t maxSignificantDigits,
876 Precision withMinDigits(int32_t minSignificantDigits)
const;
895 Precision withMaxDigits(int32_t maxSignificantDigits)
const;
899 using Precision::Precision;
937 using Precision::Precision;
969 Precision withMinFraction(int32_t minFrac)
const;
973 using Precision::Precision;
1019 impl::digits_t fMinInt;
1020 impl::digits_t fMaxInt;
1021 bool fFormatFailIfMoreThanMaxDigits;
1025 bool fHasError =
false;
1027 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt,
bool formatFailIfMoreThanMaxDigits);
1030 fUnion.errorCode = errorCode;
1035 fUnion.minMaxInt.fMinInt = -1;
1040 return IntegerWidth::zeroFillTo(1);
1043 bool isBogus()
const {
1044 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1049 status = fUnion.errorCode;
1055 void apply(impl::DecimalQuantity &quantity,
UErrorCode &status)
const;
1061 friend struct impl::MicroProps;
1064 friend class impl::NumberFormatterImpl;
1067 friend class impl::MutablePatternModifier;
1068 friend class impl::ImmutablePatternModifier;
1071 friend class impl::NumberPropertyMapper;
1074 friend class impl::GeneratorHelpers;
1093 static Scale none();
1105 static Scale powerOfTen(int32_t power);
1129 static Scale byDouble(
double multiplicand);
1137 static Scale byDoubleAndPowerOfTen(
double multiplicand, int32_t power);
1157 #ifndef U_HIDE_INTERNAL_API
1159 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1164 impl::DecNum* fArbitrary;
1167 Scale(
UErrorCode error) : fMagnitude(0), fArbitrary(
nullptr), fError(error) {}
1171 bool isValid()
const {
1172 return fMagnitude != 0 || fArbitrary !=
nullptr;
1183 void applyTo(impl::DecimalQuantity& quantity)
const;
1185 void applyReciprocalTo(impl::DecimalQuantity& quantity)
const;
1189 friend struct impl::MicroProps;
1192 friend class impl::NumberFormatterImpl;
1195 friend class impl::MultiplierFormatHandler;
1198 friend class impl::GeneratorHelpers;
1201 friend class ::icu::numparse::impl::NumberParserImpl;
1202 friend class ::icu::numparse::impl::MultiplierParseHandler;
1225 #ifndef U_HIDE_INTERNAL_API
1248 #endif // U_HIDE_INTERNAL_API
1268 friend class impl::NumberFormatterImpl;
1271 friend class impl::GeneratorHelpers;
1275 friend struct impl::MacroProps;
1286 SymbolsWrapper(
const SymbolsWrapper &other);
1289 SymbolsWrapper &operator=(
const SymbolsWrapper &other);
1292 SymbolsWrapper(SymbolsWrapper&& src) noexcept;
1295 SymbolsWrapper &operator=(SymbolsWrapper&& src) noexcept;
1300 #ifndef U_HIDE_INTERNAL_API
1318 bool isDecimalFormatSymbols()
const;
1324 bool isNumberingSystem()
const;
1338 #endif // U_HIDE_INTERNAL_API
1342 if (fType == SYMPTR_DFS && fPtr.dfs ==
nullptr) {
1345 }
else if (fType == SYMPTR_NS && fPtr.ns ==
nullptr) {
1353 enum SymbolsPointerType {
1354 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1362 void doCopyFrom(
const SymbolsWrapper &other);
1364 void doMoveFrom(SymbolsWrapper&& src);
1373 #ifndef U_HIDE_INTERNAL_API
1381 static Grouper forProperties(
const DecimalFormatProperties& properties);
1387 : fGrouping1(grouping1),
1388 fGrouping2(grouping2),
1389 fMinGrouping(minGrouping),
1390 fStrategy(strategy) {}
1393 int16_t getPrimary()
const;
1396 int16_t getSecondary()
const;
1397 #endif // U_HIDE_INTERNAL_API
1418 int16_t fMinGrouping;
1428 bool isBogus()
const {
1429 return fGrouping1 == -3;
1433 void setLocaleData(
const impl::ParsedPatternInfo &patternInfo,
const Locale& locale);
1435 bool groupAtPosition(int32_t position,
const impl::DecimalQuantity &value)
const;
1438 friend struct MacroProps;
1439 friend struct MicroProps;
1440 friend struct SimpleMicroProps;
1443 friend class NumberFormatterImpl;
1444 friend class ::icu::number::SimpleNumberFormatter;
1447 friend class ::icu::numparse::impl::NumberParserImpl;
1450 friend class impl::GeneratorHelpers;
1457 #ifndef U_HIDE_INTERNAL_API
1465 static Padder forProperties(
const DecimalFormatProperties& properties);
1466 #endif // U_HIDE_INTERNAL_API
1483 fUnion.errorCode = errorCode;
1488 bool isBogus()
const {
1489 return fWidth == -2;
1494 status = fUnion.errorCode;
1500 bool isValid()
const {
1504 int32_t padAndApply(
const impl::Modifier &mod1,
const impl::Modifier &mod2,
1505 FormattedStringBuilder &
string, int32_t leftIndex, int32_t rightIndex,
1510 friend struct MicroProps;
1513 friend class impl::NumberFormatterImpl;
1516 friend class impl::GeneratorHelpers;
1558 bool approximately =
false;
1573 const AffixPatternProvider* affixProvider =
nullptr;
1579 int32_t threshold = kInternalDefaultThreshold;
1591 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1592 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1593 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1594 unitDisplayCase.copyErrorTo(status);
1600 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1606 #pragma warning(push)
1607 #pragma warning(disable: 4661)
1615 template<
typename Derived>
1646 Derived notation(
const Notation ¬ation)
const &;
1657 Derived notation(
const Notation ¬ation) &&;
1837 Derived precision(
const Precision& precision)
const &;
1848 Derived precision(
const Precision& precision) &&;
1944 Derived integerWidth(
const IntegerWidth &style)
const &;
2194 Derived scale(
const Scale &scale)
const &;
2205 Derived scale(
const Scale &scale) &&;
2260 #ifndef U_HIDE_DRAFT_API
2269 Derived displayOptions(
const DisplayOptions &displayOptions)
const &;
2279 #endif // U_HIDE_DRAFT_API
2281 #ifndef U_HIDE_INTERNAL_API
2292 Derived unitDisplayCase(
StringPiece unitDisplayCase)
const &;
2303 Derived unitDisplayCase(
StringPiece unitDisplayCase) &&;
2304 #endif // U_HIDE_INTERNAL_API
2306 #ifndef U_HIDE_INTERNAL_API
2324 Derived threshold(int32_t threshold)
const &;
2327 Derived threshold(int32_t threshold) &&;
2399 fMacros.copyErrorTo(outErrorCode);
2416 friend class impl::NumberRangeFormatterImpl;
2422 extern template class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2423 extern template class NumberFormatterSettings<LocalizedNumberFormatter>;
2559 #ifndef U_HIDE_INTERNAL_API
2581 const impl::NumberFormatterImpl* getCompiled()
const;
2587 int32_t getCallCount()
const;
2639 #ifndef U_HIDE_INTERNAL_API
2653 void formatImpl(impl::UFormattedNumberData *results,
UErrorCode &status)
const;
2666 const impl::NumberFormatterImpl* fCompiled {
nullptr};
2667 char fUnsafeCallCount[8] {};
2671 const impl::DecimalFormatWarehouse* fWarehouse {
nullptr};
2681 void resetCompiled();
2690 bool computeCompiled(
UErrorCode& status)
const;
2700 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2702 #pragma warning(pop)
2787 #endif // __NUMBERFORMATTER_H__
C++ API: Display options class.
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.
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.
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.
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
int8_t UBool
The ICU boolean type, a signed-byte integer.
C API: Compatibility APIs for number formatting.
A Locale object represents a specific geographical, political, or cultural region.