decimfmt.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2012, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 ********************************************************************************
00006 *
00007 * File DECIMFMT.H
00008 *
00009 * Modification History:
00010 *
00011 *   Date        Name        Description
00012 *   02/19/97    aliu        Converted from java.
00013 *   03/20/97    clhuang     Updated per C++ implementation.
00014 *   04/03/97    aliu        Rewrote parsing and formatting completely, and
00015 *                           cleaned up and debugged.  Actually works now.
00016 *   04/17/97    aliu        Changed DigitCount to int per code review.
00017 *   07/10/97    helena      Made ParsePosition a class and get rid of the function
00018 *                           hiding problems.
00019 *   09/09/97    aliu        Ported over support for exponential formats.
00020 *    07/20/98    stephen        Changed documentation
00021 ********************************************************************************
00022 */
00023 
00024 #ifndef DECIMFMT_H
00025 #define DECIMFMT_H
00026 
00027 #include "unicode/utypes.h"
00033 #if !UCONFIG_NO_FORMATTING
00034 
00035 #include "unicode/dcfmtsym.h"
00036 #include "unicode/numfmt.h"
00037 #include "unicode/locid.h"
00038 #include "unicode/fpositer.h"
00039 #include "unicode/stringpiece.h"
00040 #include "unicode/curramt.h"
00041 #include "unicode/enumset.h"
00042 
00047 #if UCONFIG_FORMAT_FASTPATHS_49
00048 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
00049 #endif
00050 
00051 U_NAMESPACE_BEGIN
00052 
00053 class DigitList;
00054 class ChoiceFormat;
00055 class CurrencyPluralInfo;
00056 class Hashtable;
00057 class UnicodeSet;
00058 class FieldPositionHandler;
00059 
00060 // explicit template instantiation. see digitlst.h
00061 #if defined (_MSC_VER)
00062 template class U_I18N_API    EnumSet<UNumberFormatAttribute,
00063             UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, 
00064             UNUM_LIMIT_BOOLEAN_ATTRIBUTE>;
00065 #endif
00066 
00660 class U_I18N_API DecimalFormat: public NumberFormat {
00661 public:
00666     enum ERoundingMode {
00667         kRoundCeiling,  
00668         kRoundFloor,    
00669         kRoundDown,     
00670         kRoundUp,       
00671         kRoundHalfEven, 
00673         kRoundHalfDown, 
00675         kRoundHalfUp,   
00681         kRoundUnnecessary
00682     };
00683 
00688     enum EPadPosition {
00689         kPadBeforePrefix,
00690         kPadAfterPrefix,
00691         kPadBeforeSuffix,
00692         kPadAfterSuffix
00693     };
00694 
00708     DecimalFormat(UErrorCode& status);
00709 
00724     DecimalFormat(const UnicodeString& pattern,
00725                   UErrorCode& status);
00726 
00745     DecimalFormat(  const UnicodeString& pattern,
00746                     DecimalFormatSymbols* symbolsToAdopt,
00747                     UErrorCode& status);
00748 
00749 #ifndef U_HIDE_INTERNAL_API
00750 
00762     DecimalFormat(  const UnicodeString& pattern,
00763                     DecimalFormatSymbols* symbolsToAdopt,
00764                     UNumberFormatStyle style,
00765                     UErrorCode& status);
00766 
00767 
00778     virtual DecimalFormat& setAttribute( UNumberFormatAttribute attr,
00779                                        int32_t newvalue,
00780                                        UErrorCode &status);
00781 
00791     virtual int32_t getAttribute( UNumberFormatAttribute attr,
00792                                   UErrorCode &status) const;
00793 
00794 #if UCONFIG_HAVE_PARSEALLINPUT
00795 
00798     void setParseAllInput(UNumberFormatAttributeValue value);
00799 #endif
00800 
00801 #endif  /* U_HIDE_INTERNAL_API */
00802 
00822     DecimalFormat(  const UnicodeString& pattern,
00823                     DecimalFormatSymbols* symbolsToAdopt,
00824                     UParseError& parseError,
00825                     UErrorCode& status);
00843     DecimalFormat(  const UnicodeString& pattern,
00844                     const DecimalFormatSymbols& symbols,
00845                     UErrorCode& status);
00846 
00853     DecimalFormat(const DecimalFormat& source);
00854 
00861     DecimalFormat& operator=(const DecimalFormat& rhs);
00862 
00867     virtual ~DecimalFormat();
00868 
00876     virtual Format* clone(void) const;
00877 
00886     virtual UBool operator==(const Format& other) const;
00887 
00888 
00889     using NumberFormat::format;
00890 
00902     virtual UnicodeString& format(double number,
00903                                   UnicodeString& appendTo,
00904                                   FieldPosition& pos) const;
00905 
00906 
00919     virtual UnicodeString& format(double number,
00920                                   UnicodeString& appendTo,
00921                                   FieldPosition& pos,
00922                                   UErrorCode &status) const;
00923 
00937     virtual UnicodeString& format(double number,
00938                                   UnicodeString& appendTo,
00939                                   FieldPositionIterator* posIter,
00940                                   UErrorCode& status) const;
00941 
00953     virtual UnicodeString& format(int32_t number,
00954                                   UnicodeString& appendTo,
00955                                   FieldPosition& pos) const;
00956 
00968     virtual UnicodeString& format(int32_t number,
00969                                   UnicodeString& appendTo,
00970                                   FieldPosition& pos,
00971                                   UErrorCode &status) const;
00972 
00986     virtual UnicodeString& format(int32_t number,
00987                                   UnicodeString& appendTo,
00988                                   FieldPositionIterator* posIter,
00989                                   UErrorCode& status) const;
00990 
01002     virtual UnicodeString& format(int64_t number,
01003                                   UnicodeString& appendTo,
01004                                   FieldPosition& pos) const;
01005 
01017     virtual UnicodeString& format(int64_t number,
01018                                   UnicodeString& appendTo,
01019                                   FieldPosition& pos,
01020                                   UErrorCode &status) const;
01021 
01035     virtual UnicodeString& format(int64_t number,
01036                                   UnicodeString& appendTo,
01037                                   FieldPositionIterator* posIter,
01038                                   UErrorCode& status) const;
01039 
01056     virtual UnicodeString& format(const StringPiece &number,
01057                                   UnicodeString& appendTo,
01058                                   FieldPositionIterator* posIter,
01059                                   UErrorCode& status) const;
01060 
01061 
01077     virtual UnicodeString& format(const DigitList &number,
01078                                   UnicodeString& appendTo,
01079                                   FieldPositionIterator* posIter,
01080                                   UErrorCode& status) const;
01081 
01097     virtual UnicodeString& format(const DigitList &number,
01098                                   UnicodeString& appendTo,
01099                                   FieldPosition& pos,
01100                                   UErrorCode& status) const;
01101 
01102 
01115     virtual UnicodeString& format(const Formattable& obj,
01116                                   UnicodeString& appendTo,
01117                                   FieldPosition& pos,
01118                                   UErrorCode& status) const;
01119 
01131     UnicodeString& format(const Formattable& obj,
01132                           UnicodeString& appendTo,
01133                           UErrorCode& status) const;
01134 
01145     UnicodeString& format(double number,
01146                           UnicodeString& appendTo) const;
01147 
01159     UnicodeString& format(int32_t number,
01160                           UnicodeString& appendTo) const;
01161 
01173     UnicodeString& format(int64_t number,
01174                           UnicodeString& appendTo) const;
01194     virtual void parse(const UnicodeString& text,
01195                        Formattable& result,
01196                        ParsePosition& parsePosition) const;
01197 
01198     // Declare here again to get rid of function hiding problems.
01207     virtual void parse(const UnicodeString& text,
01208                        Formattable& result,
01209                        UErrorCode& status) const;
01210 
01211 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
01231     virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
01232                                           ParsePosition& pos) const;
01233 
01241     virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
01242 
01249     virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
01250 
01257     virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
01258 
01259 
01266     virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
01267 
01274     virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
01275 
01282     virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info);
01283 
01284 
01293     UnicodeString& getPositivePrefix(UnicodeString& result) const;
01294 
01302     virtual void setPositivePrefix(const UnicodeString& newValue);
01303 
01312     UnicodeString& getNegativePrefix(UnicodeString& result) const;
01313 
01321     virtual void setNegativePrefix(const UnicodeString& newValue);
01322 
01331     UnicodeString& getPositiveSuffix(UnicodeString& result) const;
01332 
01340     virtual void setPositiveSuffix(const UnicodeString& newValue);
01341 
01350     UnicodeString& getNegativeSuffix(UnicodeString& result) const;
01351 
01359     virtual void setNegativeSuffix(const UnicodeString& newValue);
01360 
01371     int32_t getMultiplier(void) const;
01372 
01383     virtual void setMultiplier(int32_t newValue);
01384 
01394     virtual double getRoundingIncrement(void) const;
01395 
01406     virtual void setRoundingIncrement(double newValue);
01407 
01416     virtual ERoundingMode getRoundingMode(void) const;
01417 
01426     virtual void setRoundingMode(ERoundingMode roundingMode);
01427 
01439     virtual int32_t getFormatWidth(void) const;
01440 
01455     virtual void setFormatWidth(int32_t width);
01456 
01469     virtual UnicodeString getPadCharacterString() const;
01470 
01485     virtual void setPadCharacter(const UnicodeString &padChar);
01486 
01502     virtual EPadPosition getPadPosition(void) const;
01503 
01520     virtual void setPadPosition(EPadPosition padPos);
01521 
01532     virtual UBool isScientificNotation(void);
01533 
01549     virtual void setScientificNotation(UBool useScientific);
01550 
01561     virtual int8_t getMinimumExponentDigits(void) const;
01562 
01575     virtual void setMinimumExponentDigits(int8_t minExpDig);
01576 
01589     virtual UBool isExponentSignAlwaysShown(void);
01590 
01604     virtual void setExponentSignAlwaysShown(UBool expSignAlways);
01605 
01617     int32_t getGroupingSize(void) const;
01618 
01630     virtual void setGroupingSize(int32_t newValue);
01631 
01650     int32_t getSecondaryGroupingSize(void) const;
01651 
01663     virtual void setSecondaryGroupingSize(int32_t newValue);
01664 
01673     UBool isDecimalSeparatorAlwaysShown(void) const;
01674 
01683     virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
01684 
01695     virtual UnicodeString& toPattern(UnicodeString& result) const;
01696 
01707     virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
01708 
01738     virtual void applyPattern(const UnicodeString& pattern,
01739                              UParseError& parseError,
01740                              UErrorCode& status);
01749     virtual void applyPattern(const UnicodeString& pattern,
01750                              UErrorCode& status);
01751 
01782     virtual void applyLocalizedPattern(const UnicodeString& pattern,
01783                                        UParseError& parseError,
01784                                        UErrorCode& status);
01785 
01795     virtual void applyLocalizedPattern(const UnicodeString& pattern,
01796                                        UErrorCode& status);
01797 
01798 
01808     virtual void setMaximumIntegerDigits(int32_t newValue);
01809 
01819     virtual void setMinimumIntegerDigits(int32_t newValue);
01820 
01830     virtual void setMaximumFractionDigits(int32_t newValue);
01831 
01841     virtual void setMinimumFractionDigits(int32_t newValue);
01842 
01850     int32_t getMinimumSignificantDigits() const;
01851 
01859     int32_t getMaximumSignificantDigits() const;
01860 
01870     void setMinimumSignificantDigits(int32_t min);
01871 
01882     void setMaximumSignificantDigits(int32_t max);
01883 
01890     UBool areSignificantDigitsUsed() const;
01891 
01899     void setSignificantDigitsUsed(UBool useSignificantDigits);
01900 
01901  public:
01914     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
01915 
01921     virtual void setCurrency(const UChar* theCurrency);
01922 
01928     static const char fgNumberPatterns[];
01929 
01930 public:
01931 
01943     static UClassID U_EXPORT2 getStaticClassID(void);
01944 
01956     virtual UClassID getDynamicClassID(void) const;
01957 
01958 private:
01959 
01960     DecimalFormat(); // default constructor not implemented
01961 
01962     int32_t precision() const;
01963 
01968     void init(UErrorCode& status);
01969 
01973     void construct(UErrorCode&               status,
01974                    UParseError&             parseErr,
01975                    const UnicodeString*     pattern = 0,
01976                    DecimalFormatSymbols*    symbolsToAdopt = 0
01977                    );
01978 
01987     UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
01988 
01999     void applyPattern(const UnicodeString& pattern,
02000                             UBool localized,
02001                             UParseError& parseError,
02002                             UErrorCode& status);
02003 
02004     /*
02005      * similar to applyPattern, but without re-gen affix for currency
02006      */
02007     void applyPatternInternally(const UnicodeString& pluralCount,
02008                                 const UnicodeString& pattern,
02009                                 UBool localized,
02010                                 UParseError& parseError,
02011                                 UErrorCode& status);
02012 
02013     /*
02014      * only apply pattern without expand affixes
02015      */
02016     void applyPatternWithoutExpandAffix(const UnicodeString& pattern,
02017                                         UBool localized,
02018                                         UParseError& parseError,
02019                                         UErrorCode& status);
02020 
02021 
02022     /*
02023      * expand affixes (after apply patter) and re-compute fFormatWidth
02024      */
02025     void expandAffixAdjustWidth(const UnicodeString* pluralCount);
02026 
02027 
02038     UnicodeString& subformat(UnicodeString& appendTo,
02039                              FieldPositionHandler& handler,
02040                              DigitList&     digits,
02041                              UBool          isInteger, 
02042                              UErrorCode &status) const;
02043 
02044 
02045     void parse(const UnicodeString& text,
02046                Formattable& result,
02047                ParsePosition& pos,
02048                UChar* currency) const;
02049 
02050     enum {
02051         fgStatusInfinite,
02052         fgStatusLength      // Leave last in list.
02053     } StatusFlags;
02054 
02055     UBool subparse(const UnicodeString& text,
02056                    const UnicodeString* negPrefix,
02057                    const UnicodeString* negSuffix,
02058                    const UnicodeString* posPrefix,
02059                    const UnicodeString* posSuffix,
02060                    UBool currencyParsing,
02061                    int8_t type,
02062                    ParsePosition& parsePosition,
02063                    DigitList& digits, UBool* status,
02064                    UChar* currency) const;
02065 
02066     // Mixed style parsing for currency.
02067     // It parses against the current currency pattern
02068     // using complex affix comparison
02069     // parses against the currency plural patterns using complex affix comparison,
02070     // and parses against the current pattern using simple affix comparison.
02071     UBool parseForCurrency(const UnicodeString& text,
02072                            ParsePosition& parsePosition,
02073                            DigitList& digits,
02074                            UBool* status,
02075                            UChar* currency) const;
02076 
02077     int32_t skipPadding(const UnicodeString& text, int32_t position) const;
02078 
02079     int32_t compareAffix(const UnicodeString& input,
02080                          int32_t pos,
02081                          UBool isNegative,
02082                          UBool isPrefix,
02083                          const UnicodeString* affixPat,
02084                          UBool currencyParsing,
02085                          int8_t type,
02086                          UChar* currency) const;
02087 
02088     static int32_t compareSimpleAffix(const UnicodeString& affix,
02089                                       const UnicodeString& input,
02090                                       int32_t pos,
02091                                       UBool lenient);
02092 
02093     static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos);
02094 
02095     static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
02096 
02097     int32_t compareComplexAffix(const UnicodeString& affixPat,
02098                                 const UnicodeString& input,
02099                                 int32_t pos,
02100                                 int8_t type,
02101                                 UChar* currency) const;
02102 
02103     static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
02104 
02105     static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
02106 
02107     static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
02108                              UnicodeSet *sset, UChar32 schar);
02109 
02110     static UBool matchDecimal(UChar32 symbolChar,
02111                             UBool sawDecimal,  UChar32 sawDecimalChar,
02112                              const UnicodeSet *sset, UChar32 schar);
02113 
02114     static UBool matchGrouping(UChar32 groupingChar,
02115                             UBool sawGrouping, UChar32 sawGroupingChar,
02116                              const UnicodeSet *sset,
02117                              UChar32 decimalChar, const UnicodeSet *decimalSet,
02118                              UChar32 schar);
02119 
02125     inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
02126 
02127     int32_t appendAffix(UnicodeString& buf,
02128                         double number,
02129                         FieldPositionHandler& handler,
02130                         UBool isNegative,
02131                         UBool isPrefix) const;
02132 
02138     void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
02139                             UBool localized) const;
02140 
02141     void appendAffixPattern(UnicodeString& appendTo,
02142                             const UnicodeString* affixPattern,
02143                             const UnicodeString& expAffix, UBool localized) const;
02144 
02145     void expandAffix(const UnicodeString& pattern,
02146                      UnicodeString& affix,
02147                      double number,
02148                      FieldPositionHandler& handler,
02149                      UBool doFormat,
02150                      const UnicodeString* pluralCount) const;
02151 
02152     void expandAffixes(const UnicodeString* pluralCount);
02153 
02154     void addPadding(UnicodeString& appendTo,
02155                     FieldPositionHandler& handler,
02156                     int32_t prefixLen, int32_t suffixLen) const;
02157 
02158     UBool isGroupingPosition(int32_t pos) const;
02159 
02160     void setCurrencyForSymbols();
02161 
02162     // similar to setCurrency without re-compute the affixes for currency.
02163     // If currency changes, the affix pattern for currency is not changed,
02164     // but the affix will be changed. So, affixes need to be
02165     // re-computed in setCurrency(), but not in setCurrencyInternally().
02166     virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
02167 
02168     // set up currency affix patterns for mix parsing.
02169     // The patterns saved here are the affix patterns of default currency
02170     // pattern and the unique affix patterns of the plural currency patterns.
02171     // Those patterns are used by parseForCurrency().
02172     void setupCurrencyAffixPatterns(UErrorCode& status);
02173 
02174     // set up the currency affixes used in currency plural formatting.
02175     // It sets up both fAffixesForCurrency for currency pattern if the current
02176     // pattern contains 3 currency signs,
02177     // and it sets up fPluralAffixesForCurrency for currency plural patterns.
02178     void setupCurrencyAffixes(const UnicodeString& pattern,
02179                               UBool setupForCurrentPattern,
02180                               UBool setupForPluralPattern,
02181                               UErrorCode& status);
02182 
02183     // hashtable operations
02184     Hashtable* initHashForAffixPattern(UErrorCode& status);
02185     Hashtable* initHashForAffix(UErrorCode& status);
02186 
02187     void deleteHashForAffixPattern();
02188     void deleteHashForAffix(Hashtable*& table);
02189 
02190     void copyHashForAffixPattern(const Hashtable* source,
02191                                  Hashtable* target, UErrorCode& status);
02192     void copyHashForAffix(const Hashtable* source,
02193                           Hashtable* target, UErrorCode& status);
02194 
02195     UnicodeString& _format(int64_t number,
02196                            UnicodeString& appendTo,
02197                            FieldPositionHandler& handler,
02198                            UErrorCode &status) const;
02199     UnicodeString& _format(double number,
02200                            UnicodeString& appendTo,
02201                            FieldPositionHandler& handler,
02202                            UErrorCode &status) const;
02203     UnicodeString& _format(const DigitList &number,
02204                            UnicodeString& appendTo,
02205                            FieldPositionHandler& handler,
02206                            UErrorCode &status) const;
02207 
02208     // currency sign count
02209     enum {
02210         fgCurrencySignCountZero,
02211         fgCurrencySignCountInSymbolFormat,
02212         fgCurrencySignCountInISOFormat,
02213         fgCurrencySignCountInPluralFormat
02214     } CurrencySignCount;
02215 
02220     UnicodeString           fPositivePrefix;
02221     UnicodeString           fPositiveSuffix;
02222     UnicodeString           fNegativePrefix;
02223     UnicodeString           fNegativeSuffix;
02224     UnicodeString*          fPosPrefixPattern;
02225     UnicodeString*          fPosSuffixPattern;
02226     UnicodeString*          fNegPrefixPattern;
02227     UnicodeString*          fNegSuffixPattern;
02228 
02234     ChoiceFormat*           fCurrencyChoice;
02235 
02236     DigitList *             fMultiplier;   // NULL for multiplier of one
02237     int32_t                 fGroupingSize;
02238     int32_t                 fGroupingSize2;
02239     UBool                   fDecimalSeparatorAlwaysShown;
02240     DecimalFormatSymbols*   fSymbols;
02241 
02242     UBool                   fUseSignificantDigits;
02243     int32_t                 fMinSignificantDigits;
02244     int32_t                 fMaxSignificantDigits;
02245 
02246     UBool                   fUseExponentialNotation;
02247     int8_t                  fMinExponentDigits;
02248     UBool                   fExponentSignAlwaysShown;
02249 
02250     EnumSet<UNumberFormatAttribute,
02251             UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, 
02252             UNUM_LIMIT_BOOLEAN_ATTRIBUTE>  
02253                             fBoolFlags;
02254 
02255     DigitList*              fRoundingIncrement;  // NULL if no rounding increment specified.
02256     ERoundingMode           fRoundingMode;
02257 
02258     UChar32                 fPad;
02259     int32_t                 fFormatWidth;
02260     EPadPosition            fPadPosition;
02261 
02262     /*
02263      * Following are used for currency format
02264      */
02265     // pattern used in this formatter
02266     UnicodeString fFormatPattern;
02267     // style is only valid when decimal formatter is constructed by
02268     // DecimalFormat(pattern, decimalFormatSymbol, style)
02269     int fStyle;
02270     /*
02271      * Represents whether this is a currency format, and which
02272      * currency format style.
02273      * 0: not currency format type;
02274      * 1: currency style -- symbol name, such as "$" for US dollar.
02275      * 2: currency style -- ISO name, such as USD for US dollar.
02276      * 3: currency style -- plural long name, such as "US Dollar" for
02277      *                      "1.00 US Dollar", or "US Dollars" for
02278      *                      "3.00 US Dollars".
02279      */
02280     int fCurrencySignCount;
02281 
02282 
02283     /* For currency parsing purose,
02284      * Need to remember all prefix patterns and suffix patterns of
02285      * every currency format pattern,
02286      * including the pattern of default currecny style
02287      * and plural currency style. And the patterns are set through applyPattern.
02288      */
02289     // TODO: innerclass?
02290     /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
02291     struct AffixPatternsForCurrency : public UMemory {
02292         // negative prefix pattern
02293         UnicodeString negPrefixPatternForCurrency;
02294         // negative suffix pattern
02295         UnicodeString negSuffixPatternForCurrency;
02296         // positive prefix pattern
02297         UnicodeString posPrefixPatternForCurrency;
02298         // positive suffix pattern
02299         UnicodeString posSuffixPatternForCurrency;
02300         int8_t patternType;
02301 
02302         AffixPatternsForCurrency(const UnicodeString& negPrefix,
02303                                  const UnicodeString& negSuffix,
02304                                  const UnicodeString& posPrefix,
02305                                  const UnicodeString& posSuffix,
02306                                  int8_t type) {
02307             negPrefixPatternForCurrency = negPrefix;
02308             negSuffixPatternForCurrency = negSuffix;
02309             posPrefixPatternForCurrency = posPrefix;
02310             posSuffixPatternForCurrency = posSuffix;
02311             patternType = type;
02312         }
02313     };
02314     */
02315 
02316     /* affix for currency formatting when the currency sign in the pattern
02317      * equals to 3, such as the pattern contains 3 currency sign or
02318      * the formatter style is currency plural format style.
02319      */
02320     /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
02321     struct AffixesForCurrency : public UMemory {
02322         // negative prefix
02323         UnicodeString negPrefixForCurrency;
02324         // negative suffix
02325         UnicodeString negSuffixForCurrency;
02326         // positive prefix
02327         UnicodeString posPrefixForCurrency;
02328         // positive suffix
02329         UnicodeString posSuffixForCurrency;
02330 
02331         int32_t formatWidth;
02332 
02333         AffixesForCurrency(const UnicodeString& negPrefix,
02334                            const UnicodeString& negSuffix,
02335                            const UnicodeString& posPrefix,
02336                            const UnicodeString& posSuffix) {
02337             negPrefixForCurrency = negPrefix;
02338             negSuffixForCurrency = negSuffix;
02339             posPrefixForCurrency = posPrefix;
02340             posSuffixForCurrency = posSuffix;
02341         }
02342     };
02343     */
02344 
02345     // Affix pattern set for currency.
02346     // It is a set of AffixPatternsForCurrency,
02347     // each element of the set saves the negative prefix pattern,
02348     // negative suffix pattern, positive prefix pattern,
02349     // and positive suffix  pattern of a pattern.
02350     // It is used for currency mixed style parsing.
02351     // It is actually is a set.
02352     // The set contains the default currency pattern from the locale,
02353     // and the currency plural patterns.
02354     // Since it is a set, it does not contain duplicated items.
02355     // For example, if 2 currency plural patterns are the same, only one pattern
02356     // is included in the set. When parsing, we do not check whether the plural
02357     // count match or not.
02358     Hashtable* fAffixPatternsForCurrency;
02359 
02360     // Following 2 are affixes for currency.
02361     // It is a hash map from plural count to AffixesForCurrency.
02362     // AffixesForCurrency saves the negative prefix,
02363     // negative suffix, positive prefix, and positive suffix of a pattern.
02364     // It is used during currency formatting only when the currency sign count
02365     // is 3. In which case, the affixes are getting from here, not
02366     // from the fNegativePrefix etc.
02367     Hashtable* fAffixesForCurrency;  // for current pattern
02368     Hashtable* fPluralAffixesForCurrency;  // for plural pattern
02369 
02370     // Information needed for DecimalFormat to format/parse currency plural.
02371     CurrencyPluralInfo* fCurrencyPluralInfo;
02372 
02373 #if UCONFIG_HAVE_PARSEALLINPUT
02374     UNumberFormatAttributeValue fParseAllInput;
02375 #endif
02376 
02377 
02378 protected:
02379 
02388     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
02389 
02393     static const int32_t  kDoubleIntegerDigits;
02397     static const int32_t  kDoubleFractionDigits;
02398 
02409     static const int32_t  kMaxScientificIntegerDigits;
02410 
02411 #if UCONFIG_FORMAT_FASTPATHS_49
02412  private:
02417     uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
02418 
02419 
02423     void handleChanged();
02424 #endif
02425 };
02426 
02427 inline UnicodeString&
02428 DecimalFormat::format(const Formattable& obj,
02429                       UnicodeString& appendTo,
02430                       UErrorCode& status) const {
02431     // Don't use Format:: - use immediate base class only,
02432     // in case immediate base modifies behavior later.
02433     return NumberFormat::format(obj, appendTo, status);
02434 }
02435 
02436 inline UnicodeString&
02437 DecimalFormat::format(double number,
02438                       UnicodeString& appendTo) const {
02439     FieldPosition pos(0);
02440     return format(number, appendTo, pos);
02441 }
02442 
02443 inline UnicodeString&
02444 DecimalFormat::format(int32_t number,
02445                       UnicodeString& appendTo) const {
02446     FieldPosition pos(0);
02447     return format((int64_t)number, appendTo, pos);
02448 }
02449 
02450 #ifndef U_HIDE_INTERNAL_API
02451 inline const UnicodeString &
02452 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
02453     return fSymbols->getConstSymbol(symbol);
02454 }
02455 
02456 #endif
02457 
02458 U_NAMESPACE_END
02459 
02460 #endif /* #if !UCONFIG_NO_FORMATTING */
02461 
02462 #endif // _DECIMFMT
02463 //eof

Generated on 25 Nov 2014 for ICU 50.1.2 by  doxygen 1.4.7