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/formattedvalue.h"
00015 #include "unicode/fpositer.h"
00016 #include "unicode/measunit.h"
00017 #include "unicode/nounit.h"
00018 #include "unicode/parseerr.h"
00019 #include "unicode/plurrule.h"
00020 #include "unicode/ucurr.h"
00021 #include "unicode/unum.h"
00022 #include "unicode/unumberformatter.h"
00023 #include "unicode/uobject.h"
00024
00025 #ifndef U_HIDE_DRAFT_API
00026
00083 U_NAMESPACE_BEGIN
00084
00085
00086 class IFixedDecimal;
00087 class FieldPositionIteratorHandler;
00088
00089 namespace numparse {
00090 namespace impl {
00091
00092
00093 class NumberParserImpl;
00094 class MultiplierParseHandler;
00095
00096 }
00097 }
00098
00099 namespace number {
00100
00101
00102 class UnlocalizedNumberFormatter;
00103 class LocalizedNumberFormatter;
00104 class FormattedNumber;
00105 class Notation;
00106 class ScientificNotation;
00107 class Precision;
00108 class FractionPrecision;
00109 class CurrencyPrecision;
00110 class IncrementPrecision;
00111 class IntegerWidth;
00112
00113 namespace impl {
00114
00115
00121 typedef int16_t digits_t;
00122
00123
00130 static constexpr int32_t kInternalDefaultThreshold = 3;
00131
00132
00133 class Padder;
00134 struct MacroProps;
00135 struct MicroProps;
00136 class DecimalQuantity;
00137 class UFormattedNumberData;
00138 class NumberFormatterImpl;
00139 struct ParsedPatternInfo;
00140 class ScientificModifier;
00141 class MultiplierProducer;
00142 class RoundingImpl;
00143 class ScientificHandler;
00144 class Modifier;
00145 class NumberStringBuilder;
00146 class AffixPatternProvider;
00147 class NumberPropertyMapper;
00148 struct DecimalFormatProperties;
00149 class MultiplierFormatHandler;
00150 class CurrencySymbols;
00151 class GeneratorHelpers;
00152 class DecNum;
00153 class NumberRangeFormatterImpl;
00154 struct RangeMacroProps;
00155 struct UFormattedNumberImpl;
00156
00163 void touchRangeLocales(impl::RangeMacroProps& macros);
00164
00165 }
00166
00172 typedef Notation CompactNotation;
00173
00179 typedef Notation SimpleNotation;
00180
00186 class U_I18N_API Notation : public UMemory {
00187 public:
00212 static ScientificNotation scientific();
00213
00236 static ScientificNotation engineering();
00237
00279 static CompactNotation compactShort();
00280
00303 static CompactNotation compactLong();
00304
00329 static SimpleNotation simple();
00330
00331 private:
00332 enum NotationType {
00333 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
00334 } fType;
00335
00336 union NotationUnion {
00337
00339 struct ScientificSettings {
00341 int8_t fEngineeringInterval;
00343 bool fRequireMinInt;
00345 impl::digits_t fMinExponentDigits;
00347 UNumberSignDisplay fExponentSignDisplay;
00348 } scientific;
00349
00350
00351 UNumberCompactStyle compactStyle;
00352
00353
00354 UErrorCode errorCode;
00355 } fUnion;
00356
00357 typedef NotationUnion::ScientificSettings ScientificSettings;
00358
00359 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
00360
00361 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
00362 fUnion.errorCode = errorCode;
00363 }
00364
00365 Notation() : fType(NTN_SIMPLE), fUnion() {}
00366
00367 UBool copyErrorTo(UErrorCode &status) const {
00368 if (fType == NTN_ERROR) {
00369 status = fUnion.errorCode;
00370 return TRUE;
00371 }
00372 return FALSE;
00373 }
00374
00375
00376 friend struct impl::MacroProps;
00377 friend class ScientificNotation;
00378
00379
00380 friend class impl::NumberFormatterImpl;
00381 friend class impl::ScientificModifier;
00382 friend class impl::ScientificHandler;
00383
00384
00385 friend class impl::GeneratorHelpers;
00386 };
00387
00396 class U_I18N_API ScientificNotation : public Notation {
00397 public:
00411 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
00412
00426 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
00427
00428 private:
00429
00430 using Notation::Notation;
00431
00432
00433 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
00434 UNumberSignDisplay fExponentSignDisplay);
00435
00436 friend class Notation;
00437
00438
00439 friend class impl::NumberPropertyMapper;
00440 };
00441
00447 typedef Precision SignificantDigitsPrecision;
00448
00457 class U_I18N_API Precision : public UMemory {
00458
00459 public:
00477 static Precision unlimited();
00478
00485 static FractionPrecision integer();
00486
00514 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
00515
00529 static FractionPrecision minFraction(int32_t minFractionPlaces);
00530
00541 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
00542
00556 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
00557
00571 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
00572
00585 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
00586
00595 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
00596
00608 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
00609 int32_t maxSignificantDigits);
00610
00630 static IncrementPrecision increment(double roundingIncrement);
00631
00649 static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
00650
00651 private:
00652 enum PrecisionType {
00653 RND_BOGUS,
00654 RND_NONE,
00655 RND_FRACTION,
00656 RND_SIGNIFICANT,
00657 RND_FRACTION_SIGNIFICANT,
00658
00659
00660 RND_INCREMENT,
00661
00662
00663
00664
00665 RND_INCREMENT_ONE,
00666
00667
00668 RND_INCREMENT_FIVE,
00669
00670 RND_CURRENCY,
00671 RND_ERROR
00672 } fType;
00673
00674 union PrecisionUnion {
00676 struct FractionSignificantSettings {
00677
00679 impl::digits_t fMinFrac;
00681 impl::digits_t fMaxFrac;
00683 impl::digits_t fMinSig;
00685 impl::digits_t fMaxSig;
00686 } fracSig;
00688 struct IncrementSettings {
00689
00691 double fIncrement;
00693 impl::digits_t fMinFrac;
00695 impl::digits_t fMaxFrac;
00696 } increment;
00697 UCurrencyUsage currencyUsage;
00698 UErrorCode errorCode;
00699 } fUnion;
00700
00701 typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
00702 typedef PrecisionUnion::IncrementSettings IncrementSettings;
00703
00705 UNumberFormatRoundingMode fRoundingMode;
00706
00707 Precision(const PrecisionType& type, const PrecisionUnion& union_,
00708 UNumberFormatRoundingMode roundingMode)
00709 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
00710
00711 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
00712 fUnion.errorCode = errorCode;
00713 }
00714
00715 Precision() : fType(RND_BOGUS) {}
00716
00717 bool isBogus() const {
00718 return fType == RND_BOGUS;
00719 }
00720
00721 UBool copyErrorTo(UErrorCode &status) const {
00722 if (fType == RND_ERROR) {
00723 status = fUnion.errorCode;
00724 return TRUE;
00725 }
00726 return FALSE;
00727 }
00728
00729
00730 Precision withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const;
00731
00732 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
00733
00734 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
00735
00736 static Precision
00737 constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig);
00738
00739 static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
00740
00741 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
00742
00743 static Precision constructPassThrough();
00744
00745
00746 friend struct impl::MacroProps;
00747 friend struct impl::MicroProps;
00748
00749
00750 friend class impl::NumberFormatterImpl;
00751
00752
00753 friend class impl::NumberPropertyMapper;
00754
00755
00756 friend class impl::RoundingImpl;
00757
00758
00759 friend class FractionPrecision;
00760 friend class CurrencyPrecision;
00761 friend class IncrementPrecision;
00762
00763
00764 friend class impl::GeneratorHelpers;
00765 };
00766
00776 class U_I18N_API FractionPrecision : public Precision {
00777 public:
00794 Precision withMinDigits(int32_t minSignificantDigits) const;
00795
00813 Precision withMaxDigits(int32_t maxSignificantDigits) const;
00814
00815 private:
00816
00817 using Precision::Precision;
00818
00819
00820 friend class Precision;
00821 };
00822
00832 class U_I18N_API CurrencyPrecision : public Precision {
00833 public:
00851 Precision withCurrency(const CurrencyUnit ¤cy) const;
00852
00853 private:
00854
00855 using Precision::Precision;
00856
00857
00858 friend class Precision;
00859 };
00860
00870 class U_I18N_API IncrementPrecision : public Precision {
00871 public:
00887 Precision withMinFraction(int32_t minFrac) const;
00888
00889 private:
00890
00891 using Precision::Precision;
00892
00893
00894 friend class Precision;
00895 };
00896
00906 class U_I18N_API IntegerWidth : public UMemory {
00907 public:
00919 static IntegerWidth zeroFillTo(int32_t minInt);
00920
00932 IntegerWidth truncateAt(int32_t maxInt);
00933
00934 private:
00935 union {
00936 struct {
00937 impl::digits_t fMinInt;
00938 impl::digits_t fMaxInt;
00939 bool fFormatFailIfMoreThanMaxDigits;
00940 } minMaxInt;
00941 UErrorCode errorCode;
00942 } fUnion;
00943 bool fHasError = false;
00944
00945 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
00946
00947 IntegerWidth(UErrorCode errorCode) {
00948 fUnion.errorCode = errorCode;
00949 fHasError = true;
00950 }
00951
00952 IntegerWidth() {
00953 fUnion.minMaxInt.fMinInt = -1;
00954 }
00955
00957 static IntegerWidth standard() {
00958 return IntegerWidth::zeroFillTo(1);
00959 }
00960
00961 bool isBogus() const {
00962 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
00963 }
00964
00965 UBool copyErrorTo(UErrorCode &status) const {
00966 if (fHasError) {
00967 status = fUnion.errorCode;
00968 return TRUE;
00969 }
00970 return FALSE;
00971 }
00972
00973 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
00974
00975 bool operator==(const IntegerWidth& other) const;
00976
00977
00978 friend struct impl::MacroProps;
00979 friend struct impl::MicroProps;
00980
00981
00982 friend class impl::NumberFormatterImpl;
00983
00984
00985 friend class impl::NumberPropertyMapper;
00986
00987
00988 friend class impl::GeneratorHelpers;
00989 };
00990
00999 class U_I18N_API Scale : public UMemory {
01000 public:
01007 static Scale none();
01008
01019 static Scale powerOfTen(int32_t power);
01020
01033 static Scale byDecimal(StringPiece multiplicand);
01034
01043 static Scale byDouble(double multiplicand);
01044
01051 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
01052
01053
01054
01055
01057 Scale(const Scale& other);
01058
01060 Scale& operator=(const Scale& other);
01061
01063 Scale(Scale&& src) U_NOEXCEPT;
01064
01066 Scale& operator=(Scale&& src) U_NOEXCEPT;
01067
01069 ~Scale();
01070
01071 #ifndef U_HIDE_INTERNAL_API
01072
01073 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
01074 #endif
01075
01076 private:
01077 int32_t fMagnitude;
01078 impl::DecNum* fArbitrary;
01079 UErrorCode fError;
01080
01081 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
01082
01083 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
01084
01085 bool isValid() const {
01086 return fMagnitude != 0 || fArbitrary != nullptr;
01087 }
01088
01089 UBool copyErrorTo(UErrorCode &status) const {
01090 if (fError != U_ZERO_ERROR) {
01091 status = fError;
01092 return TRUE;
01093 }
01094 return FALSE;
01095 }
01096
01097 void applyTo(impl::DecimalQuantity& quantity) const;
01098
01099 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
01100
01101
01102 friend struct impl::MacroProps;
01103 friend struct impl::MicroProps;
01104
01105
01106 friend class impl::NumberFormatterImpl;
01107
01108
01109 friend class impl::MultiplierFormatHandler;
01110
01111
01112 friend class impl::GeneratorHelpers;
01113
01114
01115 friend class ::icu::numparse::impl::NumberParserImpl;
01116 friend class ::icu::numparse::impl::MultiplierParseHandler;
01117 };
01118
01119 namespace impl {
01120
01121
01123 class U_I18N_API SymbolsWrapper : public UMemory {
01124 public:
01126 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
01127
01129 SymbolsWrapper(const SymbolsWrapper &other);
01130
01132 SymbolsWrapper &operator=(const SymbolsWrapper &other);
01133
01135 SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
01136
01138 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
01139
01141 ~SymbolsWrapper();
01142
01143 #ifndef U_HIDE_INTERNAL_API
01144
01149 void setTo(const DecimalFormatSymbols &dfs);
01150
01155 void setTo(const NumberingSystem *ns);
01156
01161 bool isDecimalFormatSymbols() const;
01162
01167 bool isNumberingSystem() const;
01168
01173 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
01174
01179 const NumberingSystem *getNumberingSystem() const;
01180
01181 #endif // U_HIDE_INTERNAL_API
01182
01184 UBool copyErrorTo(UErrorCode &status) const {
01185 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
01186 status = U_MEMORY_ALLOCATION_ERROR;
01187 return TRUE;
01188 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
01189 status = U_MEMORY_ALLOCATION_ERROR;
01190 return TRUE;
01191 }
01192 return FALSE;
01193 }
01194
01195 private:
01196 enum SymbolsPointerType {
01197 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
01198 } fType;
01199
01200 union {
01201 const DecimalFormatSymbols *dfs;
01202 const NumberingSystem *ns;
01203 } fPtr;
01204
01205 void doCopyFrom(const SymbolsWrapper &other);
01206
01207 void doMoveFrom(SymbolsWrapper&& src);
01208
01209 void doCleanup();
01210 };
01211
01212
01214 class U_I18N_API Grouper : public UMemory {
01215 public:
01216 #ifndef U_HIDE_INTERNAL_API
01217
01218 static Grouper forStrategy(UNumberGroupingStrategy grouping);
01219
01224 static Grouper forProperties(const DecimalFormatProperties& properties);
01225
01226
01227
01229 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
01230 : fGrouping1(grouping1),
01231 fGrouping2(grouping2),
01232 fMinGrouping(minGrouping),
01233 fStrategy(strategy) {}
01234 #endif // U_HIDE_INTERNAL_API
01235
01237 int16_t getPrimary() const;
01238
01240 int16_t getSecondary() const;
01241
01242 private:
01251 int16_t fGrouping1;
01252 int16_t fGrouping2;
01253
01261 int16_t fMinGrouping;
01262
01267 UNumberGroupingStrategy fStrategy;
01268
01269 Grouper() : fGrouping1(-3) {}
01270
01271 bool isBogus() const {
01272 return fGrouping1 == -3;
01273 }
01274
01276 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
01277
01278 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
01279
01280
01281 friend struct MacroProps;
01282 friend struct MicroProps;
01283
01284
01285 friend class NumberFormatterImpl;
01286
01287
01288 friend class ::icu::numparse::impl::NumberParserImpl;
01289
01290
01291 friend class impl::GeneratorHelpers;
01292 };
01293
01294
01296 class U_I18N_API Padder : public UMemory {
01297 public:
01298 #ifndef U_HIDE_INTERNAL_API
01299
01300 static Padder none();
01301
01303 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
01304 #endif // U_HIDE_INTERNAL_API
01305
01307 static Padder forProperties(const DecimalFormatProperties& properties);
01308
01309 private:
01310 UChar32 fWidth;
01311 union {
01312 struct {
01313 int32_t fCp;
01314 UNumberFormatPadPosition fPosition;
01315 } padding;
01316 UErrorCode errorCode;
01317 } fUnion;
01318
01319 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
01320
01321 Padder(int32_t width);
01322
01323 Padder(UErrorCode errorCode) : fWidth(-3) {
01324 fUnion.errorCode = errorCode;
01325 }
01326
01327 Padder() : fWidth(-2) {}
01328
01329 bool isBogus() const {
01330 return fWidth == -2;
01331 }
01332
01333 UBool copyErrorTo(UErrorCode &status) const {
01334 if (fWidth == -3) {
01335 status = fUnion.errorCode;
01336 return TRUE;
01337 }
01338 return FALSE;
01339 }
01340
01341 bool isValid() const {
01342 return fWidth > 0;
01343 }
01344
01345 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
01346 impl::NumberStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
01347 UErrorCode &status) const;
01348
01349
01350 friend struct MacroProps;
01351 friend struct MicroProps;
01352
01353
01354 friend class impl::NumberFormatterImpl;
01355
01356
01357 friend class impl::GeneratorHelpers;
01358 };
01359
01360
01362 struct U_I18N_API MacroProps : public UMemory {
01364 Notation notation;
01365
01367 MeasureUnit unit;
01368
01370 MeasureUnit perUnit;
01371
01373 Precision precision;
01374
01376 UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
01377
01379 Grouper grouper;
01380
01382 Padder padder;
01383
01385 IntegerWidth integerWidth;
01386
01388 SymbolsWrapper symbols;
01389
01390
01391
01393 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
01394
01396 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
01397
01399 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
01400
01402 Scale scale;
01403
01405 const AffixPatternProvider* affixProvider = nullptr;
01406
01408 const PluralRules* rules = nullptr;
01409
01411 const CurrencySymbols* currencySymbols = nullptr;
01412
01414 int32_t threshold = kInternalDefaultThreshold;
01415
01417 Locale locale;
01418
01419
01420
01425 bool copyErrorTo(UErrorCode &status) const {
01426 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
01427 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
01428 symbols.copyErrorTo(status) || scale.copyErrorTo(status);
01429 }
01430 };
01431
01432 }
01433
01439 template<typename Derived>
01440 class U_I18N_API NumberFormatterSettings {
01441 public:
01470 Derived notation(const Notation ¬ation) const &;
01471
01481 Derived notation(const Notation ¬ation) &&;
01482
01526 Derived unit(const icu::MeasureUnit &unit) const &;
01527
01537 Derived unit(const icu::MeasureUnit &unit) &&;
01538
01552 Derived adoptUnit(icu::MeasureUnit *unit) const &;
01553
01563 Derived adoptUnit(icu::MeasureUnit *unit) &&;
01564
01587 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
01588
01598 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
01599
01613 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
01614
01624 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
01625
01656 Derived precision(const Precision& precision) const &;
01657
01667 Derived precision(const Precision& precision) &&;
01668
01687 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
01688
01697 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
01698
01726 Derived grouping(UNumberGroupingStrategy strategy) const &;
01727
01737 Derived grouping(UNumberGroupingStrategy strategy) &&;
01738
01763 Derived integerWidth(const IntegerWidth &style) const &;
01764
01774 Derived integerWidth(const IntegerWidth &style) &&;
01775
01816 Derived symbols(const DecimalFormatSymbols &symbols) const &;
01817
01827 Derived symbols(const DecimalFormatSymbols &symbols) &&;
01828
01862 Derived adoptSymbols(NumberingSystem *symbols) const &;
01863
01873 Derived adoptSymbols(NumberingSystem *symbols) &&;
01874
01900 Derived unitWidth(UNumberUnitWidth width) const &;
01901
01911 Derived unitWidth(UNumberUnitWidth width) &&;
01912
01938 Derived sign(UNumberSignDisplay style) const &;
01939
01949 Derived sign(UNumberSignDisplay style) &&;
01950
01976 Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
01977
01987 Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
01988
02013 Derived scale(const Scale &scale) const &;
02014
02024 Derived scale(const Scale &scale) &&;
02025
02026 #ifndef U_HIDE_INTERNAL_API
02027
02033 Derived padding(const impl::Padder &padder) const &;
02034
02036 Derived padding(const impl::Padder &padder) &&;
02037
02044 Derived threshold(int32_t threshold) const &;
02045
02047 Derived threshold(int32_t threshold) &&;
02048
02054 Derived macros(const impl::MacroProps& macros) const &;
02055
02057 Derived macros(const impl::MacroProps& macros) &&;
02058
02060 Derived macros(impl::MacroProps&& macros) const &;
02061
02063 Derived macros(impl::MacroProps&& macros) &&;
02064
02065 #endif
02066
02081 UnicodeString toSkeleton(UErrorCode& status) const;
02082
02094 LocalPointer<Derived> clone() const &;
02095
02103 LocalPointer<Derived> clone() &&;
02104
02111 UBool copyErrorTo(UErrorCode &outErrorCode) const {
02112 if (U_FAILURE(outErrorCode)) {
02113
02114 return TRUE;
02115 }
02116 fMacros.copyErrorTo(outErrorCode);
02117 return U_FAILURE(outErrorCode);
02118 }
02119
02120
02121
02122 private:
02123 impl::MacroProps fMacros;
02124
02125
02126 NumberFormatterSettings() = default;
02127
02128 friend class LocalizedNumberFormatter;
02129 friend class UnlocalizedNumberFormatter;
02130
02131
02132 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
02133 friend class impl::NumberRangeFormatterImpl;
02134 };
02135
02144 class U_I18N_API UnlocalizedNumberFormatter
02145 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
02146
02147 public:
02157 LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
02158
02168 LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
02169
02175 UnlocalizedNumberFormatter() = default;
02176
02181 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
02182
02188 UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02189
02194 UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
02195
02201 UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02202
02203 private:
02204 explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
02205
02206 explicit UnlocalizedNumberFormatter(
02207 NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) U_NOEXCEPT;
02208
02209
02210 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02211
02212
02213 friend class NumberFormatter;
02214 };
02215
02224 class U_I18N_API LocalizedNumberFormatter
02225 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
02226 public:
02238 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
02239
02251 FormattedNumber formatDouble(double value, UErrorCode &status) const;
02252
02267 FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
02268
02269 #ifndef U_HIDE_INTERNAL_API
02270
02274 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
02275
02279 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
02280
02285 const impl::NumberFormatterImpl* getCompiled() const;
02286
02291 int32_t getCallCount() const;
02292
02293 #endif
02294
02308 Format* toFormat(UErrorCode& status) const;
02309
02315 LocalizedNumberFormatter() = default;
02316
02321 LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
02322
02328 LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02329
02334 LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
02335
02341 LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02342
02343 #ifndef U_HIDE_INTERNAL_API
02344
02357 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
02358
02359 #endif
02360
02365 ~LocalizedNumberFormatter();
02366
02367 private:
02368
02369
02370 const impl::NumberFormatterImpl* fCompiled {nullptr};
02371 char fUnsafeCallCount[8] {};
02372
02373 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
02374
02375 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
02376
02377 LocalizedNumberFormatter(const impl::MacroProps ¯os, const Locale &locale);
02378
02379 LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale);
02380
02381 void clear();
02382
02383 void lnfMoveHelper(LocalizedNumberFormatter&& src);
02384
02388 bool computeCompiled(UErrorCode& status) const;
02389
02390
02391 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02392 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
02393
02394
02395 friend class UnlocalizedNumberFormatter;
02396 };
02397
02406 class U_I18N_API FormattedNumber : public UMemory, public FormattedValue {
02407 public:
02408
02413 FormattedNumber()
02414 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
02415
02420 FormattedNumber(FormattedNumber&& src) U_NOEXCEPT;
02421
02426 virtual ~FormattedNumber() U_OVERRIDE;
02427
02429 FormattedNumber(const FormattedNumber&) = delete;
02430
02432 FormattedNumber& operator=(const FormattedNumber&) = delete;
02433
02438 FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT;
02439
02440
02448 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
02449
02450
02452 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
02453
02454
02462 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
02463
02464
02466 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
02467
02501 UBool nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const;
02502
02518 void getAllFieldPositions(FieldPositionIterator &iterator, UErrorCode &status) const;
02519
02520 #ifndef U_HIDE_INTERNAL_API
02521
02526 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
02527
02532 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
02533
02534 #endif
02535
02536 private:
02537
02538 const impl::UFormattedNumberData *fData;
02539
02540
02541 UErrorCode fErrorCode;
02542
02547 explicit FormattedNumber(impl::UFormattedNumberData *results)
02548 : fData(results), fErrorCode(U_ZERO_ERROR) {}
02549
02550 explicit FormattedNumber(UErrorCode errorCode)
02551 : fData(nullptr), fErrorCode(errorCode) {}
02552
02553
02554 friend class LocalizedNumberFormatter;
02555
02556
02557 friend struct impl::UFormattedNumberImpl;
02558 };
02559
02565 class U_I18N_API NumberFormatter final {
02566 public:
02574 static UnlocalizedNumberFormatter with();
02575
02585 static LocalizedNumberFormatter withLocale(const Locale &locale);
02586
02601 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
02602
02620 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton,
02621 UParseError& perror, UErrorCode& status);
02622
02626 NumberFormatter() = delete;
02627 };
02628
02629 }
02630 U_NAMESPACE_END
02631
02632 #endif // U_HIDE_DRAFT_API
02633
02634 #endif // __NUMBERFORMATTER_H__
02635
02636 #endif