2 *******************************************************************************
3 * Copyright (C) 2009-2015, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
10 #include "unicode/utypes.h"
14 * \brief C++ API: Currency Plural Information used by Decimal Format
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/unistr.h"
28 * This class represents the information needed by
29 * DecimalFormat to format currency plural,
30 * such as "3.00 US dollars" or "1.00 US dollar".
31 * DecimalFormat creates for itself an instance of
32 * CurrencyPluralInfo from its locale data.
33 * If you need to change any of these symbols, you can get the
34 * CurrencyPluralInfo object from your
35 * DecimalFormat and modify it.
37 * Following are the information needed for currency plural format and parse:
39 * plural rule of the locale,
40 * currency plural pattern of the locale.
44 class U_I18N_API CurrencyPluralInfo
: public UObject
{
48 * Create a CurrencyPluralInfo object for the default locale.
49 * @param status output param set to success/failure code on exit
52 CurrencyPluralInfo(UErrorCode
& status
);
55 * Create a CurrencyPluralInfo object for the given locale.
56 * @param locale the locale
57 * @param status output param set to success/failure code on exit
60 CurrencyPluralInfo(const Locale
& locale
, UErrorCode
& status
);
67 CurrencyPluralInfo(const CurrencyPluralInfo
& info
);
75 CurrencyPluralInfo
& operator=(const CurrencyPluralInfo
& info
);
83 virtual ~CurrencyPluralInfo();
91 UBool
operator==(const CurrencyPluralInfo
& info
) const;
99 UBool
operator!=(const CurrencyPluralInfo
& info
) const;
107 CurrencyPluralInfo
* clone() const;
111 * Gets plural rules of this locale, used for currency plural format
113 * @return plural rule
116 const PluralRules
* getPluralRules() const;
119 * Given a plural count, gets currency plural pattern of this locale,
120 * used for currency plural format
122 * @param pluralCount currency plural count
123 * @param result output param to receive the pattern
124 * @return a currency plural pattern based on plural count
127 UnicodeString
& getCurrencyPluralPattern(const UnicodeString
& pluralCount
,
128 UnicodeString
& result
) const;
136 const Locale
& getLocale() const;
140 * The plural rule is set when CurrencyPluralInfo
141 * instance is created.
142 * You can call this method to reset plural rules only if you want
143 * to modify the default plural rule of the locale.
145 * @param ruleDescription new plural rule description
146 * @param status output param set to success/failure code on exit
149 void setPluralRules(const UnicodeString
& ruleDescription
,
153 * Set currency plural pattern.
154 * The currency plural pattern is set when CurrencyPluralInfo
155 * instance is created.
156 * You can call this method to reset currency plural pattern only if
157 * you want to modify the default currency plural pattern of the locale.
159 * @param pluralCount the plural count for which the currency pattern will
161 * @param pattern the new currency plural pattern
162 * @param status output param set to success/failure code on exit
165 void setCurrencyPluralPattern(const UnicodeString
& pluralCount
,
166 const UnicodeString
& pattern
,
172 * @param loc the new locale to set
173 * @param status output param set to success/failure code on exit
176 void setLocale(const Locale
& loc
, UErrorCode
& status
);
179 * ICU "poor man's RTTI", returns a UClassID for the actual class.
183 virtual UClassID
getDynamicClassID() const;
186 * ICU "poor man's RTTI", returns a UClassID for this class.
190 static UClassID U_EXPORT2
getStaticClassID();
193 friend class DecimalFormat
;
194 friend class DecimalFormatImpl
;
196 void initialize(const Locale
& loc
, UErrorCode
& status
);
198 void setupCurrencyPluralPattern(const Locale
& loc
, UErrorCode
& status
);
203 * @param hTable hash table to be deleted
205 void deleteHash(Hashtable
* hTable
);
209 * initialize hash table
211 * @param status output param set to success/failure code on exit
212 * @return hash table initialized
214 Hashtable
* initHash(UErrorCode
& status
);
221 * @param source the source to copy from
222 * @param target the target to copy to
223 * @param status error code
225 void copyHash(const Hashtable
* source
, Hashtable
* target
, UErrorCode
& status
);
227 //-------------------- private data member ---------------------
228 // map from plural count to currency plural pattern, for example
229 // a plural pattern defined in "CurrencyUnitPatterns" is
230 // "one{{0} {1}}", in which "one" is a plural count
231 // and "{0} {1}" is a currency plural pattern".
232 // The currency plural pattern saved in this mapping is the pattern
233 // defined in "CurrencyUnitPattern" by replacing
234 // {0} with the number format pattern,
235 // and {1} with 3 currency sign.
236 Hashtable
* fPluralCountToCurrencyUnitPattern
;
239 * The plural rule is used to format currency plural name,
240 * for example: "3.00 US Dollars".
241 * If there are 3 currency signs in the currency patttern,
242 * the 3 currency signs will be replaced by currency plural name.
244 PluralRules
* fPluralRules
;
252 CurrencyPluralInfo::operator!=(const CurrencyPluralInfo
& info
) const { return !operator==(info
); }
256 #endif /* #if !UCONFIG_NO_FORMATTING */