1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (c) 2002-2016, International Business Machines
6 * Corporation and others.  All Rights Reserved.
7 **********************************************************************
8 */
9 #ifndef _UCURR_H_
10 #define _UCURR_H_
11 
12 #include "unicode/utypes.h"
13 #include "unicode/uenum.h"
14 
15 /**
16  * \file
17  * \brief C API: Encapsulates information about a currency.
18  *
19  * The ucurr API encapsulates information about a currency, as defined by
20  * ISO 4217.  A currency is represented by a 3-character string
21  * containing its ISO 4217 code.  This API can return various data
22  * necessary the proper display of a currency:
23  *
24  * <ul><li>A display symbol, for a specific locale
25  * <li>The number of fraction digits to display
26  * <li>A rounding increment
27  * </ul>
28  *
29  * The <tt>DecimalFormat</tt> class uses these data to display
30  * currencies.
31  * @author Alan Liu
32  * @since ICU 2.2
33  */
34 
35 #if !UCONFIG_NO_FORMATTING
36 
37 /**
38  * Currency Usage used for Decimal Format
39  * @stable ICU 54
40  */
41 enum UCurrencyUsage {
42     /**
43      * a setting to specify currency usage which determines currency digit
44      * and rounding for standard usage, for example: "50.00 NT$"
45      * used as DEFAULT value
46      * @stable ICU 54
47      */
48     UCURR_USAGE_STANDARD=0,
49     /**
50      * a setting to specify currency usage which determines currency digit
51      * and rounding for cash usage, for example: "50 NT$"
52      * @stable ICU 54
53      */
54     UCURR_USAGE_CASH=1,
55 #ifndef U_HIDE_DEPRECATED_API
56     /**
57      * One higher than the last enum UCurrencyUsage constant.
58      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
59      */
60     UCURR_USAGE_COUNT=2
61 #endif  // U_HIDE_DEPRECATED_API
62 };
63 /** Currency Usage used for Decimal Format */
64 typedef enum UCurrencyUsage UCurrencyUsage;
65 
66 /**
67  * Finds a currency code for the given locale.
68  * @param locale the locale for which to retrieve a currency code.
69  *               Currency can be specified by the "currency" keyword
70  *               in which case it overrides the default currency code
71  * @param buff   fill in buffer. Can be NULL for preflighting.
72  * @param buffCapacity capacity of the fill in buffer. Can be 0 for
73  *               preflighting. If it is non-zero, the buff parameter
74  *               must not be NULL.
75  * @param ec error code
76  * @return length of the currency string. It should always be 3. If 0,
77  *                currency couldn't be found or the input values are
78  *                invalid.
79  * @stable ICU 2.8
80  */
81 U_CAPI int32_t U_EXPORT2
82 ucurr_forLocale(const char* locale,
83                 UChar* buff,
84                 int32_t buffCapacity,
85                 UErrorCode* ec);
86 
87 /**
88  * Selector constants for ucurr_getName().
89  *
90  * @see ucurr_getName
91  * @stable ICU 2.6
92  */
93 typedef enum UCurrNameStyle {
94     /**
95      * Selector for ucurr_getName indicating a symbolic name for a
96      * currency, such as "$" for USD.
97      * @stable ICU 2.6
98      */
99     UCURR_SYMBOL_NAME,
100 
101     /**
102      * Selector for ucurr_getName indicating the long name for a
103      * currency, such as "US Dollar" for USD.
104      * @stable ICU 2.6
105      */
106     UCURR_LONG_NAME,
107 
108     /**
109      * Selector for getName() indicating the narrow currency symbol.
110      * The narrow currency symbol is similar to the regular currency
111      * symbol, but it always takes the shortest form: for example,
112      * "$" instead of "US$" for USD in en-CA.
113      *
114      * @stable ICU 61
115      */
116     UCURR_NARROW_SYMBOL_NAME,
117 
118 #ifndef U_HIDE_DRAFT_API
119     /**
120      * Selector for getName() indicating the formal currency symbol.
121      * The formal currency symbol is similar to the regular currency
122      * symbol, but it always takes the form used in formal settings
123      * such as banking; for example, "NT$" instead of "$" for TWD in zh-TW.
124      *
125      * @draft ICU 68
126      */
127     UCURR_FORMAL_SYMBOL_NAME,
128 
129     /**
130      * Selector for getName() indicating the variant currency symbol.
131      * The variant symbol for a currency is an alternative symbol
132      * that is not necessarily as widely used as the regular symbol.
133      *
134      * @draft ICU 68
135      */
136     UCURR_VARIANT_SYMBOL_NAME
137 #endif  // U_HIDE_DRAFT_API
138 
139 } UCurrNameStyle;
140 
141 #if !UCONFIG_NO_SERVICE
142 /**
143  * @stable ICU 2.6
144  */
145 typedef const void* UCurrRegistryKey;
146 
147 /**
148  * Register an (existing) ISO 4217 currency code for the given locale.
149  * Only the country code and the two variants EURO and PRE_EURO are
150  * recognized.
151  * @param isoCode the three-letter ISO 4217 currency code
152  * @param locale  the locale for which to register this currency code
153  * @param status the in/out status code
154  * @return a registry key that can be used to unregister this currency code, or NULL
155  * if there was an error.
156  * @stable ICU 2.6
157  */
158 U_CAPI UCurrRegistryKey U_EXPORT2
159 ucurr_register(const UChar* isoCode,
160                    const char* locale,
161                    UErrorCode* status);
162 /**
163  * Unregister the previously-registered currency definitions using the
164  * URegistryKey returned from ucurr_register.  Key becomes invalid after
165  * a successful call and should not be used again.  Any currency
166  * that might have been hidden by the original ucurr_register call is
167  * restored.
168  * @param key the registry key returned by a previous call to ucurr_register
169  * @param status the in/out status code, no special meanings are assigned
170  * @return true if the currency for this key was successfully unregistered
171  * @stable ICU 2.6
172  */
173 U_CAPI UBool U_EXPORT2
174 ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
175 #endif /* UCONFIG_NO_SERVICE */
176 
177 /**
178  * Returns the display name for the given currency in the
179  * given locale.  For example, the display name for the USD
180  * currency object in the en_US locale is "$".
181  * @param currency null-terminated 3-letter ISO 4217 code
182  * @param locale locale in which to display currency
183  * @param nameStyle selector for which kind of name to return
184  * @param isChoiceFormat always set to false, or can be NULL;
185  *     display names are static strings;
186  *     since ICU 4.4, ChoiceFormat patterns are no longer supported
187  * @param len fill-in parameter to receive length of result
188  * @param ec error code
189  * @return pointer to display string of 'len' UChars.  If the resource
190  * data contains no entry for 'currency', then 'currency' itself is
191  * returned.
192  * @stable ICU 2.6
193  */
194 U_CAPI const UChar* U_EXPORT2
195 ucurr_getName(const UChar* currency,
196               const char* locale,
197               UCurrNameStyle nameStyle,
198               UBool* isChoiceFormat,
199               int32_t* len,
200               UErrorCode* ec);
201 
202 /**
203  * Returns the plural name for the given currency in the
204  * given locale.  For example, the plural name for the USD
205  * currency object in the en_US locale is "US dollar" or "US dollars".
206  * @param currency null-terminated 3-letter ISO 4217 code
207  * @param locale locale in which to display currency
208  * @param isChoiceFormat always set to false, or can be NULL;
209  *     display names are static strings;
210  *     since ICU 4.4, ChoiceFormat patterns are no longer supported
211  * @param pluralCount plural count
212  * @param len fill-in parameter to receive length of result
213  * @param ec error code
214  * @return pointer to display string of 'len' UChars.  If the resource
215  * data contains no entry for 'currency', then 'currency' itself is
216  * returned.
217  * @stable ICU 4.2
218  */
219 U_CAPI const UChar* U_EXPORT2
220 ucurr_getPluralName(const UChar* currency,
221                     const char* locale,
222                     UBool* isChoiceFormat,
223                     const char* pluralCount,
224                     int32_t* len,
225                     UErrorCode* ec);
226 
227 /**
228  * Returns the number of the number of fraction digits that should
229  * be displayed for the given currency.
230  * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
231  *
232  * Important: The number of fraction digits for a given currency is NOT
233  * guaranteed to be constant across versions of ICU or CLDR. For example,
234  * do NOT use this value as a mechanism for deciding the magnitude used
235  * to store currency values in a database. You should use this value for
236  * display purposes only.
237  *
238  * @param currency null-terminated 3-letter ISO 4217 code
239  * @param ec input-output error code
240  * @return a non-negative number of fraction digits to be
241  * displayed, or 0 if there is an error
242  * @stable ICU 3.0
243  */
244 U_CAPI int32_t U_EXPORT2
245 ucurr_getDefaultFractionDigits(const UChar* currency,
246                                UErrorCode* ec);
247 
248 /**
249  * Returns the number of the number of fraction digits that should
250  * be displayed for the given currency with usage.
251  *
252  * Important: The number of fraction digits for a given currency is NOT
253  * guaranteed to be constant across versions of ICU or CLDR. For example,
254  * do NOT use this value as a mechanism for deciding the magnitude used
255  * to store currency values in a database. You should use this value for
256  * display purposes only.
257  *
258  * @param currency null-terminated 3-letter ISO 4217 code
259  * @param usage enum usage for the currency
260  * @param ec input-output error code
261  * @return a non-negative number of fraction digits to be
262  * displayed, or 0 if there is an error
263  * @stable ICU 54
264  */
265 U_CAPI int32_t U_EXPORT2
266 ucurr_getDefaultFractionDigitsForUsage(const UChar* currency,
267                                        const UCurrencyUsage usage,
268                                        UErrorCode* ec);
269 
270 /**
271  * Returns the rounding increment for the given currency, or 0.0 if no
272  * rounding is done by the currency.
273  * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec);
274  * @param currency null-terminated 3-letter ISO 4217 code
275  * @param ec input-output error code
276  * @return the non-negative rounding increment, or 0.0 if none,
277  * or 0.0 if there is an error
278  * @stable ICU 3.0
279  */
280 U_CAPI double U_EXPORT2
281 ucurr_getRoundingIncrement(const UChar* currency,
282                            UErrorCode* ec);
283 
284 /**
285  * Returns the rounding increment for the given currency, or 0.0 if no
286  * rounding is done by the currency given usage.
287  * @param currency null-terminated 3-letter ISO 4217 code
288  * @param usage enum usage for the currency
289  * @param ec input-output error code
290  * @return the non-negative rounding increment, or 0.0 if none,
291  * or 0.0 if there is an error
292  * @stable ICU 54
293  */
294 U_CAPI double U_EXPORT2
295 ucurr_getRoundingIncrementForUsage(const UChar* currency,
296                                    const UCurrencyUsage usage,
297                                    UErrorCode* ec);
298 
299 /**
300  * Selector constants for ucurr_openCurrencies().
301  *
302  * @see ucurr_openCurrencies
303  * @stable ICU 3.2
304  */
305 typedef enum UCurrCurrencyType {
306     /**
307      * Select all ISO-4217 currency codes.
308      * @stable ICU 3.2
309      */
310     UCURR_ALL = INT32_MAX,
311     /**
312      * Select only ISO-4217 commonly used currency codes.
313      * These currencies can be found in common use, and they usually have
314      * bank notes or coins associated with the currency code.
315      * This does not include fund codes, precious metals and other
316      * various ISO-4217 codes limited to special financial products.
317      * @stable ICU 3.2
318      */
319     UCURR_COMMON = 1,
320     /**
321      * Select ISO-4217 uncommon currency codes.
322      * These codes respresent fund codes, precious metals and other
323      * various ISO-4217 codes limited to special financial products.
324      * A fund code is a monetary resource associated with a currency.
325      * @stable ICU 3.2
326      */
327     UCURR_UNCOMMON = 2,
328     /**
329      * Select only deprecated ISO-4217 codes.
330      * These codes are no longer in general public use.
331      * @stable ICU 3.2
332      */
333     UCURR_DEPRECATED = 4,
334     /**
335      * Select only non-deprecated ISO-4217 codes.
336      * These codes are in general public use.
337      * @stable ICU 3.2
338      */
339     UCURR_NON_DEPRECATED = 8
340 } UCurrCurrencyType;
341 
342 /**
343  * Provides a UEnumeration object for listing ISO-4217 codes.
344  * @param currType You can use one of several UCurrCurrencyType values for this
345  *      variable. You can also | (or) them together to get a specific list of
346  *      currencies. Most people will want to use the (UCURR_COMMON|UCURR_NON_DEPRECATED) value to
347  *      get a list of current currencies.
348  * @param pErrorCode Error code
349  * @stable ICU 3.2
350  */
351 U_CAPI UEnumeration * U_EXPORT2
352 ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode);
353 
354 /**
355   * Queries if the given ISO 4217 3-letter code is available on the specified date range.
356   *
357   * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
358   *
359   * When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time.
360   * If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date.
361   *
362   * @param isoCode
363   *            The ISO 4217 3-letter code.
364   *
365   * @param from
366   *            The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability
367   *            of the currency any date before 'to'
368   *
369   * @param to
370   *            The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of
371   *            the currency any date after 'from'
372   *
373   * @param errorCode
374   *            ICU error code
375    *
376   * @return true if the given ISO 4217 3-letter code is supported on the specified date range.
377   *
378   * @stable ICU 4.8
379   */
380 U_CAPI UBool U_EXPORT2
381 ucurr_isAvailable(const UChar* isoCode,
382              UDate from,
383              UDate to,
384              UErrorCode* errorCode);
385 
386 /**
387  * Finds the number of valid currency codes for the
388  * given locale and date.
389  * @param locale the locale for which to retrieve the
390  *               currency count.
391  * @param date   the date for which to retrieve the
392  *               currency count for the given locale.
393  * @param ec     error code
394  * @return       the number of currency codes for the
395  *               given locale and date.  If 0, currency
396  *               codes couldn't be found for the input
397  *               values are invalid.
398  * @stable ICU 4.0
399  */
400 U_CAPI int32_t U_EXPORT2
401 ucurr_countCurrencies(const char* locale,
402                  UDate date,
403                  UErrorCode* ec);
404 
405 /**
406  * Finds a currency code for the given locale and date
407  * @param locale the locale for which to retrieve a currency code.
408  *               Currency can be specified by the "currency" keyword
409  *               in which case it overrides the default currency code
410  * @param date   the date for which to retrieve a currency code for
411  *               the given locale.
412  * @param index  the index within the available list of currency codes
413  *               for the given locale on the given date.
414  * @param buff   fill in buffer. Can be NULL for preflighting.
415  * @param buffCapacity capacity of the fill in buffer. Can be 0 for
416  *               preflighting. If it is non-zero, the buff parameter
417  *               must not be NULL.
418  * @param ec     error code
419  * @return       length of the currency string. It should always be 3.
420  *               If 0, currency couldn't be found or the input values are
421  *               invalid.
422  * @stable ICU 4.0
423  */
424 U_CAPI int32_t U_EXPORT2
425 ucurr_forLocaleAndDate(const char* locale,
426                 UDate date,
427                 int32_t index,
428                 UChar* buff,
429                 int32_t buffCapacity,
430                 UErrorCode* ec);
431 
432 /**
433  * Given a key and a locale, returns an array of string values in a preferred
434  * order that would make a difference. These are all and only those values where
435  * the open (creation) of the service with the locale formed from the input locale
436  * plus input keyword and that value has different behavior than creation with the
437  * input locale alone.
438  * @param key           one of the keys supported by this service.  For now, only
439  *                      "currency" is supported.
440  * @param locale        the locale
441  * @param commonlyUsed  if set to true it will return only commonly used values
442  *                      with the given locale in preferred order.  Otherwise,
443  *                      it will return all the available values for the locale.
444  * @param status error status
445  * @return a string enumeration over keyword values for the given key and the locale.
446  * @stable ICU 4.2
447  */
448 U_CAPI UEnumeration* U_EXPORT2
449 ucurr_getKeywordValuesForLocale(const char* key,
450                                 const char* locale,
451                                 UBool commonlyUsed,
452                                 UErrorCode* status);
453 
454 /**
455  * Returns the ISO 4217 numeric code for the currency.
456  * <p>Note: If the ISO 4217 numeric code is not assigned for the currency or
457  * the currency is unknown, this function returns 0.
458  *
459  * @param currency null-terminated 3-letter ISO 4217 code
460  * @return The ISO 4217 numeric code of the currency
461  * @stable ICU 49
462  */
463 U_CAPI int32_t U_EXPORT2
464 ucurr_getNumericCode(const UChar* currency);
465 
466 #endif /* #if !UCONFIG_NO_FORMATTING */
467 
468 #endif
469