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/unounclass.h"
00026 #include "unicode/unum.h"
00027 #include "unicode/unumberformatter.h"
00028 #include "unicode/uobject.h"
00029
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 units {
00103
00104
00105 class UnitsRouter;
00106
00107 }
00108
00109 namespace number {
00110
00111
00112 class UnlocalizedNumberFormatter;
00113 class LocalizedNumberFormatter;
00114 class FormattedNumber;
00115 class Notation;
00116 class ScientificNotation;
00117 class Precision;
00118 class FractionPrecision;
00119 class CurrencyPrecision;
00120 class IncrementPrecision;
00121 class IntegerWidth;
00122
00123 namespace impl {
00124
00125
00131 typedef int16_t digits_t;
00132
00133
00140 static constexpr int32_t kInternalDefaultThreshold = 3;
00141
00142
00143 class Padder;
00144 struct MacroProps;
00145 struct MicroProps;
00146 class DecimalQuantity;
00147 class UFormattedNumberData;
00148 class NumberFormatterImpl;
00149 struct ParsedPatternInfo;
00150 class ScientificModifier;
00151 class MultiplierProducer;
00152 class RoundingImpl;
00153 class ScientificHandler;
00154 class Modifier;
00155 class AffixPatternProvider;
00156 class NumberPropertyMapper;
00157 struct DecimalFormatProperties;
00158 class MultiplierFormatHandler;
00159 class CurrencySymbols;
00160 class GeneratorHelpers;
00161 class DecNum;
00162 class NumberRangeFormatterImpl;
00163 struct RangeMacroProps;
00164 struct UFormattedNumberImpl;
00165 class MutablePatternModifier;
00166 class ImmutablePatternModifier;
00167 struct DecimalFormatWarehouse;
00168
00175 void touchRangeLocales(impl::RangeMacroProps& macros);
00176
00177 }
00178
00184 typedef Notation CompactNotation;
00185
00191 typedef Notation SimpleNotation;
00192
00198 class U_I18N_API Notation : public UMemory {
00199 public:
00224 static ScientificNotation scientific();
00225
00248 static ScientificNotation engineering();
00249
00291 static CompactNotation compactShort();
00292
00315 static CompactNotation compactLong();
00316
00341 static SimpleNotation simple();
00342
00343 private:
00344 enum NotationType {
00345 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
00346 } fType;
00347
00348 union NotationUnion {
00349
00351 struct ScientificSettings {
00353 int8_t fEngineeringInterval;
00355 bool fRequireMinInt;
00357 impl::digits_t fMinExponentDigits;
00359 UNumberSignDisplay fExponentSignDisplay;
00360 } scientific;
00361
00362
00363 UNumberCompactStyle compactStyle;
00364
00365
00366 UErrorCode errorCode;
00367 } fUnion;
00368
00369 typedef NotationUnion::ScientificSettings ScientificSettings;
00370
00371 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
00372
00373 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
00374 fUnion.errorCode = errorCode;
00375 }
00376
00377 Notation() : fType(NTN_SIMPLE), fUnion() {}
00378
00379 UBool copyErrorTo(UErrorCode &status) const {
00380 if (fType == NTN_ERROR) {
00381 status = fUnion.errorCode;
00382 return true;
00383 }
00384 return false;
00385 }
00386
00387
00388 friend struct impl::MacroProps;
00389 friend class ScientificNotation;
00390
00391
00392 friend class impl::NumberFormatterImpl;
00393 friend class impl::ScientificModifier;
00394 friend class impl::ScientificHandler;
00395
00396
00397 friend class impl::GeneratorHelpers;
00398 };
00399
00408 class U_I18N_API ScientificNotation : public Notation {
00409 public:
00423 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
00424
00438 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
00439
00440 private:
00441
00442 using Notation::Notation;
00443
00444
00445 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
00446 UNumberSignDisplay fExponentSignDisplay);
00447
00448 friend class Notation;
00449
00450
00451 friend class impl::NumberPropertyMapper;
00452 };
00453
00459 typedef Precision SignificantDigitsPrecision;
00460
00469 class U_I18N_API Precision : public UMemory {
00470
00471 public:
00489 static Precision unlimited();
00490
00497 static FractionPrecision integer();
00498
00526 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
00527
00541 static FractionPrecision minFraction(int32_t minFractionPlaces);
00542
00553 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
00554
00568 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
00569
00583 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
00584
00597 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
00598
00607 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
00608
00620 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
00621 int32_t maxSignificantDigits);
00622
00642 static IncrementPrecision increment(double roundingIncrement);
00643
00644 #ifndef U_HIDE_DRAFT_API
00645
00668 static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude);
00669 #endif // U_HIDE_DRAFT_API
00670
00688 static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
00689
00697 Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const;
00698
00699 private:
00700 enum PrecisionType {
00701 RND_BOGUS,
00702 RND_NONE,
00703 RND_FRACTION,
00704 RND_SIGNIFICANT,
00705 RND_FRACTION_SIGNIFICANT,
00706
00707
00708 RND_INCREMENT,
00709
00710
00711
00712
00713 RND_INCREMENT_ONE,
00714
00715
00716 RND_INCREMENT_FIVE,
00717
00718 RND_CURRENCY,
00719 RND_ERROR
00720 } fType;
00721
00722 union PrecisionUnion {
00724 struct FractionSignificantSettings {
00725
00727 impl::digits_t fMinFrac;
00729 impl::digits_t fMaxFrac;
00731 impl::digits_t fMinSig;
00733 impl::digits_t fMaxSig;
00735 UNumberRoundingPriority fPriority;
00740 bool fRetain;
00741 } fracSig;
00743 struct IncrementSettings {
00744
00745
00746
00748 uint64_t fIncrement;
00750 impl::digits_t fIncrementMagnitude;
00752 impl::digits_t fMinFrac;
00753 } increment;
00754 UCurrencyUsage currencyUsage;
00755 UErrorCode errorCode;
00756 } fUnion;
00757
00758 UNumberTrailingZeroDisplay fTrailingZeroDisplay = UNUM_TRAILING_ZERO_AUTO;
00759
00760 typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
00761 typedef PrecisionUnion::IncrementSettings IncrementSettings;
00762
00763 Precision(const PrecisionType& type, const PrecisionUnion& union_)
00764 : fType(type), fUnion(union_) {}
00765
00766 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
00767 fUnion.errorCode = errorCode;
00768 }
00769
00770 Precision() : fType(RND_BOGUS) {}
00771
00772 bool isBogus() const {
00773 return fType == RND_BOGUS;
00774 }
00775
00776 UBool copyErrorTo(UErrorCode &status) const {
00777 if (fType == RND_ERROR) {
00778 status = fUnion.errorCode;
00779 return true;
00780 }
00781 return false;
00782 }
00783
00784
00785 Precision withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const;
00786
00787 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
00788
00789 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
00790
00791 static Precision constructFractionSignificant(
00792 const FractionPrecision &base,
00793 int32_t minSig,
00794 int32_t maxSig,
00795 UNumberRoundingPriority priority,
00796 bool retain);
00797
00798 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
00799
00800 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
00801
00802
00803 friend struct impl::MacroProps;
00804 friend struct impl::MicroProps;
00805
00806
00807 friend class impl::NumberFormatterImpl;
00808
00809
00810 friend class impl::NumberPropertyMapper;
00811
00812
00813 friend class impl::RoundingImpl;
00814
00815
00816 friend class FractionPrecision;
00817 friend class CurrencyPrecision;
00818 friend class IncrementPrecision;
00819
00820
00821 friend class impl::GeneratorHelpers;
00822
00823
00824 friend class units::UnitsRouter;
00825 };
00826
00836 class U_I18N_API FractionPrecision : public Precision {
00837 public:
00852 Precision withSignificantDigits(
00853 int32_t minSignificantDigits,
00854 int32_t maxSignificantDigits,
00855 UNumberRoundingPriority priority) const;
00856
00874 Precision withMinDigits(int32_t minSignificantDigits) const;
00875
00893 Precision withMaxDigits(int32_t maxSignificantDigits) const;
00894
00895 private:
00896
00897 using Precision::Precision;
00898
00899
00900 friend class Precision;
00901 };
00902
00912 class U_I18N_API CurrencyPrecision : public Precision {
00913 public:
00931 Precision withCurrency(const CurrencyUnit ¤cy) const;
00932
00933 private:
00934
00935 using Precision::Precision;
00936
00937
00938 friend class Precision;
00939 };
00940
00950 class U_I18N_API IncrementPrecision : public Precision {
00951 public:
00967 Precision withMinFraction(int32_t minFrac) const;
00968
00969 private:
00970
00971 using Precision::Precision;
00972
00973
00974 friend class Precision;
00975 };
00976
00986 class U_I18N_API IntegerWidth : public UMemory {
00987 public:
00999 static IntegerWidth zeroFillTo(int32_t minInt);
01000
01012 IntegerWidth truncateAt(int32_t maxInt);
01013
01014 private:
01015 union {
01016 struct {
01017 impl::digits_t fMinInt;
01018 impl::digits_t fMaxInt;
01019 bool fFormatFailIfMoreThanMaxDigits;
01020 } minMaxInt;
01021 UErrorCode errorCode;
01022 } fUnion;
01023 bool fHasError = false;
01024
01025 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
01026
01027 IntegerWidth(UErrorCode errorCode) {
01028 fUnion.errorCode = errorCode;
01029 fHasError = true;
01030 }
01031
01032 IntegerWidth() {
01033 fUnion.minMaxInt.fMinInt = -1;
01034 }
01035
01037 static IntegerWidth standard() {
01038 return IntegerWidth::zeroFillTo(1);
01039 }
01040
01041 bool isBogus() const {
01042 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
01043 }
01044
01045 UBool copyErrorTo(UErrorCode &status) const {
01046 if (fHasError) {
01047 status = fUnion.errorCode;
01048 return true;
01049 }
01050 return false;
01051 }
01052
01053 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
01054
01055 bool operator==(const IntegerWidth& other) const;
01056
01057
01058 friend struct impl::MacroProps;
01059 friend struct impl::MicroProps;
01060
01061
01062 friend class impl::NumberFormatterImpl;
01063
01064
01065 friend class impl::MutablePatternModifier;
01066 friend class impl::ImmutablePatternModifier;
01067
01068
01069 friend class impl::NumberPropertyMapper;
01070
01071
01072 friend class impl::GeneratorHelpers;
01073 };
01074
01083 class U_I18N_API Scale : public UMemory {
01084 public:
01091 static Scale none();
01092
01103 static Scale powerOfTen(int32_t power);
01104
01117 static Scale byDecimal(StringPiece multiplicand);
01118
01127 static Scale byDouble(double multiplicand);
01128
01135 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
01136
01137
01138
01139
01141 Scale(const Scale& other);
01142
01144 Scale& operator=(const Scale& other);
01145
01147 Scale(Scale&& src) U_NOEXCEPT;
01148
01150 Scale& operator=(Scale&& src) U_NOEXCEPT;
01151
01153 ~Scale();
01154
01155 #ifndef U_HIDE_INTERNAL_API
01156
01157 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
01158 #endif
01159
01160 private:
01161 int32_t fMagnitude;
01162 impl::DecNum* fArbitrary;
01163 UErrorCode fError;
01164
01165 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
01166
01167 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
01168
01169 bool isValid() const {
01170 return fMagnitude != 0 || fArbitrary != nullptr;
01171 }
01172
01173 UBool copyErrorTo(UErrorCode &status) const {
01174 if (U_FAILURE(fError)) {
01175 status = fError;
01176 return true;
01177 }
01178 return false;
01179 }
01180
01181 void applyTo(impl::DecimalQuantity& quantity) const;
01182
01183 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
01184
01185
01186 friend struct impl::MacroProps;
01187 friend struct impl::MicroProps;
01188
01189
01190 friend class impl::NumberFormatterImpl;
01191
01192
01193 friend class impl::MultiplierFormatHandler;
01194
01195
01196 friend class impl::GeneratorHelpers;
01197
01198
01199 friend class ::icu::numparse::impl::NumberParserImpl;
01200 friend class ::icu::numparse::impl::MultiplierParseHandler;
01201 };
01202
01203 namespace impl {
01204
01205
01206
01211 class U_I18N_API StringProp : public UMemory {
01212
01213 public:
01215 ~StringProp();
01216
01218 StringProp(const StringProp &other);
01219
01221 StringProp &operator=(const StringProp &other);
01222
01223 #ifndef U_HIDE_INTERNAL_API
01224
01226 StringProp(StringProp &&src) U_NOEXCEPT;
01227
01229 StringProp &operator=(StringProp &&src) U_NOEXCEPT;
01230
01232 int16_t length() const {
01233 return fLength;
01234 }
01235
01239 void set(StringPiece value);
01240
01242 bool isSet() const {
01243 return fLength > 0;
01244 }
01245
01246 #endif // U_HIDE_INTERNAL_API
01247
01248 private:
01249 char *fValue;
01250 int16_t fLength;
01251 UErrorCode fError;
01252
01253 StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
01254 }
01255
01257 UBool copyErrorTo(UErrorCode &status) const {
01258 if (U_FAILURE(fError)) {
01259 status = fError;
01260 return true;
01261 }
01262 return false;
01263 }
01264
01265
01266 friend class impl::NumberFormatterImpl;
01267
01268
01269 friend class impl::GeneratorHelpers;
01270
01271
01272
01273 friend struct impl::MacroProps;
01274 };
01275
01276
01278 class U_I18N_API SymbolsWrapper : public UMemory {
01279 public:
01281 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
01282
01284 SymbolsWrapper(const SymbolsWrapper &other);
01285
01287 SymbolsWrapper &operator=(const SymbolsWrapper &other);
01288
01290 SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
01291
01293 SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
01294
01296 ~SymbolsWrapper();
01297
01298 #ifndef U_HIDE_INTERNAL_API
01299
01304 void setTo(const DecimalFormatSymbols &dfs);
01305
01310 void setTo(const NumberingSystem *ns);
01311
01316 bool isDecimalFormatSymbols() const;
01317
01322 bool isNumberingSystem() const;
01323
01328 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
01329
01334 const NumberingSystem *getNumberingSystem() const;
01335
01336 #endif // U_HIDE_INTERNAL_API
01337
01339 UBool copyErrorTo(UErrorCode &status) const {
01340 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
01341 status = U_MEMORY_ALLOCATION_ERROR;
01342 return true;
01343 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
01344 status = U_MEMORY_ALLOCATION_ERROR;
01345 return true;
01346 }
01347 return false;
01348 }
01349
01350 private:
01351 enum SymbolsPointerType {
01352 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
01353 } fType;
01354
01355 union {
01356 const DecimalFormatSymbols *dfs;
01357 const NumberingSystem *ns;
01358 } fPtr;
01359
01360 void doCopyFrom(const SymbolsWrapper &other);
01361
01362 void doMoveFrom(SymbolsWrapper&& src);
01363
01364 void doCleanup();
01365 };
01366
01367
01369 class U_I18N_API Grouper : public UMemory {
01370 public:
01371 #ifndef U_HIDE_INTERNAL_API
01372
01373 static Grouper forStrategy(UNumberGroupingStrategy grouping);
01374
01379 static Grouper forProperties(const DecimalFormatProperties& properties);
01380
01381
01382
01384 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
01385 : fGrouping1(grouping1),
01386 fGrouping2(grouping2),
01387 fMinGrouping(minGrouping),
01388 fStrategy(strategy) {}
01389
01391 int16_t getPrimary() const;
01392
01394 int16_t getSecondary() const;
01395 #endif // U_HIDE_INTERNAL_API
01396
01397 private:
01406 int16_t fGrouping1;
01407 int16_t fGrouping2;
01408
01416 int16_t fMinGrouping;
01417
01422 UNumberGroupingStrategy fStrategy;
01423
01424 Grouper() : fGrouping1(-3) {}
01425
01426 bool isBogus() const {
01427 return fGrouping1 == -3;
01428 }
01429
01431 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
01432
01433 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
01434
01435
01436 friend struct MacroProps;
01437 friend struct MicroProps;
01438
01439
01440 friend class NumberFormatterImpl;
01441
01442
01443 friend class ::icu::numparse::impl::NumberParserImpl;
01444
01445
01446 friend class impl::GeneratorHelpers;
01447 };
01448
01449
01451 class U_I18N_API Padder : public UMemory {
01452 public:
01453 #ifndef U_HIDE_INTERNAL_API
01454
01455 static Padder none();
01456
01458 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
01459
01461 static Padder forProperties(const DecimalFormatProperties& properties);
01462 #endif // U_HIDE_INTERNAL_API
01463
01464 private:
01465 UChar32 fWidth;
01466 union {
01467 struct {
01468 int32_t fCp;
01469 UNumberFormatPadPosition fPosition;
01470 } padding;
01471 UErrorCode errorCode;
01472 } fUnion;
01473
01474 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
01475
01476 Padder(int32_t width);
01477
01478 Padder(UErrorCode errorCode) : fWidth(-3) {
01479 fUnion.errorCode = errorCode;
01480 }
01481
01482 Padder() : fWidth(-2) {}
01483
01484 bool isBogus() const {
01485 return fWidth == -2;
01486 }
01487
01488 UBool copyErrorTo(UErrorCode &status) const {
01489 if (fWidth == -3) {
01490 status = fUnion.errorCode;
01491 return true;
01492 }
01493 return false;
01494 }
01495
01496 bool isValid() const {
01497 return fWidth > 0;
01498 }
01499
01500 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
01501 FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
01502 UErrorCode &status) const;
01503
01504
01505 friend struct MacroProps;
01506 friend struct MicroProps;
01507
01508
01509 friend class impl::NumberFormatterImpl;
01510
01511
01512 friend class impl::GeneratorHelpers;
01513 };
01514
01515
01517 struct U_I18N_API MacroProps : public UMemory {
01519 Notation notation;
01520
01522 MeasureUnit unit;
01523
01525 MeasureUnit perUnit;
01526
01528 Precision precision;
01529
01531 UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
01532
01534 Grouper grouper;
01535
01537 Padder padder;
01538
01540 IntegerWidth integerWidth;
01541
01543 SymbolsWrapper symbols;
01544
01545
01546
01548 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
01549
01551 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
01552
01554 bool approximately = false;
01555
01557 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
01558
01560 Scale scale;
01561
01563 StringProp usage;
01564
01566 StringProp unitDisplayCase;
01567
01569 const AffixPatternProvider* affixProvider = nullptr;
01570
01572 const PluralRules* rules = nullptr;
01573
01575 int32_t threshold = kInternalDefaultThreshold;
01576
01578 Locale locale;
01579
01580
01581
01586 bool copyErrorTo(UErrorCode &status) const {
01587 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
01588 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
01589 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
01590 unitDisplayCase.copyErrorTo(status);
01591 }
01592 };
01593
01594 }
01595
01596 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
01597
01598
01599
01600
01601
01602 #pragma warning(push)
01603 #pragma warning(disable: 4661)
01604 #endif
01605
01611 template<typename Derived>
01612 class U_I18N_API NumberFormatterSettings {
01613 public:
01642 Derived notation(const Notation ¬ation) const &;
01643
01653 Derived notation(const Notation ¬ation) &&;
01654
01703 Derived unit(const icu::MeasureUnit &unit) const &;
01704
01714 Derived unit(const icu::MeasureUnit &unit) &&;
01715
01729 Derived adoptUnit(icu::MeasureUnit *unit) const &;
01730
01740 Derived adoptUnit(icu::MeasureUnit *unit) &&;
01741
01764 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
01765
01775 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
01776
01790 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
01791
01801 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
01802
01833 Derived precision(const Precision& precision) const &;
01834
01844 Derived precision(const Precision& precision) &&;
01845
01864 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
01865
01874 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
01875
01903 Derived grouping(UNumberGroupingStrategy strategy) const &;
01904
01914 Derived grouping(UNumberGroupingStrategy strategy) &&;
01915
01940 Derived integerWidth(const IntegerWidth &style) const &;
01941
01951 Derived integerWidth(const IntegerWidth &style) &&;
01952
01993 Derived symbols(const DecimalFormatSymbols &symbols) const &;
01994
02004 Derived symbols(const DecimalFormatSymbols &symbols) &&;
02005
02039 Derived adoptSymbols(NumberingSystem *symbols) const &;
02040
02050 Derived adoptSymbols(NumberingSystem *symbols) &&;
02051
02077 Derived unitWidth(UNumberUnitWidth width) const &;
02078
02088 Derived unitWidth(UNumberUnitWidth width) &&;
02089
02115 Derived sign(UNumberSignDisplay style) const &;
02116
02126 Derived sign(UNumberSignDisplay style) &&;
02127
02153 Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
02154
02164 Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
02165
02190 Derived scale(const Scale &scale) const &;
02191
02201 Derived scale(const Scale &scale) &&;
02202
02245 Derived usage(StringPiece usage) const &;
02246
02254 Derived usage(StringPiece usage) &&;
02255
02256 #ifndef U_HIDE_DRAFT_API
02257 #ifndef U_HIDE_INTERNAL_API
02258
02264 Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
02265
02271 Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
02272 #endif // U_HIDE_INTERNAL_API
02273 #endif // U_HIDE_DRAFT_API
02274
02275 #ifndef U_HIDE_INTERNAL_API
02276
02282 Derived padding(const impl::Padder &padder) const &;
02283
02285 Derived padding(const impl::Padder &padder) &&;
02286
02293 Derived threshold(int32_t threshold) const &;
02294
02296 Derived threshold(int32_t threshold) &&;
02297
02303 Derived macros(const impl::MacroProps& macros) const &;
02304
02306 Derived macros(const impl::MacroProps& macros) &&;
02307
02309 Derived macros(impl::MacroProps&& macros) const &;
02310
02312 Derived macros(impl::MacroProps&& macros) &&;
02313
02314 #endif
02315
02333 UnicodeString toSkeleton(UErrorCode& status) const;
02334
02346 LocalPointer<Derived> clone() const &;
02347
02355 LocalPointer<Derived> clone() &&;
02356
02363 UBool copyErrorTo(UErrorCode &outErrorCode) const {
02364 if (U_FAILURE(outErrorCode)) {
02365
02366 return true;
02367 }
02368 fMacros.copyErrorTo(outErrorCode);
02369 return U_FAILURE(outErrorCode);
02370 }
02371
02372
02373
02374 private:
02375 impl::MacroProps fMacros;
02376
02377
02378 NumberFormatterSettings() = default;
02379
02380 friend class LocalizedNumberFormatter;
02381 friend class UnlocalizedNumberFormatter;
02382
02383
02384 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
02385 friend class impl::NumberRangeFormatterImpl;
02386 };
02387
02396 class U_I18N_API UnlocalizedNumberFormatter
02397 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
02398
02399 public:
02409 LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
02410
02420 LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
02421
02427 UnlocalizedNumberFormatter() = default;
02428
02433 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
02434
02440 UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02441
02446 UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
02447
02453 UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
02454
02455 private:
02456 explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
02457
02458 explicit UnlocalizedNumberFormatter(
02459 NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) U_NOEXCEPT;
02460
02461
02462 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02463
02464
02465 friend class NumberFormatter;
02466 };
02467
02476 class U_I18N_API LocalizedNumberFormatter
02477 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
02478 public:
02490 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
02491
02503 FormattedNumber formatDouble(double value, UErrorCode &status) const;
02504
02519 FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
02520
02521 #ifndef U_HIDE_INTERNAL_API
02522
02523
02527 const DecimalFormatSymbols* getDecimalFormatSymbols() const;
02528
02532 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
02533
02537 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
02538
02543 const impl::NumberFormatterImpl* getCompiled() const;
02544
02549 int32_t getCallCount() const;
02550
02551 #endif
02552
02566 Format* toFormat(UErrorCode& status) const;
02567
02573 LocalizedNumberFormatter() = default;
02574
02579 LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
02580
02586 LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02587
02592 LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
02593
02599 LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) U_NOEXCEPT;
02600
02601 #ifndef U_HIDE_INTERNAL_API
02602
02615 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
02616
02617 #endif
02618
02623 ~LocalizedNumberFormatter();
02624
02625 private:
02626
02627
02628 const impl::NumberFormatterImpl* fCompiled {nullptr};
02629 char fUnsafeCallCount[8] {};
02630
02631
02632
02633 const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
02634
02635 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
02636
02637 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
02638
02639 LocalizedNumberFormatter(const impl::MacroProps ¯os, const Locale &locale);
02640
02641 LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale);
02642
02643 void resetCompiled();
02644
02645 void lnfMoveHelper(LocalizedNumberFormatter&& src);
02646
02647 void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
02648
02652 bool computeCompiled(UErrorCode& status) const;
02653
02654
02655 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
02656 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
02657
02658
02659 friend class UnlocalizedNumberFormatter;
02660 };
02661
02662 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
02663
02664 #pragma warning(pop)
02665 #endif
02666
02675 class U_I18N_API FormattedNumber : public UMemory, public FormattedValue {
02676 public:
02677
02682 FormattedNumber()
02683 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
02684
02689 FormattedNumber(FormattedNumber&& src) U_NOEXCEPT;
02690
02695 virtual ~FormattedNumber() U_OVERRIDE;
02696
02698 FormattedNumber(const FormattedNumber&) = delete;
02699
02701 FormattedNumber& operator=(const FormattedNumber&) = delete;
02702
02707 FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT;
02708
02709
02717 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
02718
02719
02721 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
02722
02723
02731 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
02732
02733
02735 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
02736
02755 template<typename StringClass>
02756 inline StringClass toDecimalNumber(UErrorCode& status) const;
02757
02769 MeasureUnit getOutputUnit(UErrorCode& status) const;
02770
02771 #ifndef U_HIDE_DRAFT_API
02772
02780 NounClass getNounClass(UErrorCode &status) const;
02781
02782 #endif // U_HIDE_DRAFT_API
02783
02784 #ifndef U_HIDE_INTERNAL_API
02785
02790 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
02791
02796 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
02797
02798 #endif
02799
02800 #ifndef U_HIDE_DEPRECATED_API
02801
02808 const char *getGender(UErrorCode &status) const;
02809
02810 #endif
02811
02812 private:
02813
02814 const impl::UFormattedNumberData *fData;
02815
02816
02817 UErrorCode fErrorCode;
02818
02823 explicit FormattedNumber(impl::UFormattedNumberData *results)
02824 : fData(results), fErrorCode(U_ZERO_ERROR) {}
02825
02826 explicit FormattedNumber(UErrorCode errorCode)
02827 : fData(nullptr), fErrorCode(errorCode) {}
02828
02829 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
02830
02831
02832 friend class LocalizedNumberFormatter;
02833
02834
02835 friend struct impl::UFormattedNumberImpl;
02836 };
02837
02838 template<typename StringClass>
02839 StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
02840 StringClass result;
02841 StringByteSink<StringClass> sink(&result);
02842 toDecimalNumber(sink, status);
02843 return result;
02844 }
02845
02851 class U_I18N_API NumberFormatter final {
02852 public:
02860 static UnlocalizedNumberFormatter with();
02861
02871 static LocalizedNumberFormatter withLocale(const Locale &locale);
02872
02890 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
02891
02912 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton,
02913 UParseError& perror, UErrorCode& status);
02914
02918 NumberFormatter() = delete;
02919 };
02920
02921 }
02922 U_NAMESPACE_END
02923
02924 #endif
02925
02926 #endif
02927
02928 #endif // __NUMBERFORMATTER_H__