ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
decimfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File DECIMFMT.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 03/20/97 clhuang Updated per C++ implementation.
14 * 04/03/97 aliu Rewrote parsing and formatting completely, and
15 * cleaned up and debugged. Actually works now.
16 * 04/17/97 aliu Changed DigitCount to int per code review.
17 * 07/10/97 helena Made ParsePosition a class and get rid of the function
18 * hiding problems.
19 * 09/09/97 aliu Ported over support for exponential formats.
20 * 07/20/98 stephen Changed documentation
21 * 01/30/13 emmons Added Scaling methods
22 ********************************************************************************
23 */
24 
25 #ifndef DECIMFMT_H
26 #define DECIMFMT_H
27 
28 #include "unicode/utypes.h"
34 #if !UCONFIG_NO_FORMATTING
35 
36 #include "unicode/dcfmtsym.h"
37 #include "unicode/numfmt.h"
38 #include "unicode/locid.h"
39 #include "unicode/fpositer.h"
40 #include "unicode/stringpiece.h"
41 #include "unicode/curramt.h"
42 #include "unicode/enumset.h"
43 
48 #if UCONFIG_FORMAT_FASTPATHS_49
49 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
50 #endif
51 
53 
54 class DigitList;
55 class ChoiceFormat;
56 class CurrencyPluralInfo;
57 class Hashtable;
58 class UnicodeSet;
59 class FieldPositionHandler;
60 class DecimalFormatStaticSets;
61 class FixedDecimal;
62 
63 // explicit template instantiation. see digitlst.h
64 #if defined (_MSC_VER)
65 template class U_I18N_API EnumSet<UNumberFormatAttribute,
68 #endif
69 
664 public:
674  kRoundHalfEven,
676  kRoundHalfDown,
678  kRoundHalfUp,
684  kRoundUnnecessary
685  };
686 
692  kPadBeforePrefix,
693  kPadAfterPrefix,
694  kPadBeforeSuffix,
695  kPadAfterSuffix
696  };
697 
711  DecimalFormat(UErrorCode& status);
712 
727  DecimalFormat(const UnicodeString& pattern,
728  UErrorCode& status);
729 
748  DecimalFormat( const UnicodeString& pattern,
749  DecimalFormatSymbols* symbolsToAdopt,
750  UErrorCode& status);
751 
752 #ifndef U_HIDE_INTERNAL_API
753 
765  DecimalFormat( const UnicodeString& pattern,
766  DecimalFormatSymbols* symbolsToAdopt,
767  UNumberFormatStyle style,
768  UErrorCode& status);
769 
770 #if UCONFIG_HAVE_PARSEALLINPUT
771 
774  void setParseAllInput(UNumberFormatAttributeValue value);
775 #endif
776 
777 #endif /* U_HIDE_INTERNAL_API */
778 
779 
790  virtual DecimalFormat& setAttribute( UNumberFormatAttribute attr,
791  int32_t newvalue,
792  UErrorCode &status);
793 
803  virtual int32_t getAttribute( UNumberFormatAttribute attr,
804  UErrorCode &status) const;
805 
806 
813  virtual void setGroupingUsed(UBool newValue);
814 
822  virtual void setParseIntegerOnly(UBool value);
823 
824  /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
834  virtual void setContext(UDisplayContext value, UErrorCode& status);
835 
855  DecimalFormat( const UnicodeString& pattern,
856  DecimalFormatSymbols* symbolsToAdopt,
857  UParseError& parseError,
858  UErrorCode& status);
876  DecimalFormat( const UnicodeString& pattern,
877  const DecimalFormatSymbols& symbols,
878  UErrorCode& status);
879 
886  DecimalFormat(const DecimalFormat& source);
887 
895 
900  virtual ~DecimalFormat();
901 
909  virtual Format* clone(void) const;
910 
919  virtual UBool operator==(const Format& other) const;
920 
921 
922  using NumberFormat::format;
923 
935  virtual UnicodeString& format(double number,
936  UnicodeString& appendTo,
937  FieldPosition& pos) const;
938 
939 
952  virtual UnicodeString& format(double number,
953  UnicodeString& appendTo,
954  FieldPosition& pos,
955  UErrorCode &status) const;
956 
970  virtual UnicodeString& format(double number,
971  UnicodeString& appendTo,
972  FieldPositionIterator* posIter,
973  UErrorCode& status) const;
974 
986  virtual UnicodeString& format(int32_t number,
987  UnicodeString& appendTo,
988  FieldPosition& pos) const;
989 
1001  virtual UnicodeString& format(int32_t number,
1002  UnicodeString& appendTo,
1003  FieldPosition& pos,
1004  UErrorCode &status) const;
1005 
1019  virtual UnicodeString& format(int32_t number,
1020  UnicodeString& appendTo,
1021  FieldPositionIterator* posIter,
1022  UErrorCode& status) const;
1023 
1035  virtual UnicodeString& format(int64_t number,
1036  UnicodeString& appendTo,
1037  FieldPosition& pos) const;
1038 
1050  virtual UnicodeString& format(int64_t number,
1051  UnicodeString& appendTo,
1052  FieldPosition& pos,
1053  UErrorCode &status) const;
1054 
1068  virtual UnicodeString& format(int64_t number,
1069  UnicodeString& appendTo,
1070  FieldPositionIterator* posIter,
1071  UErrorCode& status) const;
1072 
1089  virtual UnicodeString& format(const StringPiece &number,
1090  UnicodeString& appendTo,
1091  FieldPositionIterator* posIter,
1092  UErrorCode& status) const;
1093 
1094 
1110  virtual UnicodeString& format(const DigitList &number,
1111  UnicodeString& appendTo,
1112  FieldPositionIterator* posIter,
1113  UErrorCode& status) const;
1114 
1130  virtual UnicodeString& format(const DigitList &number,
1131  UnicodeString& appendTo,
1132  FieldPosition& pos,
1133  UErrorCode& status) const;
1134 
1135  using NumberFormat::parse;
1136 
1156  virtual void parse(const UnicodeString& text,
1157  Formattable& result,
1158  ParsePosition& parsePosition) const;
1159 
1179  virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
1180  ParsePosition& pos) const;
1181 
1189  virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
1190 
1197  virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1198 
1205  virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1206 
1207 
1214  virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
1215 
1222  virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
1223 
1230  virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info);
1231 
1232 
1241  UnicodeString& getPositivePrefix(UnicodeString& result) const;
1242 
1250  virtual void setPositivePrefix(const UnicodeString& newValue);
1251 
1260  UnicodeString& getNegativePrefix(UnicodeString& result) const;
1261 
1269  virtual void setNegativePrefix(const UnicodeString& newValue);
1270 
1279  UnicodeString& getPositiveSuffix(UnicodeString& result) const;
1280 
1288  virtual void setPositiveSuffix(const UnicodeString& newValue);
1289 
1298  UnicodeString& getNegativeSuffix(UnicodeString& result) const;
1299 
1307  virtual void setNegativeSuffix(const UnicodeString& newValue);
1308 
1319  int32_t getMultiplier(void) const;
1320 
1331  virtual void setMultiplier(int32_t newValue);
1332 
1342  virtual double getRoundingIncrement(void) const;
1343 
1355  virtual void setRoundingIncrement(double newValue);
1356 
1365  virtual ERoundingMode getRoundingMode(void) const;
1366 
1375  virtual void setRoundingMode(ERoundingMode roundingMode);
1376 
1388  virtual int32_t getFormatWidth(void) const;
1389 
1404  virtual void setFormatWidth(int32_t width);
1405 
1418  virtual UnicodeString getPadCharacterString() const;
1419 
1434  virtual void setPadCharacter(const UnicodeString &padChar);
1435 
1451  virtual EPadPosition getPadPosition(void) const;
1452 
1469  virtual void setPadPosition(EPadPosition padPos);
1470 
1481  virtual UBool isScientificNotation(void) const;
1482 
1498  virtual void setScientificNotation(UBool useScientific);
1499 
1510  virtual int8_t getMinimumExponentDigits(void) const;
1511 
1524  virtual void setMinimumExponentDigits(int8_t minExpDig);
1525 
1538  virtual UBool isExponentSignAlwaysShown(void) const;
1539 
1553  virtual void setExponentSignAlwaysShown(UBool expSignAlways);
1554 
1566  int32_t getGroupingSize(void) const;
1567 
1579  virtual void setGroupingSize(int32_t newValue);
1580 
1599  int32_t getSecondaryGroupingSize(void) const;
1600 
1612  virtual void setSecondaryGroupingSize(int32_t newValue);
1613 
1622  UBool isDecimalSeparatorAlwaysShown(void) const;
1623 
1632  virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
1633 
1644  virtual UnicodeString& toPattern(UnicodeString& result) const;
1645 
1656  virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
1657 
1687  virtual void applyPattern(const UnicodeString& pattern,
1688  UParseError& parseError,
1689  UErrorCode& status);
1698  virtual void applyPattern(const UnicodeString& pattern,
1699  UErrorCode& status);
1700 
1731  virtual void applyLocalizedPattern(const UnicodeString& pattern,
1732  UParseError& parseError,
1733  UErrorCode& status);
1734 
1744  virtual void applyLocalizedPattern(const UnicodeString& pattern,
1745  UErrorCode& status);
1746 
1747 
1757  virtual void setMaximumIntegerDigits(int32_t newValue);
1758 
1768  virtual void setMinimumIntegerDigits(int32_t newValue);
1769 
1779  virtual void setMaximumFractionDigits(int32_t newValue);
1780 
1790  virtual void setMinimumFractionDigits(int32_t newValue);
1791 
1799  int32_t getMinimumSignificantDigits() const;
1800 
1808  int32_t getMaximumSignificantDigits() const;
1809 
1821  void setMinimumSignificantDigits(int32_t min);
1822 
1834  void setMaximumSignificantDigits(int32_t max);
1835 
1842  UBool areSignificantDigitsUsed() const;
1843 
1851  void setSignificantDigitsUsed(UBool useSignificantDigits);
1852 
1853  public:
1866  virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1867 
1873  virtual void setCurrency(const UChar* theCurrency);
1874 
1880  static const char fgNumberPatterns[];
1881 
1882 #ifndef U_HIDE_INTERNAL_API
1883 
1889  FixedDecimal getFixedDecimal(double number, UErrorCode &status) const;
1890 
1897  FixedDecimal getFixedDecimal(const Formattable &number, UErrorCode &status) const;
1898 
1905  FixedDecimal getFixedDecimal(DigitList &number, UErrorCode &status) const;
1906 #endif /* U_HIDE_INTERNAL_API */
1907 
1908 public:
1909 
1921  static UClassID U_EXPORT2 getStaticClassID(void);
1922 
1934  virtual UClassID getDynamicClassID(void) const;
1935 
1936 private:
1937 
1938  DecimalFormat(); // default constructor not implemented
1939 
1940  int32_t precision() const;
1941 
1946  void init();
1947 
1951  void construct(UErrorCode& status,
1952  UParseError& parseErr,
1953  const UnicodeString* pattern = 0,
1954  DecimalFormatSymbols* symbolsToAdopt = 0
1955  );
1956 
1965  UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
1966 
1977  void applyPattern(const UnicodeString& pattern,
1978  UBool localized,
1979  UParseError& parseError,
1980  UErrorCode& status);
1981 
1982  /*
1983  * similar to applyPattern, but without re-gen affix for currency
1984  */
1985  void applyPatternInternally(const UnicodeString& pluralCount,
1986  const UnicodeString& pattern,
1987  UBool localized,
1988  UParseError& parseError,
1989  UErrorCode& status);
1990 
1991  /*
1992  * only apply pattern without expand affixes
1993  */
1994  void applyPatternWithoutExpandAffix(const UnicodeString& pattern,
1995  UBool localized,
1996  UParseError& parseError,
1997  UErrorCode& status);
1998 
1999 
2000  /*
2001  * expand affixes (after apply patter) and re-compute fFormatWidth
2002  */
2003  void expandAffixAdjustWidth(const UnicodeString* pluralCount);
2004 
2005 
2016  UnicodeString& subformat(UnicodeString& appendTo,
2017  FieldPositionHandler& handler,
2018  DigitList& digits,
2019  UBool isInteger,
2020  UErrorCode &status) const;
2021 
2022 
2023  void parse(const UnicodeString& text,
2024  Formattable& result,
2025  ParsePosition& pos,
2026  UChar* currency) const;
2027 
2028  enum {
2029  fgStatusInfinite,
2030  fgStatusLength // Leave last in list.
2031  } StatusFlags;
2032 
2033  UBool subparse(const UnicodeString& text,
2034  const UnicodeString* negPrefix,
2035  const UnicodeString* negSuffix,
2036  const UnicodeString* posPrefix,
2037  const UnicodeString* posSuffix,
2038  UBool complexCurrencyParsing,
2039  int8_t type,
2040  ParsePosition& parsePosition,
2041  DigitList& digits, UBool* status,
2042  UChar* currency) const;
2043 
2044  // Mixed style parsing for currency.
2045  // It parses against the current currency pattern
2046  // using complex affix comparison
2047  // parses against the currency plural patterns using complex affix comparison,
2048  // and parses against the current pattern using simple affix comparison.
2049  UBool parseForCurrency(const UnicodeString& text,
2050  ParsePosition& parsePosition,
2051  DigitList& digits,
2052  UBool* status,
2053  UChar* currency) const;
2054 
2055  int32_t skipPadding(const UnicodeString& text, int32_t position) const;
2056 
2057  int32_t compareAffix(const UnicodeString& input,
2058  int32_t pos,
2059  UBool isNegative,
2060  UBool isPrefix,
2061  const UnicodeString* affixPat,
2062  UBool complexCurrencyParsing,
2063  int8_t type,
2064  UChar* currency) const;
2065 
2066  static UnicodeString& trimMarksFromAffix(const UnicodeString& affix, UnicodeString& trimmedAffix);
2067 
2068  UBool equalWithSignCompatibility(UChar32 lhs, UChar32 rhs) const;
2069 
2070  int32_t compareSimpleAffix(const UnicodeString& affix,
2071  const UnicodeString& input,
2072  int32_t pos,
2073  UBool lenient) const;
2074 
2075  static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos);
2076 
2077  static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
2078 
2079  static int32_t skipUWhiteSpaceAndMarks(const UnicodeString& text, int32_t pos);
2080 
2081  static int32_t skipBidiMarks(const UnicodeString& text, int32_t pos);
2082 
2083  int32_t compareComplexAffix(const UnicodeString& affixPat,
2084  const UnicodeString& input,
2085  int32_t pos,
2086  int8_t type,
2087  UChar* currency) const;
2088 
2089  static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
2090 
2091  static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
2092 
2093  static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
2094  UnicodeSet *sset, UChar32 schar);
2095 
2096  static UBool matchDecimal(UChar32 symbolChar,
2097  UBool sawDecimal, UChar32 sawDecimalChar,
2098  const UnicodeSet *sset, UChar32 schar);
2099 
2100  static UBool matchGrouping(UChar32 groupingChar,
2101  UBool sawGrouping, UChar32 sawGroupingChar,
2102  const UnicodeSet *sset,
2103  UChar32 decimalChar, const UnicodeSet *decimalSet,
2104  UChar32 schar);
2105 
2111  inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
2112 
2113  int32_t appendAffix(UnicodeString& buf,
2114  double number,
2115  FieldPositionHandler& handler,
2116  UBool isNegative,
2117  UBool isPrefix) const;
2118 
2124  void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
2125  UBool localized) const;
2126 
2127  void appendAffixPattern(UnicodeString& appendTo,
2128  const UnicodeString* affixPattern,
2129  const UnicodeString& expAffix, UBool localized) const;
2130 
2131  void expandAffix(const UnicodeString& pattern,
2132  UnicodeString& affix,
2133  double number,
2134  FieldPositionHandler& handler,
2135  UBool doFormat,
2136  const UnicodeString* pluralCount) const;
2137 
2138  void expandAffixes(const UnicodeString* pluralCount);
2139 
2140  void addPadding(UnicodeString& appendTo,
2141  FieldPositionHandler& handler,
2142  int32_t prefixLen, int32_t suffixLen) const;
2143 
2144  UBool isGroupingPosition(int32_t pos) const;
2145 
2146  void setCurrencyForSymbols();
2147 
2148  // similar to setCurrency without re-compute the affixes for currency.
2149  // If currency changes, the affix pattern for currency is not changed,
2150  // but the affix will be changed. So, affixes need to be
2151  // re-computed in setCurrency(), but not in setCurrencyInternally().
2152  virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
2153 
2154  // set up currency affix patterns for mix parsing.
2155  // The patterns saved here are the affix patterns of default currency
2156  // pattern and the unique affix patterns of the plural currency patterns.
2157  // Those patterns are used by parseForCurrency().
2158  void setupCurrencyAffixPatterns(UErrorCode& status);
2159 
2160  // set up the currency affixes used in currency plural formatting.
2161  // It sets up both fAffixesForCurrency for currency pattern if the current
2162  // pattern contains 3 currency signs,
2163  // and it sets up fPluralAffixesForCurrency for currency plural patterns.
2164  void setupCurrencyAffixes(const UnicodeString& pattern,
2165  UBool setupForCurrentPattern,
2166  UBool setupForPluralPattern,
2167  UErrorCode& status);
2168 
2169  // hashtable operations
2170  Hashtable* initHashForAffixPattern(UErrorCode& status);
2171  Hashtable* initHashForAffix(UErrorCode& status);
2172 
2173  void deleteHashForAffixPattern();
2174  void deleteHashForAffix(Hashtable*& table);
2175 
2176  void copyHashForAffixPattern(const Hashtable* source,
2177  Hashtable* target, UErrorCode& status);
2178  void copyHashForAffix(const Hashtable* source,
2179  Hashtable* target, UErrorCode& status);
2180 
2181  UnicodeString& _format(int64_t number,
2182  UnicodeString& appendTo,
2183  FieldPositionHandler& handler,
2184  UErrorCode &status) const;
2185  UnicodeString& _format(double number,
2186  UnicodeString& appendTo,
2187  FieldPositionHandler& handler,
2188  UErrorCode &status) const;
2189  UnicodeString& _format(const DigitList &number,
2190  UnicodeString& appendTo,
2191  FieldPositionHandler& handler,
2192  UErrorCode &status) const;
2193 
2198  UnicodeString fPositivePrefix;
2199  UnicodeString fPositiveSuffix;
2200  UnicodeString fNegativePrefix;
2201  UnicodeString fNegativeSuffix;
2202  UnicodeString* fPosPrefixPattern;
2203  UnicodeString* fPosSuffixPattern;
2204  UnicodeString* fNegPrefixPattern;
2205  UnicodeString* fNegSuffixPattern;
2206 
2212  ChoiceFormat* fCurrencyChoice;
2213 
2214  DigitList * fMultiplier; // NULL for multiplier of one
2215  int32_t fScale;
2216  int32_t fGroupingSize;
2217  int32_t fGroupingSize2;
2218  UBool fDecimalSeparatorAlwaysShown;
2219  DecimalFormatSymbols* fSymbols;
2220 
2221  UBool fUseSignificantDigits;
2222  int32_t fMinSignificantDigits;
2223  int32_t fMaxSignificantDigits;
2224 
2225  UBool fUseExponentialNotation;
2226  int8_t fMinExponentDigits;
2227  UBool fExponentSignAlwaysShown;
2228 
2232  fBoolFlags;
2233 
2234  DigitList* fRoundingIncrement; // NULL if no rounding increment specified.
2235  ERoundingMode fRoundingMode;
2236 
2237  UChar32 fPad;
2238  int32_t fFormatWidth;
2239  EPadPosition fPadPosition;
2240 
2241  /*
2242  * Following are used for currency format
2243  */
2244  // pattern used in this formatter
2245  UnicodeString fFormatPattern;
2246  // style is only valid when decimal formatter is constructed by
2247  // DecimalFormat(pattern, decimalFormatSymbol, style)
2248  int fStyle;
2249  /*
2250  * Represents whether this is a currency format, and which
2251  * currency format style.
2252  * 0: not currency format type;
2253  * 1: currency style -- symbol name, such as "$" for US dollar.
2254  * 2: currency style -- ISO name, such as USD for US dollar.
2255  * 3: currency style -- plural long name, such as "US Dollar" for
2256  * "1.00 US Dollar", or "US Dollars" for
2257  * "3.00 US Dollars".
2258  */
2259  int fCurrencySignCount;
2260 
2261 
2262  /* For currency parsing purose,
2263  * Need to remember all prefix patterns and suffix patterns of
2264  * every currency format pattern,
2265  * including the pattern of default currecny style
2266  * and plural currency style. And the patterns are set through applyPattern.
2267  */
2268  // TODO: innerclass?
2269  /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2270  struct AffixPatternsForCurrency : public UMemory {
2271  // negative prefix pattern
2272  UnicodeString negPrefixPatternForCurrency;
2273  // negative suffix pattern
2274  UnicodeString negSuffixPatternForCurrency;
2275  // positive prefix pattern
2276  UnicodeString posPrefixPatternForCurrency;
2277  // positive suffix pattern
2278  UnicodeString posSuffixPatternForCurrency;
2279  int8_t patternType;
2280 
2281  AffixPatternsForCurrency(const UnicodeString& negPrefix,
2282  const UnicodeString& negSuffix,
2283  const UnicodeString& posPrefix,
2284  const UnicodeString& posSuffix,
2285  int8_t type) {
2286  negPrefixPatternForCurrency = negPrefix;
2287  negSuffixPatternForCurrency = negSuffix;
2288  posPrefixPatternForCurrency = posPrefix;
2289  posSuffixPatternForCurrency = posSuffix;
2290  patternType = type;
2291  }
2292  };
2293  */
2294 
2295  /* affix for currency formatting when the currency sign in the pattern
2296  * equals to 3, such as the pattern contains 3 currency sign or
2297  * the formatter style is currency plural format style.
2298  */
2299  /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2300  struct AffixesForCurrency : public UMemory {
2301  // negative prefix
2302  UnicodeString negPrefixForCurrency;
2303  // negative suffix
2304  UnicodeString negSuffixForCurrency;
2305  // positive prefix
2306  UnicodeString posPrefixForCurrency;
2307  // positive suffix
2308  UnicodeString posSuffixForCurrency;
2309 
2310  int32_t formatWidth;
2311 
2312  AffixesForCurrency(const UnicodeString& negPrefix,
2313  const UnicodeString& negSuffix,
2314  const UnicodeString& posPrefix,
2315  const UnicodeString& posSuffix) {
2316  negPrefixForCurrency = negPrefix;
2317  negSuffixForCurrency = negSuffix;
2318  posPrefixForCurrency = posPrefix;
2319  posSuffixForCurrency = posSuffix;
2320  }
2321  };
2322  */
2323 
2324  // Affix pattern set for currency.
2325  // It is a set of AffixPatternsForCurrency,
2326  // each element of the set saves the negative prefix pattern,
2327  // negative suffix pattern, positive prefix pattern,
2328  // and positive suffix pattern of a pattern.
2329  // It is used for currency mixed style parsing.
2330  // It is actually is a set.
2331  // The set contains the default currency pattern from the locale,
2332  // and the currency plural patterns.
2333  // Since it is a set, it does not contain duplicated items.
2334  // For example, if 2 currency plural patterns are the same, only one pattern
2335  // is included in the set. When parsing, we do not check whether the plural
2336  // count match or not.
2337  Hashtable* fAffixPatternsForCurrency;
2338 
2339  // Following 2 are affixes for currency.
2340  // It is a hash map from plural count to AffixesForCurrency.
2341  // AffixesForCurrency saves the negative prefix,
2342  // negative suffix, positive prefix, and positive suffix of a pattern.
2343  // It is used during currency formatting only when the currency sign count
2344  // is 3. In which case, the affixes are getting from here, not
2345  // from the fNegativePrefix etc.
2346  Hashtable* fAffixesForCurrency; // for current pattern
2347  Hashtable* fPluralAffixesForCurrency; // for plural pattern
2348 
2349  // Information needed for DecimalFormat to format/parse currency plural.
2350  CurrencyPluralInfo* fCurrencyPluralInfo;
2351 
2352 #if UCONFIG_HAVE_PARSEALLINPUT
2353  UNumberFormatAttributeValue fParseAllInput;
2354 #endif
2355 
2356  // Decimal Format Static Sets singleton.
2357  const DecimalFormatStaticSets *fStaticSets;
2358 
2359 
2360 protected:
2361 
2362 #ifndef U_HIDE_INTERNAL_API
2363 
2367  DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& isNegative, UErrorCode& status) const;
2368 #endif /* U_HIDE_INTERNAL_API */
2369 
2378  virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
2379 
2383  static const int32_t kDoubleIntegerDigits;
2387  static const int32_t kDoubleFractionDigits;
2388 
2399  static const int32_t kMaxScientificIntegerDigits;
2400 
2401 #if UCONFIG_FORMAT_FASTPATHS_49
2402  private:
2407  uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
2408 
2409 
2413  void handleChanged();
2414 #endif
2415 };
2416 
2417 inline const UnicodeString &
2418 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
2419  return fSymbols->getConstSymbol(symbol);
2420 }
2421 
2423 
2424 #endif /* #if !UCONFIG_NO_FORMATTING */
2425 
2426 #endif // _DECIMFMT
2427 //eof
Base class for all formats.
Definition: format.h:94
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.
Definition: decimfmt.h:663
enum bitset for boolean fields.
Definition: enumset.h:31
Abstract base class for all number formats.
Definition: numfmt.h:172
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
C++ API: FieldPosition Iterator.
UDisplayContext
Display context settings.
static const int32_t kMaxScientificIntegerDigits
When someone turns on scientific mode, we assume that more than this number of digits is due to flipp...
Definition: decimfmt.h:2399
virtual void setMinimumIntegerDigits(int32_t newValue)
Sets the minimum number of digits allowed in the integer portion of a number.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
virtual Format * clone() const =0
Clone this object polymorphically.
Limit of boolean attributes.
Definition: unum.h:927
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:90
virtual void setMinimumFractionDigits(int32_t newValue)
Sets the minimum number of digits allowed in the fraction portion of a number.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
C++ API: StringPiece: Read-only byte string wrapper class.
C++ API: Currency Amount Object.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
virtual void getEffectiveCurrency(UChar *result, UErrorCode &ec) const
Returns the currency in effect for this formatter.
UNumberFormatStyle
The possible number format styles.
Definition: unum.h:138
virtual void setCurrency(const UChar *theCurrency, UErrorCode &ec)
Sets the currency used to display currency amounts.
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:53
virtual void setGroupingUsed(UBool newValue)
Set whether or not grouping will be used in this format.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:298
virtual void setParseIntegerOnly(UBool value)
Sets whether or not numbers should be parsed as integers only.
virtual CurrencyAmount * parseCurrency(const UnicodeString &text, ParsePosition &pos) const
Parses text from the given string as a currency amount.
EPadPosition
Pad position.
Definition: decimfmt.h:691
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:276
One below the first bitfield-boolean item.
Definition: unum.h:908
ERoundingMode
Rounding mode.
Definition: decimfmt.h:669
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
virtual void setMaximumIntegerDigits(int32_t newValue)
Sets the maximum number of digits allowed in the integer portion of a number.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
Round away from zero.
Definition: decimfmt.h:673
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
static UClassID getStaticClassID(void)
Return the class ID for this class.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
Round towards negative infinity.
Definition: decimfmt.h:671
C++ API: Symbols for formatting numbers.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
C++ API: Locale ID object.
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:171
Round towards zero.
Definition: decimfmt.h:672
This class represents the information needed by DecimalFormat to format currency plural, such as "3.00 US dollars" or "1.00 US dollar".
Definition: currpinf.h:44
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:245
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
C++: internal template EnumSet<>
C++ API: Abstract base class for all number formats.
UNumberFormatAttribute
The possible UNumberFormat numeric attributes.
Definition: unum.h:834
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
Round towards positive infinity.
Definition: decimfmt.h:670
virtual void setMaximumFractionDigits(int32_t newValue)
Sets the maximum number of digits allowed in the fraction portion of a number.
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
static const int32_t kDoubleIntegerDigits
number of integer digits
Definition: decimfmt.h:2383
A currency together with a numeric amount, such as 200 USD.
Definition: curramt.h:35
static const int32_t kDoubleFractionDigits
number of fraction digits
Definition: decimfmt.h:2387
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200