00001
00002
00003
00004 #include "unicode/utypes.h"
00005
00006 #if !UCONFIG_NO_FORMATTING
00007 #ifndef __NUMBERFORMATTER_H__
00008 #define __NUMBERFORMATTER_H__
00009
00010 #include "unicode/appendable.h"
00011 #include "unicode/dcfmtsym.h"
00012 #include "unicode/currunit.h"
00013 #include "unicode/fieldpos.h"
00014 #include "unicode/fpositer.h"
00015 #include "unicode/measunit.h"
00016 #include "unicode/nounit.h"
00017 #include "unicode/plurrule.h"
00018 #include "unicode/ucurr.h"
00019 #include "unicode/unum.h"
00020 #include "unicode/unumberformatter.h"
00021 #include "unicode/uobject.h"
00022
00023 #ifndef U_HIDE_DRAFT_API
00024
00079 U_NAMESPACE_BEGIN
00080
00081
00082 class IFixedDecimal;
00083 class FieldPositionIteratorHandler;
00084
00085 namespace numparse {
00086 namespace impl {
00087
00088
00089 class NumberParserImpl;
00090 class MultiplierParseHandler;
00091
00092 }
00093 }
00094
00095 namespace number {
00096
00097
00098 class UnlocalizedNumberFormatter;
00099 class LocalizedNumberFormatter;
00100 class FormattedNumber;
00101 class Notation;
00102 class ScientificNotation;
00103 class Precision;
00104 class FractionPrecision;
00105 class CurrencyPrecision;
00106 class IncrementPrecision;
00107 class IntegerWidth;
00108
00109 namespace impl {
00110
00116 typedef int16_t digits_t;
00117
00124 static constexpr int32_t DEFAULT_THRESHOLD = 3;
00125
00126
00127 class Padder;
00128 struct MacroProps;
00129 struct MicroProps;
00130 class DecimalQuantity;
00131 struct UFormattedNumberData;
00132 class NumberFormatterImpl;
00133 struct ParsedPatternInfo;
00134 class ScientificModifier;
00135 class MultiplierProducer;
00136 class RoundingImpl;
00137 class ScientificHandler;
00138 class Modifier;
00139 class NumberStringBuilder;
00140 class AffixPatternProvider;
00141 class NumberPropertyMapper;
00142 struct DecimalFormatProperties;
00143 class MultiplierFormatHandler;
00144 class CurrencySymbols;
00145 class GeneratorHelpers;
00146 class DecNum;
00147 class NumberRangeFormatterImpl;
00148 struct RangeMacroProps;
00149
00156 void touchRangeLocales(impl::RangeMacroProps& macros);
00157
00158 }
00159
00165 typedef Notation CompactNotation;
00166
00172 typedef Notation SimpleNotation;
00173
00179 class U_I18N_API Notation : public UMemory {
00180 public:
00205 static ScientificNotation scientific();
00206
00229 static ScientificNotation engineering();
00230
00272 static CompactNotation compactShort();
00273
00296 static CompactNotation compactLong();
00297
00322 static SimpleNotation simple();
00323
00324 private:
00325 enum NotationType {
00326 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
00327 } fType;
00328
00329 union NotationUnion {
00330
00332 struct ScientificSettings {
00334 int8_t fEngineeringInterval;
00336 bool fRequireMinInt;
00338 impl::digits_t fMinExponentDigits;
00340 UNumberSignDisplay fExponentSignDisplay;
00341 } scientific;
00342
00343
00344 UNumberCompactStyle compactStyle;
00345
00346
00347 UErrorCode errorCode;
00348 } fUnion;
00349
00350 typedef NotationUnion::ScientificSettings ScientificSettings;
00351
00352 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
00353
00354 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
00355 fUnion.errorCode = errorCode;
00356 }
00357
00358 Notation() : fType(NTN_SIMPLE), fUnion() {}
00359
00360 UBool copyErrorTo(UErrorCode &status) const {
00361 if (fType == NTN_ERROR) {
00362 status = fUnion.errorCode;
00363 return TRUE;
00364 }
00365 return FALSE;
00366 }
00367
00368
00369 friend struct impl::MacroProps;
00370 friend class ScientificNotation;
00371
00372
00373 friend class impl::NumberFormatterImpl;
00374 friend class impl::ScientificModifier;
00375 friend class impl::ScientificHandler;
00376
00377
00378 friend class impl::GeneratorHelpers;
00379 };
00380
00389 class U_I18N_API ScientificNotation : public Notation {
00390 public:
00404 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
00405
00419 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
00420
00421 private:
00422
00423 using Notation::Notation;
00424
00425
00426 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
00427 UNumberSignDisplay fExponentSignDisplay);
00428
00429 friend class Notation;
00430
00431
00432 friend class impl::NumberPropertyMapper;
00433 };
00434
00440 typedef Precision SignificantDigitsPrecision;
00441
00442
00443
00444
00445
00450 typedef Precision Rounder;
00451
00456 typedef FractionPrecision FractionRounder;
00457
00462 typedef IncrementPrecision IncrementRounder;
00463
00468 typedef CurrencyPrecision CurrencyRounder;
00469
00478 class U_I18N_API Precision : public UMemory {
00479
00480 public:
00497 static Precision unlimited();
00498
00505 static FractionPrecision integer();
00506
00534 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
00535
00549 static FractionPrecision minFraction(int32_t minFractionPlaces);
00550
00561 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
00562
00576 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
00577
00591 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
00592
00605 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
00606
00615 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
00616
00628 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
00629 int32_t maxSignificantDigits);
00630
00631 #ifndef U_HIDE_DEPRECATED_API
00632
00633
00634
00636 static inline SignificantDigitsPrecision fixedDigits(int32_t a) {
00637 return fixedSignificantDigits(a);
00638 }
00639
00641 static inline SignificantDigitsPrecision minDigits(int32_t a) {
00642 return minSignificantDigits(a);
00643 }
00644
00646 static inline SignificantDigitsPrecision maxDigits(int32_t a) {
00647 return maxSignificantDigits(a);
00648 }
00649
00651 static inline SignificantDigitsPrecision minMaxDigits(int32_t a, int32_t b) {
00652 return minMaxSignificantDigits(a, b);
00653 }
00654 #endif
00655
00675 static IncrementPrecision increment(double roundingIncrement);
00676
00694 static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
00695
00696 #ifndef U_HIDE_DEPRECATED_API
00697
00708 Precision withMode(UNumberFormatRoundingMode roundingMode) const;
00709 #endif
00710
00711 private:
00712 enum PrecisionType {
00713 RND_BOGUS,
00714 RND_NONE,
00715 RND_FRACTION,
00716 RND_SIGNIFICANT,
00717 RND_FRACTION_SIGNIFICANT,
00718 RND_INCREMENT,
00719 RND_CURRENCY,
00720 RND_ERROR
00721 } fType;
00722
00723 union PrecisionUnion {
00725 struct FractionSignificantSettings {
00726
00728 impl::digits_t fMinFrac;
00730 impl::digits_t fMaxFrac;
00732 impl::digits_t fMinSig;
00734 impl::digits_t fMaxSig;
00735 } fracSig;
00737 struct IncrementSettings {
00739 double fIncrement;
00741 impl::digits_t fMinFrac;
00743 impl::digits_t fMaxFrac;
00744 } increment;
00745 UCurrencyUsage currencyUsage;
00746 UErrorCode errorCode;
00747 } fUnion;
00748
00749 typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
00750 typedef PrecisionUnion::IncrementSettings IncrementSettings;
00751
00753 UNumberFormatRoundingMode fRoundingMode;
00754
00755 Precision(const PrecisionType& type, const PrecisionUnion& union_,
00756 UNumberFormatRoundingMode roundingMode)
00757 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
00758
00759 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
00760 fUnion.errorCode = errorCode;
00761 }
00762
00763 Precision() : fType(RND_BOGUS) {}
00764
00765 bool isBogus() const {
00766 return fType == RND_BOGUS;
00767 }
00768
00769 UBool copyErrorTo(UErrorCode &status) const {
00770 if (fType == RND_ERROR) {
00771 status = fUnion.errorCode;
00772 return TRUE;
00773 }
00774 return FALSE;
00775 }
00776
00777
00778 Precision withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const;
00779
00780 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
00781
00782 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
00783
00784 static Precision
00785 constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig);
00786
00787 static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
00788
00789 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
00790
00791 static Precision constructPassThrough();
00792
00793
00794 friend struct impl::MacroProps;
00795 friend struct impl::MicroProps;
00796
00797
00798 friend class impl::NumberFormatterImpl;
00799
00800
00801 friend class impl::NumberPropertyMapper;
00802
00803
00804 friend class impl::RoundingImpl;
00805
00806
00807 friend class FractionPrecision;
00808 friend class CurrencyPrecision;
00809 friend class IncrementPrecision;
00810
00811
00812 friend class impl::GeneratorHelpers;
00813 };
00814
00824 class U_I18N_API FractionPrecision : public Precision {
00825 public:
00842 Precision withMinDigits(int32_t minSignificantDigits) const;
00843
00861 Precision withMaxDigits(int32_t maxSignificantDigits) const;
00862
00863 private:
00864
00865 using Precision::Precision;
00866
00867
00868 friend class Precision;
00869 };
00870
00880 class U_I18N_API CurrencyPrecision : public Precision {
00881 public:
00899 Precision withCurrency(const CurrencyUnit ¤cy) const;
00900
00901 private:
00902
00903 using Precision::Precision;
00904
00905
00906 friend class Precision;
00907 };
00908
00918 class U_I18N_API IncrementPrecision : public Precision {
00919 public:
00935 Precision withMinFraction(int32_t minFrac) const;
00936
00937 private:
00938
00939 using Precision::Precision;
00940
00941
00942 friend class Precision;
00943 };
00944
00954 class U_I18N_API IntegerWidth : public UMemory {
00955 public:
00967 static IntegerWidth zeroFillTo(int32_t minInt);
00968
00980 IntegerWidth truncateAt(int32_t maxInt);
00981
00982 private:
00983 union {
00984 struct {
00985 impl::digits_t fMinInt;
00986 impl::digits_t fMaxInt;
00987 bool fFormatFailIfMoreThanMaxDigits;
00988 } minMaxInt;
00989 UErrorCode errorCode;
00990 } fUnion;
00991 bool fHasError = false;
00992
00993 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
00994
00995 IntegerWidth(UErrorCode errorCode) {
00996 fUnion.errorCode = errorCode;
00997 fHasError = true;
00998 }
00999
01000 IntegerWidth() {
01001 fUnion.minMaxInt.fMinInt = -1;
01002 }
01003
01005 static IntegerWidth standard() {
01006 return IntegerWidth::zeroFillTo(1);
01007 }
01008
01009 bool isBogus() const {
01010 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
01011 }
01012
01013 UBool copyErrorTo(UErrorCode &status) const {
01014 if (fHasError) {
01015 status = fUnion.errorCode;
01016 return TRUE;
01017 }
01018 return FALSE;
01019 }
01020
01021 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
01022
01023 bool operator==(const IntegerWidth& other) const;
01024
01025
01026 friend struct impl::MacroProps;
01027 friend struct impl::MicroProps;
01028
01029
01030 friend class impl::NumberFormatterImpl;
01031
01032
01033 friend class impl::NumberPropertyMapper;
01034
01035
01036 friend class impl::GeneratorHelpers;
01037 };
01038
01047 class U_I18N_API Scale : public UMemory {
01048 public:
01055 static Scale none();
01056
01067 static Scale powerOfTen(int32_t power);
01068
01081 static Scale byDecimal(StringPiece multiplicand);
01082
01091 static Scale byDouble(double multiplicand);
01092
01099 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
01100
01101
01102
01103
01105 Scale(const Scale& other);
01106
01108 Scale& operator=(const Scale& other);
01109
01111 Scale(Scale&& src) U_NOEXCEPT;
01112
01114 Scale& operator=(Scale&& src) U_NOEXCEPT;
01115
01117 ~Scale();
01118
01119 #ifndef U_HIDE_INTERNAL_API
01120
01121 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
01122 #endif
01123
01124 private:
01125 int32_t fMagnitude;
01126 impl::DecNum* fArbitrary;
01127 UErrorCode fError;
01128
01129 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
01130
01131 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
01132
01133 bool isValid() const {
01134 return fMagnitude != 0 || fArbitrary != nullptr;
01135 }
01136
01137 UBool copyErrorTo(UErrorCode &status) const {
01138 if (fError != U_ZERO_ERROR) {
01139 status = fError;
01140 return TRUE;
01141 }
01142 return FALSE;
01143 }
01144
01145 void applyTo(impl::DecimalQuantity& quantity) const;
01146
01147 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
01148
01149
01150 friend struct impl::MacroProps;
01151 friend struct impl::MicroProps;
01152
01153
01154 friend class impl::NumberFormatterImpl;
01155
01156
01157 friend class impl::MultiplierFormatHandler;
01158
01159
01160 friend class impl::GeneratorHelpers;
01161
01162
01163 friend class ::icu::numparse::impl::NumberParserImpl;
01164 friend class ::icu::numparse::impl::MultiplierParseHandler;
01165 };
01166
01167 namespace impl {
01168
01169
01171 class U_I18N_API SymbolsWrapper : public UMemory {
01172 public:
01174 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
01175
01177 SymbolsWrapper(const SymbolsWrapper &other);
01178
01180 SymbolsWrapper &operator=(const SymbolsWrapper &other);
01181
01183 SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
01184
01186 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
01187
01189 ~SymbolsWrapper();
01190
01191 #ifndef U_HIDE_INTERNAL_API
01192
01197 void setTo(const DecimalFormatSymbols &dfs);
01198
01203 void setTo(const NumberingSystem *ns);
01204
01209 bool isDecimalFormatSymbols() const;
01210
01215 bool isNumberingSystem() const;
01216
01221 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
01222
01227 const NumberingSystem *getNumberingSystem() const;
01228
01229 #endif // U_HIDE_INTERNAL_API
01230
01232 UBool copyErrorTo(UErrorCode &status) const {
01233 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
01234 status = U_MEMORY_ALLOCATION_ERROR;
01235 return TRUE;
01236 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
01237 status = U_MEMORY_ALLOCATION_ERROR;
01238 return TRUE;
01239 }
01240 return FALSE;
01241 }
01242
01243 private:
01244 enum SymbolsPointerType {
01245 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
01246 } fType;
01247
01248 union {
01249 const DecimalFormatSymbols *dfs;
01250 const NumberingSystem *ns;
01251 } fPtr;
01252
01253 void doCopyFrom(const SymbolsWrapper &other);
01254
01255 void doMoveFrom(SymbolsWrapper&& src);
01256
01257 void doCleanup();
01258 };
01259
01260
01262 class U_I18N_API Grouper : public UMemory {
01263 public:
01264 #ifndef U_HIDE_INTERNAL_API
01265
01266 static Grouper forStrategy(UNumberGroupingStrategy grouping);
01267
01272 static Grouper forProperties(const DecimalFormatProperties& properties);
01273
01274
01275
01277 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
01278 : fGrouping1(grouping1),
01279 fGrouping2(grouping2),
01280 fMinGrouping(minGrouping),
01281 fStrategy(strategy) {}
01282 #endif // U_HIDE_INTERNAL_API
01283
01285 int16_t getPrimary() const;
01286
01288 int16_t getSecondary() const;
01289
01290 private:
01299 int16_t fGrouping1;
01300 int16_t fGrouping2;
01301
01309 int16_t fMinGrouping;
01310
01315 UNumberGroupingStrategy fStrategy;
01316
01317 Grouper() : fGrouping1(-3) {};
01318
01319 bool isBogus() const {
01320 return fGrouping1 == -3;
01321 }
01322
01324 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
01325
01326 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
01327
01328
01329 friend struct MacroProps;
01330 friend struct MicroProps;
01331
01332
01333 friend class NumberFormatterImpl;
01334
01335
01336 friend class ::icu::numparse::impl::NumberParserImpl;
01337
01338
01339 friend class impl::GeneratorHelpers;
01340 };
01341
01342
01344 class U_I18N_API Padder : public UMemory {
01345 public:
01346 #ifndef U_HIDE_INTERNAL_API
01347
01348 static Padder none();
01349
01351 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
01352 #endif // U_HIDE_INTERNAL_API
01353
01355 static Padder forProperties(const DecimalFormatProperties& properties);
01356
01357 private:
01358 UChar32 fWidth;
01359 union {
01360 struct {
01361 int32_t fCp;
01362 UNumberFormatPadPosition fPosition;
01363 } padding;
01364 UErrorCode errorCode;
01365 } fUnion;
01366
01367 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
01368
01369 Padder(int32_t width);
01370
01371 Padder(UErrorCode errorCode) : fWidth(-3) {
01372 fUnion.errorCode = errorCode;
01373 }
01374
01375 Padder() : fWidth(-2) {}
01376
01377 bool isBogus() const {
01378 return fWidth == -2;
01379 }
01380
01381 UBool copyErrorTo(UErrorCode &status) const {
01382 if (fWidth == -3) {
01383 status = fUnion.errorCode;
01384 return TRUE;
01385 }
01386 return FALSE;
01387 }
01388
01389 bool isValid() const {
01390 return fWidth > 0;
01391 }
01392
01393 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
01394 impl::NumberStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
01395 UErrorCode &status) const;
01396
01397
01398 friend struct MacroProps;
01399 friend struct MicroProps;
01400
01401
01402 friend class impl::NumberFormatterImpl;
01403
01404
01405 friend class impl::GeneratorHelpers;
01406 };
01407
01408
01410 struct U_I18N_API MacroProps : public UMemory {
01412 Notation notation;
01413
01415 MeasureUnit unit;
01416
01418 MeasureUnit perUnit;
01419
01421 Precision precision;
01422
01424 UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
01425
01427 Grouper grouper;
01428
01430 Padder padder;
01431
01433 IntegerWidth integerWidth;
01434
01436 SymbolsWrapper symbols;
01437
01438
01439
01441 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
01442
01444 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
01445
01447 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
01448
01450 Scale scale;
01451
01453 const AffixPatternProvider* affixProvider = nullptr;
01454
01456 const PluralRules* rules = nullptr;
01457
01459 const CurrencySymbols* currencySymbols = nullptr;
01460
01462 int32_t threshold = DEFAULT_THRESHOLD;
01463
01465 Locale locale;
01466
01467
01468
01473 bool copyErrorTo(UErrorCode &status) const {
01474 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
01475 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
01476 symbols.copyErrorTo(status) || scale.copyErrorTo(status);
01477 }
01478 };
01479
01480 }
01481
01487 template<typename Derived>
01488 class U_I18N_API NumberFormatterSettings {
01489 public:
01518 Derived notation(const Notation ¬ation) const &;
01519
01529 Derived notation(const Notation ¬ation) &&;
01530
01575 Derived unit(const icu::MeasureUnit &unit) const &;
01576
01586 Derived unit(const icu::MeasureUnit &unit) &&;
01587
01603 Derived adoptUnit(icu::MeasureUnit *unit) const &;
01604
01614 Derived adoptUnit(icu::MeasureUnit *unit) &&;
01615
01633 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
01634
01644 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
01645
01663 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
01664
01674 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
01675
01706 Derived precision(const Precision& precision) const &;
01707
01717 Derived precision(const Precision& precision) &&;
01718
01719 #ifndef U_HIDE_DEPRECATED_API
01720
01721
01722
01724 Derived rounding(const Rounder& rounder) const & {
01725 return precision(rounder);
01726 }
01727 #endif
01728
01747 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
01748
01757 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
01758
01786 Derived grouping(UNumberGroupingStrategy strategy) const &;
01787
01797 Derived grouping(UNumberGroupingStrategy strategy) &&;
01798
01823 Derived integerWidth(const IntegerWidth &style) const &;
01824
01834 Derived integerWidth(const IntegerWidth &style) &&;
01835
01876 Derived symbols(const DecimalFormatSymbols &symbols) const &;
01877
01887 Derived symbols(const DecimalFormatSymbols &symbols) &&;
01888
01922 Derived adoptSymbols(NumberingSystem *symbols) const &;
01923
01933 Derived adoptSymbols(NumberingSystem *symbols) &&;
01934
01960 Derived unitWidth(UNumberUnitWidth width) const &;
01961
01971 Derived unitWidth(UNumberUnitWidth width) &&;
01972
01998 Derived sign(UNumberSignDisplay style) const &;
01999
02009 Derived sign(UNumberSignDisplay style) &&;
02010
02036 Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
02037
02047 Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
02048
02073 Derived scale(const Scale &scale) const &;
02074
02084 Derived scale(const Scale &scale) &&;
02085
02086 #ifndef U_HIDE_INTERNAL_API
02087
02093 Derived padding(const impl::Padder &padder) const &;
02094
02096 Derived padding(const impl::Padder &padder) &&;
02097
02104 Derived threshold(int32_t threshold) const &;
02105
02107 Derived threshold(int32_t threshold) &&;
02108
02114 Derived macros(const impl::MacroProps& macros) const &;
02115
02117 Derived macros(const impl::MacroProps& macros) &&;
02118
02120 Derived macros(impl::MacroProps&& macros) const &;
02121
02123 Derived macros(impl::MacroProps&& macros) &&;
02124
02125 #endif
02126
02141 UnicodeString toSkeleton(UErrorCode& status) const;
02142
02149 UBool copyErrorTo(UErrorCode &outErrorCode) const {
02150 if (U_FAILURE(outErrorCode)) {
02151
02152 return TRUE;
02153 }
02154 fMacros.copyErrorTo(outErrorCode);
02155 return U_FAILURE(outErrorCode);
02156 };
02157
02158
02159
02160 private:
02161 impl::MacroProps fMacros;
02162
02163
02164 NumberFormatterSettings() = default;
02165
02166 friend class LocalizedNumberFormatter;
02167 friend class UnlocalizedNumberFormatter;
02168
02169
02170 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
02171 friend class impl::NumberRangeFormatterImpl;
02172 };
02173
02180 class U_I18N_API UnlocalizedNumberFormatter
02181 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
02182
02183 public:
02193 LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
02194
02204 LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
02205
02211 UnlocalizedNumberFormatter() = default;
02212
02217 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
02218
02224 UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02225
02230 UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
02231
02237 UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02238
02239 private:
02240 explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
02241
02242 explicit UnlocalizedNumberFormatter(
02243 NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) U_NOEXCEPT;
02244
02245
02246 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02247
02248
02249 friend class NumberFormatter;
02250 };
02251
02258 class U_I18N_API LocalizedNumberFormatter
02259 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
02260 public:
02272 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
02273
02285 FormattedNumber formatDouble(double value, UErrorCode &status) const;
02286
02301 FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
02302
02303 #ifndef U_HIDE_INTERNAL_API
02304
02308 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
02309
02313 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
02314
02319 const impl::NumberFormatterImpl* getCompiled() const;
02320
02325 int32_t getCallCount() const;
02326
02327 #endif
02328
02342 Format* toFormat(UErrorCode& status) const;
02343
02349 LocalizedNumberFormatter() = default;
02350
02355 LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
02356
02362 LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02363
02368 LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
02369
02375 LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02376
02377 #ifndef U_HIDE_INTERNAL_API
02378
02391 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
02392
02393 #endif
02394
02399 ~LocalizedNumberFormatter();
02400
02401 private:
02402
02403
02404 const impl::NumberFormatterImpl* fCompiled {nullptr};
02405 char fUnsafeCallCount[8] {};
02406
02407 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
02408
02409 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
02410
02411 LocalizedNumberFormatter(const impl::MacroProps ¯os, const Locale &locale);
02412
02413 LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale);
02414
02415 void clear();
02416
02417 void lnfMoveHelper(LocalizedNumberFormatter&& src);
02418
02422 bool computeCompiled(UErrorCode& status) const;
02423
02424
02425 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02426 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
02427
02428
02429 friend class UnlocalizedNumberFormatter;
02430 };
02431
02438 class U_I18N_API FormattedNumber : public UMemory {
02439 public:
02440 #ifndef U_HIDE_DEPRECATED_API
02441
02449 UnicodeString toString() const;
02450 #endif
02451
02460 UnicodeString toString(UErrorCode& status) const;
02461
02462 #ifndef U_HIDE_DEPRECATED_API
02463
02474 Appendable &appendTo(Appendable &appendable);
02475 #endif
02476
02488 Appendable &appendTo(Appendable &appendable, UErrorCode& status) const;
02489
02490 #ifndef U_HIDE_DEPRECATED_API
02491
02511 void populateFieldPosition(FieldPosition &fieldPosition, UErrorCode &status);
02512 #endif
02513
02545 UBool nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const;
02546
02547 #ifndef U_HIDE_DEPRECATED_API
02548
02563 void populateFieldPositionIterator(FieldPositionIterator &iterator, UErrorCode &status);
02564 #endif
02565
02579 void getAllFieldPositions(FieldPositionIterator &iterator, UErrorCode &status) const;
02580
02581 #ifndef U_HIDE_INTERNAL_API
02582
02587 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
02588
02593 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
02594
02595 #endif
02596
02600 FormattedNumber(const FormattedNumber&) = delete;
02601
02605 FormattedNumber& operator=(const FormattedNumber&) = delete;
02606
02612 FormattedNumber(FormattedNumber&& src) U_NOEXCEPT;
02613
02619 FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT;
02620
02625 ~FormattedNumber();
02626
02627 private:
02628
02629 const impl::UFormattedNumberData *fResults;
02630
02631
02632 UErrorCode fErrorCode;
02633
02638 explicit FormattedNumber(impl::UFormattedNumberData *results)
02639 : fResults(results), fErrorCode(U_ZERO_ERROR) {};
02640
02641 explicit FormattedNumber(UErrorCode errorCode)
02642 : fResults(nullptr), fErrorCode(errorCode) {};
02643
02644
02645 friend class LocalizedNumberFormatter;
02646 };
02647
02653 class U_I18N_API NumberFormatter final {
02654 public:
02662 static UnlocalizedNumberFormatter with();
02663
02673 static LocalizedNumberFormatter withLocale(const Locale &locale);
02674
02686 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
02687
02691 NumberFormatter() = delete;
02692 };
02693
02694 }
02695 U_NAMESPACE_END
02696
02697 #endif // U_HIDE_DRAFT_API
02698
02699 #endif // __NUMBERFORMATTER_H__
02700
02701 #endif