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"
14 #if U_SHOW_CPLUSPLUS_API
18 * \brief C++ API: Currency Plural Information used by Decimal Format
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/unistr.h"
32 * This class represents the information needed by
33 * DecimalFormat to format currency plural,
34 * such as "3.00 US dollars" or "1.00 US dollar".
35 * DecimalFormat creates for itself an instance of
36 * CurrencyPluralInfo from its locale data.
37 * If you need to change any of these symbols, you can get the
38 * CurrencyPluralInfo object from your
39 * DecimalFormat and modify it.
41 * Following are the information needed for currency plural format and parse:
43 * plural rule of the locale,
44 * currency plural pattern of the locale.
48 class U_I18N_API CurrencyPluralInfo
: public UObject
{
52 * Create a CurrencyPluralInfo object for the default locale.
53 * @param status output param set to success/failure code on exit
56 CurrencyPluralInfo(UErrorCode
& status
);
59 * Create a CurrencyPluralInfo object for the given locale.
60 * @param locale the locale
61 * @param status output param set to success/failure code on exit
64 CurrencyPluralInfo(const Locale
& locale
, UErrorCode
& status
);
71 CurrencyPluralInfo(const CurrencyPluralInfo
& info
);
79 CurrencyPluralInfo
& operator=(const CurrencyPluralInfo
& info
);
87 virtual ~CurrencyPluralInfo();
95 UBool
operator==(const CurrencyPluralInfo
& info
) const;
103 UBool
operator!=(const CurrencyPluralInfo
& info
) const;
111 CurrencyPluralInfo
* clone() const;
115 * Gets plural rules of this locale, used for currency plural format
117 * @return plural rule
120 const PluralRules
* getPluralRules() const;
123 * Given a plural count, gets currency plural pattern of this locale,
124 * used for currency plural format
126 * @param pluralCount currency plural count
127 * @param result output param to receive the pattern
128 * @return a currency plural pattern based on plural count
131 UnicodeString
& getCurrencyPluralPattern(const UnicodeString
& pluralCount
,
132 UnicodeString
& result
) const;
140 const Locale
& getLocale() const;
144 * The plural rule is set when CurrencyPluralInfo
145 * instance is created.
146 * You can call this method to reset plural rules only if you want
147 * to modify the default plural rule of the locale.
149 * @param ruleDescription new plural rule description
150 * @param status output param set to success/failure code on exit
153 void setPluralRules(const UnicodeString
& ruleDescription
,
157 * Set currency plural pattern.
158 * The currency plural pattern is set when CurrencyPluralInfo
159 * instance is created.
160 * You can call this method to reset currency plural pattern only if
161 * you want to modify the default currency plural pattern of the locale.
163 * @param pluralCount the plural count for which the currency pattern will
165 * @param pattern the new currency plural pattern
166 * @param status output param set to success/failure code on exit
169 void setCurrencyPluralPattern(const UnicodeString
& pluralCount
,
170 const UnicodeString
& pattern
,
176 * @param loc the new locale to set
177 * @param status output param set to success/failure code on exit
180 void setLocale(const Locale
& loc
, UErrorCode
& status
);
183 * ICU "poor man's RTTI", returns a UClassID for the actual class.
187 virtual UClassID
getDynamicClassID() const;
190 * ICU "poor man's RTTI", returns a UClassID for this class.
194 static UClassID U_EXPORT2
getStaticClassID();
197 friend class DecimalFormat
;
198 friend class DecimalFormatImpl
;
200 void initialize(const Locale
& loc
, UErrorCode
& status
);
202 void setupCurrencyPluralPattern(const Locale
& loc
, UErrorCode
& status
);
207 * @param hTable hash table to be deleted
209 void deleteHash(Hashtable
* hTable
);
213 * initialize hash table
215 * @param status output param set to success/failure code on exit
216 * @return hash table initialized
218 Hashtable
* initHash(UErrorCode
& status
);
225 * @param source the source to copy from
226 * @param target the target to copy to
227 * @param status error code
229 void copyHash(const Hashtable
* source
, Hashtable
* target
, UErrorCode
& status
);
231 //-------------------- private data member ---------------------
232 // map from plural count to currency plural pattern, for example
233 // a plural pattern defined in "CurrencyUnitPatterns" is
234 // "one{{0} {1}}", in which "one" is a plural count
235 // and "{0} {1}" is a currency plural pattern".
236 // The currency plural pattern saved in this mapping is the pattern
237 // defined in "CurrencyUnitPattern" by replacing
238 // {0} with the number format pattern,
239 // and {1} with 3 currency sign.
240 Hashtable
* fPluralCountToCurrencyUnitPattern
;
243 * The plural rule is used to format currency plural name,
244 * for example: "3.00 US Dollars".
245 * If there are 3 currency signs in the currency pattern,
246 * the 3 currency signs will be replaced by currency plural name.
248 PluralRules
* fPluralRules
;
255 * An internal status variable used to indicate that the object is in an 'invalid' state.
256 * Used by copy constructor, the assignment operator and the clone method.
258 UErrorCode fInternalStatus
;
263 CurrencyPluralInfo::operator!=(const CurrencyPluralInfo
& info
) const {
264 return !operator==(info
);
269 #endif /* #if !UCONFIG_NO_FORMATTING */
271 #endif /* U_SHOW_CPLUSPLUS_API */