1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2009-2015, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
12 #include "unicode/utypes.h"
16 * \brief C++ API: Currency Plural Information used by Decimal Format
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/unistr.h"
23 #if U_SHOW_CPLUSPLUS_API
31 * This class represents the information needed by
32 * DecimalFormat to format currency plural,
33 * such as "3.00 US dollars" or "1.00 US dollar".
34 * DecimalFormat creates for itself an instance of
35 * CurrencyPluralInfo from its locale data.
36 * If you need to change any of these symbols, you can get the
37 * CurrencyPluralInfo object from your
38 * DecimalFormat and modify it.
40 * Following are the information needed for currency plural format and parse:
42 * plural rule of the locale,
43 * currency plural pattern of the locale.
47 class U_I18N_API CurrencyPluralInfo
: public UObject
{
51 * Create a CurrencyPluralInfo object for the default locale.
52 * @param status output param set to success/failure code on exit
55 CurrencyPluralInfo(UErrorCode
& status
);
58 * Create a CurrencyPluralInfo object for the given locale.
59 * @param locale the locale
60 * @param status output param set to success/failure code on exit
63 CurrencyPluralInfo(const Locale
& locale
, UErrorCode
& status
);
70 CurrencyPluralInfo(const CurrencyPluralInfo
& info
);
78 CurrencyPluralInfo
& operator=(const CurrencyPluralInfo
& info
);
86 virtual ~CurrencyPluralInfo();
94 UBool
operator==(const CurrencyPluralInfo
& info
) const;
102 UBool
operator!=(const CurrencyPluralInfo
& info
) const;
110 CurrencyPluralInfo
* clone() const;
114 * Gets plural rules of this locale, used for currency plural format
116 * @return plural rule
119 const PluralRules
* getPluralRules() const;
122 * Given a plural count, gets currency plural pattern of this locale,
123 * used for currency plural format
125 * @param pluralCount currency plural count
126 * @param result output param to receive the pattern
127 * @return a currency plural pattern based on plural count
130 UnicodeString
& getCurrencyPluralPattern(const UnicodeString
& pluralCount
,
131 UnicodeString
& result
) const;
139 const Locale
& getLocale() const;
143 * The plural rule is set when CurrencyPluralInfo
144 * instance is created.
145 * You can call this method to reset plural rules only if you want
146 * to modify the default plural rule of the locale.
148 * @param ruleDescription new plural rule description
149 * @param status output param set to success/failure code on exit
152 void setPluralRules(const UnicodeString
& ruleDescription
,
156 * Set currency plural pattern.
157 * The currency plural pattern is set when CurrencyPluralInfo
158 * instance is created.
159 * You can call this method to reset currency plural pattern only if
160 * you want to modify the default currency plural pattern of the locale.
162 * @param pluralCount the plural count for which the currency pattern will
164 * @param pattern the new currency plural pattern
165 * @param status output param set to success/failure code on exit
168 void setCurrencyPluralPattern(const UnicodeString
& pluralCount
,
169 const UnicodeString
& pattern
,
175 * @param loc the new locale to set
176 * @param status output param set to success/failure code on exit
179 void setLocale(const Locale
& loc
, UErrorCode
& status
);
182 * ICU "poor man's RTTI", returns a UClassID for the actual class.
186 virtual UClassID
getDynamicClassID() const;
189 * ICU "poor man's RTTI", returns a UClassID for this class.
193 static UClassID U_EXPORT2
getStaticClassID();
196 friend class DecimalFormat
;
197 friend class DecimalFormatImpl
;
199 void initialize(const Locale
& loc
, UErrorCode
& status
);
201 void setupCurrencyPluralPattern(const Locale
& loc
, UErrorCode
& status
);
206 * @param hTable hash table to be deleted
208 void deleteHash(Hashtable
* hTable
);
212 * initialize hash table
214 * @param status output param set to success/failure code on exit
215 * @return hash table initialized
217 Hashtable
* initHash(UErrorCode
& status
);
224 * @param source the source to copy from
225 * @param target the target to copy to
226 * @param status error code
228 void copyHash(const Hashtable
* source
, Hashtable
* target
, UErrorCode
& status
);
230 //-------------------- private data member ---------------------
231 // map from plural count to currency plural pattern, for example
232 // a plural pattern defined in "CurrencyUnitPatterns" is
233 // "one{{0} {1}}", in which "one" is a plural count
234 // and "{0} {1}" is a currency plural pattern".
235 // The currency plural pattern saved in this mapping is the pattern
236 // defined in "CurrencyUnitPattern" by replacing
237 // {0} with the number format pattern,
238 // and {1} with 3 currency sign.
239 Hashtable
* fPluralCountToCurrencyUnitPattern
;
242 * The plural rule is used to format currency plural name,
243 * for example: "3.00 US Dollars".
244 * If there are 3 currency signs in the currency patttern,
245 * the 3 currency signs will be replaced by currency plural name.
247 PluralRules
* fPluralRules
;
255 CurrencyPluralInfo::operator!=(const CurrencyPluralInfo
& info
) const { return !operator==(info
); }
258 #endif // U_SHOW_CPLUSPLUS_API
260 #endif /* #if !UCONFIG_NO_FORMATTING */