1 // Copyright (C) 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"
30 * This class represents the information needed by
31 * DecimalFormat to format currency plural,
32 * such as "3.00 US dollars" or "1.00 US dollar".
33 * DecimalFormat creates for itself an instance of
34 * CurrencyPluralInfo from its locale data.
35 * If you need to change any of these symbols, you can get the
36 * CurrencyPluralInfo object from your
37 * DecimalFormat and modify it.
39 * Following are the information needed for currency plural format and parse:
41 * plural rule of the locale,
42 * currency plural pattern of the locale.
46 class U_I18N_API CurrencyPluralInfo : public UObject {
50 * Create a CurrencyPluralInfo object for the default locale.
51 * @param status output param set to success/failure code on exit
54 CurrencyPluralInfo(UErrorCode& status);
57 * Create a CurrencyPluralInfo object for the given locale.
58 * @param locale the locale
59 * @param status output param set to success/failure code on exit
62 CurrencyPluralInfo(const Locale& locale, UErrorCode& status);
69 CurrencyPluralInfo(const CurrencyPluralInfo& info);
77 CurrencyPluralInfo& operator=(const CurrencyPluralInfo& info);
85 virtual ~CurrencyPluralInfo();
93 UBool operator==(const CurrencyPluralInfo& info) const;
101 UBool operator!=(const CurrencyPluralInfo& info) const;
109 CurrencyPluralInfo* clone() const;
113 * Gets plural rules of this locale, used for currency plural format
115 * @return plural rule
118 const PluralRules* getPluralRules() const;
121 * Given a plural count, gets currency plural pattern of this locale,
122 * used for currency plural format
124 * @param pluralCount currency plural count
125 * @param result output param to receive the pattern
126 * @return a currency plural pattern based on plural count
129 UnicodeString& getCurrencyPluralPattern(const UnicodeString& pluralCount,
130 UnicodeString& result) const;
138 const Locale& getLocale() const;
142 * The plural rule is set when CurrencyPluralInfo
143 * instance is created.
144 * You can call this method to reset plural rules only if you want
145 * to modify the default plural rule of the locale.
147 * @param ruleDescription new plural rule description
148 * @param status output param set to success/failure code on exit
151 void setPluralRules(const UnicodeString& ruleDescription,
155 * Set currency plural pattern.
156 * The currency plural pattern is set when CurrencyPluralInfo
157 * instance is created.
158 * You can call this method to reset currency plural pattern only if
159 * you want to modify the default currency plural pattern of the locale.
161 * @param pluralCount the plural count for which the currency pattern will
163 * @param pattern the new currency plural pattern
164 * @param status output param set to success/failure code on exit
167 void setCurrencyPluralPattern(const UnicodeString& pluralCount,
168 const UnicodeString& pattern,
174 * @param loc the new locale to set
175 * @param status output param set to success/failure code on exit
178 void setLocale(const Locale& loc, UErrorCode& status);
181 * ICU "poor man's RTTI", returns a UClassID for the actual class.
185 virtual UClassID getDynamicClassID() const;
188 * ICU "poor man's RTTI", returns a UClassID for this class.
192 static UClassID U_EXPORT2 getStaticClassID();
195 friend class DecimalFormat;
196 friend class DecimalFormatImpl;
198 void initialize(const Locale& loc, UErrorCode& status);
200 void setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status);
205 * @param hTable hash table to be deleted
207 void deleteHash(Hashtable* hTable);
211 * initialize hash table
213 * @param status output param set to success/failure code on exit
214 * @return hash table initialized
216 Hashtable* initHash(UErrorCode& status);
223 * @param source the source to copy from
224 * @param target the target to copy to
225 * @param status error code
227 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
229 //-------------------- private data member ---------------------
230 // map from plural count to currency plural pattern, for example
231 // a plural pattern defined in "CurrencyUnitPatterns" is
232 // "one{{0} {1}}", in which "one" is a plural count
233 // and "{0} {1}" is a currency plural pattern".
234 // The currency plural pattern saved in this mapping is the pattern
235 // defined in "CurrencyUnitPattern" by replacing
236 // {0} with the number format pattern,
237 // and {1} with 3 currency sign.
238 Hashtable* fPluralCountToCurrencyUnitPattern;
241 * The plural rule is used to format currency plural name,
242 * for example: "3.00 US Dollars".
243 * If there are 3 currency signs in the currency patttern,
244 * the 3 currency signs will be replaced by currency plural name.
246 PluralRules* fPluralRules;
254 CurrencyPluralInfo::operator!=(const CurrencyPluralInfo& info) const { return !operator==(info); }
258 #endif /* #if !UCONFIG_NO_FORMATTING */