ICU 54.1 54.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
52 U_NAMESPACE_BEGIN
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,
66 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
67 UNUM_LIMIT_BOOLEAN_ATTRIBUTE>;
68 #endif
69
663 class U_I18N_API DecimalFormat: public NumberFormat {
664 public:
669 enum ERoundingMode {
670 kRoundCeiling,
671 kRoundFloor,
672 kRoundDown,
673 kRoundUp,
674 kRoundHalfEven,
676 kRoundHalfDown,
678 kRoundHalfUp,
684 kRoundUnnecessary
685 };
686
691 enum EPadPosition {
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
894 DecimalFormat& operator=(const DecimalFormat& rhs);
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
1634 #ifndef U_HIDE_DRAFT_API
1635
1641 UBool isDecimalPatternMatchRequired(void) const;
1642 #endif /* U_HIDE_DRAFT_API */
1643
1653 virtual void setDecimalPatternMatchRequired(UBool newValue);
1654
1655
1666 virtual UnicodeString& toPattern(UnicodeString& result) const;
1667
1678 virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
1679
1709 virtual void applyPattern(const UnicodeString& pattern,
1710 UParseError& parseError,
1711 UErrorCode& status);
1720 virtual void applyPattern(const UnicodeString& pattern,
1721 UErrorCode& status);
1722
1753 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1754 UParseError& parseError,
1755 UErrorCode& status);
1756
1766 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1767 UErrorCode& status);
1768
1769
1779 virtual void setMaximumIntegerDigits(int32_t newValue);
1780
1790 virtual void setMinimumIntegerDigits(int32_t newValue);
1791
1801 virtual void setMaximumFractionDigits(int32_t newValue);
1802
1812 virtual void setMinimumFractionDigits(int32_t newValue);
1813
1821 int32_t getMinimumSignificantDigits() const;
1822
1830 int32_t getMaximumSignificantDigits() const;
1831
1843 void setMinimumSignificantDigits(int32_t min);
1844
1856 void setMaximumSignificantDigits(int32_t max);
1857
1864 UBool areSignificantDigitsUsed() const;
1865
1873 void setSignificantDigitsUsed(UBool useSignificantDigits);
1874
1875 public:
1888 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1889
1895 virtual void setCurrency(const UChar* theCurrency);
1896
1897 #ifndef U_HIDE_DRAFT_API
1898
1905 void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec);
1906
1911 UCurrencyUsage getCurrencyUsage() const;
1912 #endif /* U_HIDE_DRAFT_API */
1913
1914
1915 #ifndef U_HIDE_DEPRECATED_API
1916
1921 static const char fgNumberPatterns[];
1922 #endif /* U_HIDE_DEPRECATED_API */
1923
1924 #ifndef U_HIDE_INTERNAL_API
1925
1931 FixedDecimal getFixedDecimal(double number, UErrorCode &status) const;
1932
1939 FixedDecimal getFixedDecimal(const Formattable &number, UErrorCode &status) const;
1940
1947 FixedDecimal getFixedDecimal(DigitList &number, UErrorCode &status) const;
1948 #endif /* U_HIDE_INTERNAL_API */
1949
1950 public:
1951
1963 static UClassID U_EXPORT2 getStaticClassID(void);
1964
1976 virtual UClassID getDynamicClassID(void) const;
1977
1978 private:
1979
1980 DecimalFormat(); // default constructor not implemented
1981
1982 int32_t precision() const;
1983
1988 void init();
1989
1993 void construct(UErrorCode& status,
1994 UParseError& parseErr,
1995 const UnicodeString* pattern = 0,
1996 DecimalFormatSymbols* symbolsToAdopt = 0
1997 );
1998
2007 UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
2008
2019 void applyPattern(const UnicodeString& pattern,
2020 UBool localized,
2021 UParseError& parseError,
2022 UErrorCode& status);
2023
2024 /*
2025 * similar to applyPattern, but without re-gen affix for currency
2026 */
2027 void applyPatternInternally(const UnicodeString& pluralCount,
2028 const UnicodeString& pattern,
2029 UBool localized,
2030 UParseError& parseError,
2031 UErrorCode& status);
2032
2033 /*
2034 * only apply pattern without expand affixes
2035 */
2036 void applyPatternWithoutExpandAffix(const UnicodeString& pattern,
2037 UBool localized,
2038 UParseError& parseError,
2039 UErrorCode& status);
2040
2041
2042 /*
2043 * expand affixes (after apply patter) and re-compute fFormatWidth
2044 */
2045 void expandAffixAdjustWidth(const UnicodeString* pluralCount);
2046
2047
2058 UnicodeString& subformat(UnicodeString& appendTo,
2059 FieldPositionHandler& handler,
2060 DigitList& digits,
2061 UBool isInteger,
2062 UErrorCode &status) const;
2063
2064
2065 void parse(const UnicodeString& text,
2066 Formattable& result,
2067 ParsePosition& pos,
2068 UChar* currency) const;
2069
2070 enum {
2071 fgStatusInfinite,
2072 fgStatusLength // Leave last in list.
2073 } StatusFlags;
2074
2075 UBool subparse(const UnicodeString& text,
2076 const UnicodeString* negPrefix,
2077 const UnicodeString* negSuffix,
2078 const UnicodeString* posPrefix,
2079 const UnicodeString* posSuffix,
2080 UBool complexCurrencyParsing,
2081 int8_t type,
2082 ParsePosition& parsePosition,
2083 DigitList& digits, UBool* status,
2084 UChar* currency) const;
2085
2086 // Mixed style parsing for currency.
2087 // It parses against the current currency pattern
2088 // using complex affix comparison
2089 // parses against the currency plural patterns using complex affix comparison,
2090 // and parses against the current pattern using simple affix comparison.
2091 UBool parseForCurrency(const UnicodeString& text,
2092 ParsePosition& parsePosition,
2093 DigitList& digits,
2094 UBool* status,
2095 UChar* currency) const;
2096
2097 int32_t skipPadding(const UnicodeString& text, int32_t position) const;
2098
2099 int32_t compareAffix(const UnicodeString& input,
2100 int32_t pos,
2101 UBool isNegative,
2102 UBool isPrefix,
2103 const UnicodeString* affixPat,
2104 UBool complexCurrencyParsing,
2105 int8_t type,
2106 UChar* currency) const;
2107
2108 static UnicodeString& trimMarksFromAffix(const UnicodeString& affix, UnicodeString& trimmedAffix);
2109
2110 UBool equalWithSignCompatibility(UChar32 lhs, UChar32 rhs) const;
2111
2112 int32_t compareSimpleAffix(const UnicodeString& affix,
2113 const UnicodeString& input,
2114 int32_t pos,
2115 UBool lenient) const;
2116
2117 static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos);
2118
2119 static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
2120
2121 static int32_t skipUWhiteSpaceAndMarks(const UnicodeString& text, int32_t pos);
2122
2123 static int32_t skipBidiMarks(const UnicodeString& text, int32_t pos);
2124
2125 int32_t compareComplexAffix(const UnicodeString& affixPat,
2126 const UnicodeString& input,
2127 int32_t pos,
2128 int8_t type,
2129 UChar* currency) const;
2130
2131 static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
2132
2133 static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
2134
2135 static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
2136 UnicodeSet *sset, UChar32 schar);
2137
2138 static UBool matchDecimal(UChar32 symbolChar,
2139 UBool sawDecimal, UChar32 sawDecimalChar,
2140 const UnicodeSet *sset, UChar32 schar);
2141
2142 static UBool matchGrouping(UChar32 groupingChar,
2143 UBool sawGrouping, UChar32 sawGroupingChar,
2144 const UnicodeSet *sset,
2145 UChar32 decimalChar, const UnicodeSet *decimalSet,
2146 UChar32 schar);
2147
2153 inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
2154
2155 int32_t appendAffix(UnicodeString& buf,
2156 double number,
2157 FieldPositionHandler& handler,
2158 UBool isNegative,
2159 UBool isPrefix) const;
2160
2166 void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
2167 UBool localized) const;
2168
2169 void appendAffixPattern(UnicodeString& appendTo,
2170 const UnicodeString* affixPattern,
2171 const UnicodeString& expAffix, UBool localized) const;
2172
2173 void expandAffix(const UnicodeString& pattern,
2174 UnicodeString& affix,
2175 double number,
2176 FieldPositionHandler& handler,
2177 UBool doFormat,
2178 const UnicodeString* pluralCount) const;
2179
2180 void expandAffixes(const UnicodeString* pluralCount);
2181
2182 void addPadding(UnicodeString& appendTo,
2183 FieldPositionHandler& handler,
2184 int32_t prefixLen, int32_t suffixLen) const;
2185
2186 UBool isGroupingPosition(int32_t pos) const;
2187
2188 void setCurrencyForSymbols();
2189
2190 // similar to setCurrency without re-compute the affixes for currency.
2191 // If currency changes, the affix pattern for currency is not changed,
2192 // but the affix will be changed. So, affixes need to be
2193 // re-computed in setCurrency(), but not in setCurrencyInternally().
2194 virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
2195
2196 // set up currency affix patterns for mix parsing.
2197 // The patterns saved here are the affix patterns of default currency
2198 // pattern and the unique affix patterns of the plural currency patterns.
2199 // Those patterns are used by parseForCurrency().
2200 void setupCurrencyAffixPatterns(UErrorCode& status);
2201
2202 // set up the currency affixes used in currency plural formatting.
2203 // It sets up both fAffixesForCurrency for currency pattern if the current
2204 // pattern contains 3 currency signs,
2205 // and it sets up fPluralAffixesForCurrency for currency plural patterns.
2206 void setupCurrencyAffixes(const UnicodeString& pattern,
2207 UBool setupForCurrentPattern,
2208 UBool setupForPluralPattern,
2209 UErrorCode& status);
2210
2211 // get the currency rounding with respect to currency usage
2212 double getCurrencyRounding(const UChar* currency,
2213 UErrorCode* ec) const;
2214
2215 // get the currency fraction with respect to currency usage
2216 int getCurrencyFractionDigits(const UChar* currency,
2217 UErrorCode* ec) const;
2218
2219 // hashtable operations
2220 Hashtable* initHashForAffixPattern(UErrorCode& status);
2221 Hashtable* initHashForAffix(UErrorCode& status);
2222
2223 void deleteHashForAffixPattern();
2224 void deleteHashForAffix(Hashtable*& table);
2225
2226 void copyHashForAffixPattern(const Hashtable* source,
2227 Hashtable* target, UErrorCode& status);
2228 void copyHashForAffix(const Hashtable* source,
2229 Hashtable* target, UErrorCode& status);
2230
2231 UnicodeString& _format(int64_t number,
2232 UnicodeString& appendTo,
2233 FieldPositionHandler& handler,
2234 UErrorCode &status) const;
2235 UnicodeString& _format(double number,
2236 UnicodeString& appendTo,
2237 FieldPositionHandler& handler,
2238 UErrorCode &status) const;
2239 UnicodeString& _format(const DigitList &number,
2240 UnicodeString& appendTo,
2241 FieldPositionHandler& handler,
2242 UErrorCode &status) const;
2243
2248 UnicodeString fPositivePrefix;
2249 UnicodeString fPositiveSuffix;
2250 UnicodeString fNegativePrefix;
2251 UnicodeString fNegativeSuffix;
2252 UnicodeString* fPosPrefixPattern;
2253 UnicodeString* fPosSuffixPattern;
2254 UnicodeString* fNegPrefixPattern;
2255 UnicodeString* fNegSuffixPattern;
2256
2262 ChoiceFormat* fCurrencyChoice;
2263
2264 DigitList * fMultiplier; // NULL for multiplier of one
2265 int32_t fScale;
2266 int32_t fGroupingSize;
2267 int32_t fGroupingSize2;
2268 UBool fDecimalSeparatorAlwaysShown;
2269 DecimalFormatSymbols* fSymbols;
2270
2271 UBool fUseSignificantDigits;
2272 int32_t fMinSignificantDigits;
2273 int32_t fMaxSignificantDigits;
2274
2275 UBool fUseExponentialNotation;
2276 int8_t fMinExponentDigits;
2277 UBool fExponentSignAlwaysShown;
2278
2279 EnumSet<UNumberFormatAttribute,
2280 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
2281 UNUM_LIMIT_BOOLEAN_ATTRIBUTE>
2282 fBoolFlags;
2283
2284 DigitList* fRoundingIncrement; // NULL if no rounding increment specified.
2285 ERoundingMode fRoundingMode;
2286
2287 UChar32 fPad;
2288 int32_t fFormatWidth;
2289 EPadPosition fPadPosition;
2290
2291 /*
2292 * Following are used for currency format
2293 */
2294 // pattern used in this formatter
2295 UnicodeString fFormatPattern;
2296 // style is only valid when decimal formatter is constructed by
2297 // DecimalFormat(pattern, decimalFormatSymbol, style)
2298 int fStyle;
2299 /*
2300 * Represents whether this is a currency format, and which
2301 * currency format style.
2302 * 0: not currency format type;
2303 * 1: currency style -- symbol name, such as "$" for US dollar.
2304 * 2: currency style -- ISO name, such as USD for US dollar.
2305 * 3: currency style -- plural long name, such as "US Dollar" for
2306 * "1.00 US Dollar", or "US Dollars" for
2307 * "3.00 US Dollars".
2308 */
2309 int fCurrencySignCount;
2310
2311
2312 /* For currency parsing purose,
2313 * Need to remember all prefix patterns and suffix patterns of
2314 * every currency format pattern,
2315 * including the pattern of default currecny style
2316 * and plural currency style. And the patterns are set through applyPattern.
2317 */
2318 // TODO: innerclass?
2319 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2320 struct AffixPatternsForCurrency : public UMemory {
2321 // negative prefix pattern
2322 UnicodeString negPrefixPatternForCurrency;
2323 // negative suffix pattern
2324 UnicodeString negSuffixPatternForCurrency;
2325 // positive prefix pattern
2326 UnicodeString posPrefixPatternForCurrency;
2327 // positive suffix pattern
2328 UnicodeString posSuffixPatternForCurrency;
2329 int8_t patternType;
2330
2331 AffixPatternsForCurrency(const UnicodeString& negPrefix,
2332 const UnicodeString& negSuffix,
2333 const UnicodeString& posPrefix,
2334 const UnicodeString& posSuffix,
2335 int8_t type) {
2336 negPrefixPatternForCurrency = negPrefix;
2337 negSuffixPatternForCurrency = negSuffix;
2338 posPrefixPatternForCurrency = posPrefix;
2339 posSuffixPatternForCurrency = posSuffix;
2340 patternType = type;
2341 }
2342 };
2343 */
2344
2345 /* affix for currency formatting when the currency sign in the pattern
2346 * equals to 3, such as the pattern contains 3 currency sign or
2347 * the formatter style is currency plural format style.
2348 */
2349 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2350 struct AffixesForCurrency : public UMemory {
2351 // negative prefix
2352 UnicodeString negPrefixForCurrency;
2353 // negative suffix
2354 UnicodeString negSuffixForCurrency;
2355 // positive prefix
2356 UnicodeString posPrefixForCurrency;
2357 // positive suffix
2358 UnicodeString posSuffixForCurrency;
2359
2360 int32_t formatWidth;
2361
2362 AffixesForCurrency(const UnicodeString& negPrefix,
2363 const UnicodeString& negSuffix,
2364 const UnicodeString& posPrefix,
2365 const UnicodeString& posSuffix) {
2366 negPrefixForCurrency = negPrefix;
2367 negSuffixForCurrency = negSuffix;
2368 posPrefixForCurrency = posPrefix;
2369 posSuffixForCurrency = posSuffix;
2370 }
2371 };
2372 */
2373
2374 // Affix pattern set for currency.
2375 // It is a set of AffixPatternsForCurrency,
2376 // each element of the set saves the negative prefix pattern,
2377 // negative suffix pattern, positive prefix pattern,
2378 // and positive suffix pattern of a pattern.
2379 // It is used for currency mixed style parsing.
2380 // It is actually is a set.
2381 // The set contains the default currency pattern from the locale,
2382 // and the currency plural patterns.
2383 // Since it is a set, it does not contain duplicated items.
2384 // For example, if 2 currency plural patterns are the same, only one pattern
2385 // is included in the set. When parsing, we do not check whether the plural
2386 // count match or not.
2387 Hashtable* fAffixPatternsForCurrency;
2388
2389 // Following 2 are affixes for currency.
2390 // It is a hash map from plural count to AffixesForCurrency.
2391 // AffixesForCurrency saves the negative prefix,
2392 // negative suffix, positive prefix, and positive suffix of a pattern.
2393 // It is used during currency formatting only when the currency sign count
2394 // is 3. In which case, the affixes are getting from here, not
2395 // from the fNegativePrefix etc.
2396 Hashtable* fAffixesForCurrency; // for current pattern
2397 Hashtable* fPluralAffixesForCurrency; // for plural pattern
2398
2399 // Information needed for DecimalFormat to format/parse currency plural.
2400 CurrencyPluralInfo* fCurrencyPluralInfo;
2401
2402 #if UCONFIG_HAVE_PARSEALLINPUT
2403 UNumberFormatAttributeValue fParseAllInput;
2404 #endif
2405
2406 // Decimal Format Static Sets singleton.
2407 const DecimalFormatStaticSets *fStaticSets;
2408
2409 // Currency Usage(STANDARD vs CASH)
2410 UCurrencyUsage fCurrencyUsage;
2411
2412 protected:
2413
2414 #ifndef U_HIDE_INTERNAL_API
2415
2419 DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& isNegative, UErrorCode& status) const;
2420 #endif /* U_HIDE_INTERNAL_API */
2421
2430 virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
2431
2435 static const int32_t kDoubleIntegerDigits;
2439 static const int32_t kDoubleFractionDigits;
2440
2451 static const int32_t kMaxScientificIntegerDigits;
2452
2453 #if UCONFIG_FORMAT_FASTPATHS_49
2454 private:
2459 uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
2460
2461
2465 void handleChanged();
2466 #endif
2467 };
2468
2469 inline const UnicodeString &
2470 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
2471 return fSymbols->getConstSymbol(symbol);
2472 }
2473
2474 U_NAMESPACE_END
2475
2476 #endif /* #if !UCONFIG_NO_FORMATTING */
2477
2478 #endif // _DECIMFMT
2479 //eof