00001
00002
00003
00004 #ifndef __NUMBERFORMATTER_H__
00005 #define __NUMBERFORMATTER_H__
00006
00007 #include "unicode/utypes.h"
00008
00009 #if U_SHOW_CPLUSPLUS_API
00010
00011 #if !UCONFIG_NO_FORMATTING
00012
00013 #include "unicode/appendable.h"
00014 #include "unicode/bytestream.h"
00015 #include "unicode/currunit.h"
00016 #include "unicode/dcfmtsym.h"
00017 #include "unicode/fieldpos.h"
00018 #include "unicode/formattedvalue.h"
00019 #include "unicode/fpositer.h"
00020 #include "unicode/measunit.h"
00021 #include "unicode/nounit.h"
00022 #include "unicode/parseerr.h"
00023 #include "unicode/plurrule.h"
00024 #include "unicode/ucurr.h"
00025 #include "unicode/unum.h"
00026 #include "unicode/unumberformatter.h"
00027 #include "unicode/uobject.h"
00028
00085 U_NAMESPACE_BEGIN
00086
00087
00088 class IFixedDecimal;
00089 class FieldPositionIteratorHandler;
00090 class FormattedStringBuilder;
00091
00092 namespace numparse {
00093 namespace impl {
00094
00095
00096 class NumberParserImpl;
00097 class MultiplierParseHandler;
00098
00099 }
00100 }
00101
00102 namespace number {
00103
00104
00105 class UnlocalizedNumberFormatter;
00106 class LocalizedNumberFormatter;
00107 class FormattedNumber;
00108 class Notation;
00109 class ScientificNotation;
00110 class Precision;
00111 class FractionPrecision;
00112 class CurrencyPrecision;
00113 class IncrementPrecision;
00114 class IntegerWidth;
00115
00116 namespace impl {
00117
00118
00124 typedef int16_t digits_t;
00125
00126
00133 static constexpr int32_t kInternalDefaultThreshold = 3;
00134
00135
00136 class Padder;
00137 struct MacroProps;
00138 struct MicroProps;
00139 class DecimalQuantity;
00140 class UFormattedNumberData;
00141 class NumberFormatterImpl;
00142 struct ParsedPatternInfo;
00143 class ScientificModifier;
00144 class MultiplierProducer;
00145 class RoundingImpl;
00146 class ScientificHandler;
00147 class Modifier;
00148 class AffixPatternProvider;
00149 class NumberPropertyMapper;
00150 struct DecimalFormatProperties;
00151 class MultiplierFormatHandler;
00152 class CurrencySymbols;
00153 class GeneratorHelpers;
00154 class DecNum;
00155 class NumberRangeFormatterImpl;
00156 struct RangeMacroProps;
00157 struct UFormattedNumberImpl;
00158 class MutablePatternModifier;
00159 class ImmutablePatternModifier;
00160
00167 void touchRangeLocales(impl::RangeMacroProps& macros);
00168
00169 }
00170
00176 typedef Notation CompactNotation;
00177
00183 typedef Notation SimpleNotation;
00184
00190 class U_I18N_API Notation : public UMemory {
00191 public:
00216 static ScientificNotation scientific();
00217
00240 static ScientificNotation engineering();
00241
00283 static CompactNotation compactShort();
00284
00307 static CompactNotation compactLong();
00308
00333 static SimpleNotation simple();
00334
00335 private:
00336 enum NotationType {
00337 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
00338 } fType;
00339
00340 union NotationUnion {
00341
00343 struct ScientificSettings {
00345 int8_t fEngineeringInterval;
00347 bool fRequireMinInt;
00349 impl::digits_t fMinExponentDigits;
00351 UNumberSignDisplay fExponentSignDisplay;
00352 } scientific;
00353
00354
00355 UNumberCompactStyle compactStyle;
00356
00357
00358 UErrorCode errorCode;
00359 } fUnion;
00360
00361 typedef NotationUnion::ScientificSettings ScientificSettings;
00362
00363 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
00364
00365 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
00366 fUnion.errorCode = errorCode;
00367 }
00368
00369 Notation() : fType(NTN_SIMPLE), fUnion() {}
00370
00371 UBool copyErrorTo(UErrorCode &status) const {
00372 if (fType == NTN_ERROR) {
00373 status = fUnion.errorCode;
00374 return TRUE;
00375 }
00376 return FALSE;
00377 }
00378
00379
00380 friend struct impl::MacroProps;
00381 friend class ScientificNotation;
00382
00383
00384 friend class impl::NumberFormatterImpl;
00385 friend class impl::ScientificModifier;
00386 friend class impl::ScientificHandler;
00387
00388
00389 friend class impl::GeneratorHelpers;
00390 };
00391
00400 class U_I18N_API ScientificNotation : public Notation {
00401 public:
00415 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
00416
00430 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
00431
00432 private:
00433
00434 using Notation::Notation;
00435
00436
00437 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
00438 UNumberSignDisplay fExponentSignDisplay);
00439
00440 friend class Notation;
00441
00442
00443 friend class impl::NumberPropertyMapper;
00444 };
00445
00451 typedef Precision SignificantDigitsPrecision;
00452
00461 class U_I18N_API Precision : public UMemory {
00462
00463 public:
00481 static Precision unlimited();
00482
00489 static FractionPrecision integer();
00490
00518 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
00519
00533 static FractionPrecision minFraction(int32_t minFractionPlaces);
00534
00545 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
00546
00560 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
00561
00575 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
00576
00589 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
00590
00599 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
00600
00612 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
00613 int32_t maxSignificantDigits);
00614
00634 static IncrementPrecision increment(double roundingIncrement);
00635
00653 static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
00654
00655 private:
00656 enum PrecisionType {
00657 RND_BOGUS,
00658 RND_NONE,
00659 RND_FRACTION,
00660 RND_SIGNIFICANT,
00661 RND_FRACTION_SIGNIFICANT,
00662
00663
00664 RND_INCREMENT,
00665
00666
00667
00668
00669 RND_INCREMENT_ONE,
00670
00671
00672 RND_INCREMENT_FIVE,
00673
00674 RND_CURRENCY,
00675 RND_ERROR
00676 } fType;
00677
00678 union PrecisionUnion {
00680 struct FractionSignificantSettings {
00681
00683 impl::digits_t fMinFrac;
00685 impl::digits_t fMaxFrac;
00687 impl::digits_t fMinSig;
00689 impl::digits_t fMaxSig;
00690 } fracSig;
00692 struct IncrementSettings {
00693
00695 double fIncrement;
00697 impl::digits_t fMinFrac;
00699 impl::digits_t fMaxFrac;
00700 } increment;
00701 UCurrencyUsage currencyUsage;
00702 UErrorCode errorCode;
00703 } fUnion;
00704
00705 typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
00706 typedef PrecisionUnion::IncrementSettings IncrementSettings;
00707
00709 UNumberFormatRoundingMode fRoundingMode;
00710
00711 Precision(const PrecisionType& type, const PrecisionUnion& union_,
00712 UNumberFormatRoundingMode roundingMode)
00713 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
00714
00715 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
00716 fUnion.errorCode = errorCode;
00717 }
00718
00719 Precision() : fType(RND_BOGUS) {}
00720
00721 bool isBogus() const {
00722 return fType == RND_BOGUS;
00723 }
00724
00725 UBool copyErrorTo(UErrorCode &status) const {
00726 if (fType == RND_ERROR) {
00727 status = fUnion.errorCode;
00728 return TRUE;
00729 }
00730 return FALSE;
00731 }
00732
00733
00734 Precision withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const;
00735
00736 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
00737
00738 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
00739
00740 static Precision
00741 constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig);
00742
00743 static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
00744
00745 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
00746
00747 static Precision constructPassThrough();
00748
00749
00750 friend struct impl::MacroProps;
00751 friend struct impl::MicroProps;
00752
00753
00754 friend class impl::NumberFormatterImpl;
00755
00756
00757 friend class impl::NumberPropertyMapper;
00758
00759
00760 friend class impl::RoundingImpl;
00761
00762
00763 friend class FractionPrecision;
00764 friend class CurrencyPrecision;
00765 friend class IncrementPrecision;
00766
00767
00768 friend class impl::GeneratorHelpers;
00769 };
00770
00780 class U_I18N_API FractionPrecision : public Precision {
00781 public:
00798 Precision withMinDigits(int32_t minSignificantDigits) const;
00799
00817 Precision withMaxDigits(int32_t maxSignificantDigits) const;
00818
00819 private:
00820
00821 using Precision::Precision;
00822
00823
00824 friend class Precision;
00825 };
00826
00836 class U_I18N_API CurrencyPrecision : public Precision {
00837 public:
00855 Precision withCurrency(const CurrencyUnit ¤cy) const;
00856
00857 private:
00858
00859 using Precision::Precision;
00860
00861
00862 friend class Precision;
00863 };
00864
00874 class U_I18N_API IncrementPrecision : public Precision {
00875 public:
00891 Precision withMinFraction(int32_t minFrac) const;
00892
00893 private:
00894
00895 using Precision::Precision;
00896
00897
00898 friend class Precision;
00899 };
00900
00910 class U_I18N_API IntegerWidth : public UMemory {
00911 public:
00923 static IntegerWidth zeroFillTo(int32_t minInt);
00924
00936 IntegerWidth truncateAt(int32_t maxInt);
00937
00938 private:
00939 union {
00940 struct {
00941 impl::digits_t fMinInt;
00942 impl::digits_t fMaxInt;
00943 bool fFormatFailIfMoreThanMaxDigits;
00944 } minMaxInt;
00945 UErrorCode errorCode;
00946 } fUnion;
00947 bool fHasError = false;
00948
00949 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
00950
00951 IntegerWidth(UErrorCode errorCode) {
00952 fUnion.errorCode = errorCode;
00953 fHasError = true;
00954 }
00955
00956 IntegerWidth() {
00957 fUnion.minMaxInt.fMinInt = -1;
00958 }
00959
00961 static IntegerWidth standard() {
00962 return IntegerWidth::zeroFillTo(1);
00963 }
00964
00965 bool isBogus() const {
00966 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
00967 }
00968
00969 UBool copyErrorTo(UErrorCode &status) const {
00970 if (fHasError) {
00971 status = fUnion.errorCode;
00972 return TRUE;
00973 }
00974 return FALSE;
00975 }
00976
00977 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
00978
00979 bool operator==(const IntegerWidth& other) const;
00980
00981
00982 friend struct impl::MacroProps;
00983 friend struct impl::MicroProps;
00984
00985
00986 friend class impl::NumberFormatterImpl;
00987
00988
00989 friend class impl::MutablePatternModifier;
00990 friend class impl::ImmutablePatternModifier;
00991
00992
00993 friend class impl::NumberPropertyMapper;
00994
00995
00996 friend class impl::GeneratorHelpers;
00997 };
00998
01007 class U_I18N_API Scale : public UMemory {
01008 public:
01015 static Scale none();
01016
01027 static Scale powerOfTen(int32_t power);
01028
01041 static Scale byDecimal(StringPiece multiplicand);
01042
01051 static Scale byDouble(double multiplicand);
01052
01059 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
01060
01061
01062
01063
01065 Scale(const Scale& other);
01066
01068 Scale& operator=(const Scale& other);
01069
01071 Scale(Scale&& src) U_NOEXCEPT;
01072
01074 Scale& operator=(Scale&& src) U_NOEXCEPT;
01075
01077 ~Scale();
01078
01079 #ifndef U_HIDE_INTERNAL_API
01080
01081 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
01082 #endif
01083
01084 private:
01085 int32_t fMagnitude;
01086 impl::DecNum* fArbitrary;
01087 UErrorCode fError;
01088
01089 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
01090
01091 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
01092
01093 bool isValid() const {
01094 return fMagnitude != 0 || fArbitrary != nullptr;
01095 }
01096
01097 UBool copyErrorTo(UErrorCode &status) const {
01098 if (fError != U_ZERO_ERROR) {
01099 status = fError;
01100 return TRUE;
01101 }
01102 return FALSE;
01103 }
01104
01105 void applyTo(impl::DecimalQuantity& quantity) const;
01106
01107 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
01108
01109
01110 friend struct impl::MacroProps;
01111 friend struct impl::MicroProps;
01112
01113
01114 friend class impl::NumberFormatterImpl;
01115
01116
01117 friend class impl::MultiplierFormatHandler;
01118
01119
01120 friend class impl::GeneratorHelpers;
01121
01122
01123 friend class ::icu::numparse::impl::NumberParserImpl;
01124 friend class ::icu::numparse::impl::MultiplierParseHandler;
01125 };
01126
01127 namespace impl {
01128
01129
01131 class U_I18N_API SymbolsWrapper : public UMemory {
01132 public:
01134 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
01135
01137 SymbolsWrapper(const SymbolsWrapper &other);
01138
01140 SymbolsWrapper &operator=(const SymbolsWrapper &other);
01141
01143 SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
01144
01146 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
01147
01149 ~SymbolsWrapper();
01150
01151 #ifndef U_HIDE_INTERNAL_API
01152
01157 void setTo(const DecimalFormatSymbols &dfs);
01158
01163 void setTo(const NumberingSystem *ns);
01164
01169 bool isDecimalFormatSymbols() const;
01170
01175 bool isNumberingSystem() const;
01176
01181 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
01182
01187 const NumberingSystem *getNumberingSystem() const;
01188
01189 #endif // U_HIDE_INTERNAL_API
01190
01192 UBool copyErrorTo(UErrorCode &status) const {
01193 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
01194 status = U_MEMORY_ALLOCATION_ERROR;
01195 return TRUE;
01196 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
01197 status = U_MEMORY_ALLOCATION_ERROR;
01198 return TRUE;
01199 }
01200 return FALSE;
01201 }
01202
01203 private:
01204 enum SymbolsPointerType {
01205 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
01206 } fType;
01207
01208 union {
01209 const DecimalFormatSymbols *dfs;
01210 const NumberingSystem *ns;
01211 } fPtr;
01212
01213 void doCopyFrom(const SymbolsWrapper &other);
01214
01215 void doMoveFrom(SymbolsWrapper&& src);
01216
01217 void doCleanup();
01218 };
01219
01220
01222 class U_I18N_API Grouper : public UMemory {
01223 public:
01224 #ifndef U_HIDE_INTERNAL_API
01225
01226 static Grouper forStrategy(UNumberGroupingStrategy grouping);
01227
01232 static Grouper forProperties(const DecimalFormatProperties& properties);
01233
01234
01235
01237 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
01238 : fGrouping1(grouping1),
01239 fGrouping2(grouping2),
01240 fMinGrouping(minGrouping),
01241 fStrategy(strategy) {}
01242 #endif // U_HIDE_INTERNAL_API
01243
01245 int16_t getPrimary() const;
01246
01248 int16_t getSecondary() const;
01249
01250 private:
01259 int16_t fGrouping1;
01260 int16_t fGrouping2;
01261
01269 int16_t fMinGrouping;
01270
01275 UNumberGroupingStrategy fStrategy;
01276
01277 Grouper() : fGrouping1(-3) {}
01278
01279 bool isBogus() const {
01280 return fGrouping1 == -3;
01281 }
01282
01284 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
01285
01286 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
01287
01288
01289 friend struct MacroProps;
01290 friend struct MicroProps;
01291
01292
01293 friend class NumberFormatterImpl;
01294
01295
01296 friend class ::icu::numparse::impl::NumberParserImpl;
01297
01298
01299 friend class impl::GeneratorHelpers;
01300 };
01301
01302
01304 class U_I18N_API Padder : public UMemory {
01305 public:
01306 #ifndef U_HIDE_INTERNAL_API
01307
01308 static Padder none();
01309
01311 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
01312 #endif // U_HIDE_INTERNAL_API
01313
01315 static Padder forProperties(const DecimalFormatProperties& properties);
01316
01317 private:
01318 UChar32 fWidth;
01319 union {
01320 struct {
01321 int32_t fCp;
01322 UNumberFormatPadPosition fPosition;
01323 } padding;
01324 UErrorCode errorCode;
01325 } fUnion;
01326
01327 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
01328
01329 Padder(int32_t width);
01330
01331 Padder(UErrorCode errorCode) : fWidth(-3) {
01332 fUnion.errorCode = errorCode;
01333 }
01334
01335 Padder() : fWidth(-2) {}
01336
01337 bool isBogus() const {
01338 return fWidth == -2;
01339 }
01340
01341 UBool copyErrorTo(UErrorCode &status) const {
01342 if (fWidth == -3) {
01343 status = fUnion.errorCode;
01344 return TRUE;
01345 }
01346 return FALSE;
01347 }
01348
01349 bool isValid() const {
01350 return fWidth > 0;
01351 }
01352
01353 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
01354 FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
01355 UErrorCode &status) const;
01356
01357
01358 friend struct MacroProps;
01359 friend struct MicroProps;
01360
01361
01362 friend class impl::NumberFormatterImpl;
01363
01364
01365 friend class impl::GeneratorHelpers;
01366 };
01367
01368
01370 struct U_I18N_API MacroProps : public UMemory {
01372 Notation notation;
01373
01375 MeasureUnit unit;
01376
01378 MeasureUnit perUnit;
01379
01381 Precision precision;
01382
01384 UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
01385
01387 Grouper grouper;
01388
01390 Padder padder;
01391
01393 IntegerWidth integerWidth;
01394
01396 SymbolsWrapper symbols;
01397
01398
01399
01401 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
01402
01404 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
01405
01407 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
01408
01410 Scale scale;
01411
01413 const AffixPatternProvider* affixProvider = nullptr;
01414
01416 const PluralRules* rules = nullptr;
01417
01419 int32_t threshold = kInternalDefaultThreshold;
01420
01422 Locale locale;
01423
01424
01425
01430 bool copyErrorTo(UErrorCode &status) const {
01431 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
01432 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
01433 symbols.copyErrorTo(status) || scale.copyErrorTo(status);
01434 }
01435 };
01436
01437 }
01438
01439 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
01440
01441
01442
01443
01444
01445 #pragma warning(push)
01446 #pragma warning(disable: 4661)
01447 #endif
01448
01454 template<typename Derived>
01455 class U_I18N_API NumberFormatterSettings {
01456 public:
01485 Derived notation(const Notation ¬ation) const &;
01486
01496 Derived notation(const Notation ¬ation) &&;
01497
01541 Derived unit(const icu::MeasureUnit &unit) const &;
01542
01552 Derived unit(const icu::MeasureUnit &unit) &&;
01553
01567 Derived adoptUnit(icu::MeasureUnit *unit) const &;
01568
01578 Derived adoptUnit(icu::MeasureUnit *unit) &&;
01579
01602 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
01603
01613 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
01614
01628 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
01629
01639 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
01640
01671 Derived precision(const Precision& precision) const &;
01672
01682 Derived precision(const Precision& precision) &&;
01683
01702 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
01703
01712 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
01713
01741 Derived grouping(UNumberGroupingStrategy strategy) const &;
01742
01752 Derived grouping(UNumberGroupingStrategy strategy) &&;
01753
01778 Derived integerWidth(const IntegerWidth &style) const &;
01779
01789 Derived integerWidth(const IntegerWidth &style) &&;
01790
01831 Derived symbols(const DecimalFormatSymbols &symbols) const &;
01832
01842 Derived symbols(const DecimalFormatSymbols &symbols) &&;
01843
01877 Derived adoptSymbols(NumberingSystem *symbols) const &;
01878
01888 Derived adoptSymbols(NumberingSystem *symbols) &&;
01889
01915 Derived unitWidth(UNumberUnitWidth width) const &;
01916
01926 Derived unitWidth(UNumberUnitWidth width) &&;
01927
01953 Derived sign(UNumberSignDisplay style) const &;
01954
01964 Derived sign(UNumberSignDisplay style) &&;
01965
01991 Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
01992
02002 Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
02003
02028 Derived scale(const Scale &scale) const &;
02029
02039 Derived scale(const Scale &scale) &&;
02040
02041 #ifndef U_HIDE_INTERNAL_API
02042
02048 Derived padding(const impl::Padder &padder) const &;
02049
02051 Derived padding(const impl::Padder &padder) &&;
02052
02059 Derived threshold(int32_t threshold) const &;
02060
02062 Derived threshold(int32_t threshold) &&;
02063
02069 Derived macros(const impl::MacroProps& macros) const &;
02070
02072 Derived macros(const impl::MacroProps& macros) &&;
02073
02075 Derived macros(impl::MacroProps&& macros) const &;
02076
02078 Derived macros(impl::MacroProps&& macros) &&;
02079
02080 #endif
02081
02096 UnicodeString toSkeleton(UErrorCode& status) const;
02097
02109 LocalPointer<Derived> clone() const &;
02110
02118 LocalPointer<Derived> clone() &&;
02119
02126 UBool copyErrorTo(UErrorCode &outErrorCode) const {
02127 if (U_FAILURE(outErrorCode)) {
02128
02129 return TRUE;
02130 }
02131 fMacros.copyErrorTo(outErrorCode);
02132 return U_FAILURE(outErrorCode);
02133 }
02134
02135
02136
02137 private:
02138 impl::MacroProps fMacros;
02139
02140
02141 NumberFormatterSettings() = default;
02142
02143 friend class LocalizedNumberFormatter;
02144 friend class UnlocalizedNumberFormatter;
02145
02146
02147 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
02148 friend class impl::NumberRangeFormatterImpl;
02149 };
02150
02159 class U_I18N_API UnlocalizedNumberFormatter
02160 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
02161
02162 public:
02172 LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
02173
02183 LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
02184
02190 UnlocalizedNumberFormatter() = default;
02191
02196 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
02197
02203 UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02204
02209 UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
02210
02216 UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02217
02218 private:
02219 explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
02220
02221 explicit UnlocalizedNumberFormatter(
02222 NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) U_NOEXCEPT;
02223
02224
02225 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02226
02227
02228 friend class NumberFormatter;
02229 };
02230
02239 class U_I18N_API LocalizedNumberFormatter
02240 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
02241 public:
02253 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
02254
02266 FormattedNumber formatDouble(double value, UErrorCode &status) const;
02267
02282 FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
02283
02284 #ifndef U_HIDE_INTERNAL_API
02285
02289 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
02290
02294 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
02295
02300 const impl::NumberFormatterImpl* getCompiled() const;
02301
02306 int32_t getCallCount() const;
02307
02308 #endif
02309
02323 Format* toFormat(UErrorCode& status) const;
02324
02330 LocalizedNumberFormatter() = default;
02331
02336 LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
02337
02343 LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02344
02349 LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
02350
02356 LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02357
02358 #ifndef U_HIDE_INTERNAL_API
02359
02372 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
02373
02374 #endif
02375
02380 ~LocalizedNumberFormatter();
02381
02382 private:
02383
02384
02385 const impl::NumberFormatterImpl* fCompiled {nullptr};
02386 char fUnsafeCallCount[8] {};
02387
02388 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
02389
02390 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
02391
02392 LocalizedNumberFormatter(const impl::MacroProps ¯os, const Locale &locale);
02393
02394 LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale);
02395
02396 void clear();
02397
02398 void lnfMoveHelper(LocalizedNumberFormatter&& src);
02399
02403 bool computeCompiled(UErrorCode& status) const;
02404
02405
02406 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02407 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
02408
02409
02410 friend class UnlocalizedNumberFormatter;
02411 };
02412
02413 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
02414
02415 #pragma warning(pop)
02416 #endif
02417
02426 class U_I18N_API FormattedNumber : public UMemory, public FormattedValue {
02427 public:
02428
02433 FormattedNumber()
02434 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
02435
02440 FormattedNumber(FormattedNumber&& src) U_NOEXCEPT;
02441
02446 virtual ~FormattedNumber() U_OVERRIDE;
02447
02449 FormattedNumber(const FormattedNumber&) = delete;
02450
02452 FormattedNumber& operator=(const FormattedNumber&) = delete;
02453
02458 FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT;
02459
02460
02468 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
02469
02470
02472 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
02473
02474
02482 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
02483
02484
02486 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
02487
02488 #ifndef U_HIDE_DRAFT_API
02489
02507 template<typename StringClass>
02508 inline StringClass toDecimalNumber(UErrorCode& status) const;
02509 #endif // U_HIDE_DRAFT_API
02510
02511 #ifndef U_HIDE_INTERNAL_API
02512
02517 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
02518
02523 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
02524
02525 #endif
02526
02527 private:
02528
02529 const impl::UFormattedNumberData *fData;
02530
02531
02532 UErrorCode fErrorCode;
02533
02538 explicit FormattedNumber(impl::UFormattedNumberData *results)
02539 : fData(results), fErrorCode(U_ZERO_ERROR) {}
02540
02541 explicit FormattedNumber(UErrorCode errorCode)
02542 : fData(nullptr), fErrorCode(errorCode) {}
02543
02544
02545 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
02546
02547
02548 friend class LocalizedNumberFormatter;
02549
02550
02551 friend struct impl::UFormattedNumberImpl;
02552 };
02553
02554 #ifndef U_HIDE_DRAFT_API
02555
02556 template<typename StringClass>
02557 StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
02558 StringClass result;
02559 StringByteSink<StringClass> sink(&result);
02560 toDecimalNumber(sink, status);
02561 return result;
02562 }
02563 #endif // U_HIDE_DRAFT_API
02564
02570 class U_I18N_API NumberFormatter final {
02571 public:
02579 static UnlocalizedNumberFormatter with();
02580
02590 static LocalizedNumberFormatter withLocale(const Locale &locale);
02591
02606 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
02607
02625 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton,
02626 UParseError& perror, UErrorCode& status);
02627
02631 NumberFormatter() = delete;
02632 };
02633
02634 }
02635 U_NAMESPACE_END
02636
02637 #endif
02638
02639 #endif
02640
02641 #endif // __NUMBERFORMATTER_H__
02642