1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (c) 2002-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
12 #include "unicode/utypes.h"
13 #include "unicode/uenum.h"
17 * \brief C API: Encapsulates information about a currency.
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:
24 * <ul><li>A display symbol, for a specific locale
25 * <li>The number of fraction digits to display
26 * <li>A rounding increment
29 * The <tt>DecimalFormat</tt> class uses these data to display
35 #if !UCONFIG_NO_FORMATTING
38 * Currency Usage used for Decimal Format
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
48 UCURR_USAGE_STANDARD
=0,
50 * a setting to specify currency usage which determines currency digit
51 * and rounding for cash usage, for example: "50 NT$"
55 #ifndef U_HIDE_DEPRECATED_API
57 * One higher than the last enum UCurrencyUsage constant.
58 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
61 #endif // U_HIDE_DEPRECATED_API
63 typedef enum UCurrencyUsage UCurrencyUsage
;
66 * Finds a currency code for the given locale.
67 * @param locale the locale for which to retrieve a currency code.
68 * Currency can be specified by the "currency" keyword
69 * in which case it overrides the default currency code
70 * @param buff fill in buffer. Can be NULL for preflighting.
71 * @param buffCapacity capacity of the fill in buffer. Can be 0 for
72 * preflighting. If it is non-zero, the buff parameter
74 * @param ec error code
75 * @return length of the currency string. It should always be 3. If 0,
76 * currency couldn't be found or the input values are
80 U_STABLE
int32_t U_EXPORT2
81 ucurr_forLocale(const char* locale
,
87 * Selector constants for ucurr_getName().
92 typedef enum UCurrNameStyle
{
94 * Selector for ucurr_getName indicating a symbolic name for a
95 * currency, such as "$" for USD.
101 * Selector for ucurr_getName indicating the long name for a
102 * currency, such as "US Dollar" for USD.
107 #ifndef U_HIDE_DRAFT_API
110 * Selector for getName() indicating the narrow currency symbol.
111 * The narrow currency symbol is similar to the regular currency
112 * symbol, but it always takes the shortest form: for example,
113 * "$" instead of "US$" for USD in en-CA.
117 UCURR_NARROW_SYMBOL_NAME
118 #endif // U_HIDE_DRAFT_API
121 #if !UCONFIG_NO_SERVICE
125 typedef const void* UCurrRegistryKey
;
128 * Register an (existing) ISO 4217 currency code for the given locale.
129 * Only the country code and the two variants EURO and PRE_EURO are
131 * @param isoCode the three-letter ISO 4217 currency code
132 * @param locale the locale for which to register this currency code
133 * @param status the in/out status code
134 * @return a registry key that can be used to unregister this currency code, or NULL
135 * if there was an error.
138 U_STABLE UCurrRegistryKey U_EXPORT2
139 ucurr_register(const UChar
* isoCode
,
143 * Unregister the previously-registered currency definitions using the
144 * URegistryKey returned from ucurr_register. Key becomes invalid after
145 * a successful call and should not be used again. Any currency
146 * that might have been hidden by the original ucurr_register call is
148 * @param key the registry key returned by a previous call to ucurr_register
149 * @param status the in/out status code, no special meanings are assigned
150 * @return TRUE if the currency for this key was successfully unregistered
153 U_STABLE UBool U_EXPORT2
154 ucurr_unregister(UCurrRegistryKey key
, UErrorCode
* status
);
155 #endif /* UCONFIG_NO_SERVICE */
158 * Returns the display name for the given currency in the
159 * given locale. For example, the display name for the USD
160 * currency object in the en_US locale is "$".
161 * @param currency null-terminated 3-letter ISO 4217 code
162 * @param locale locale in which to display currency
163 * @param nameStyle selector for which kind of name to return
164 * @param isChoiceFormat fill-in set to TRUE if the returned value
165 * is a ChoiceFormat pattern; otherwise it is a static string
166 * @param len fill-in parameter to receive length of result
167 * @param ec error code
168 * @return pointer to display string of 'len' UChars. If the resource
169 * data contains no entry for 'currency', then 'currency' itself is
170 * returned. If *isChoiceFormat is TRUE, then the result is a
171 * ChoiceFormat pattern. Otherwise it is a static string.
174 U_STABLE
const UChar
* U_EXPORT2
175 ucurr_getName(const UChar
* currency
,
177 UCurrNameStyle nameStyle
,
178 UBool
* isChoiceFormat
,
183 * Returns the plural name for the given currency in the
184 * given locale. For example, the plural name for the USD
185 * currency object in the en_US locale is "US dollar" or "US dollars".
186 * @param currency null-terminated 3-letter ISO 4217 code
187 * @param locale locale in which to display currency
188 * @param isChoiceFormat fill-in set to TRUE if the returned value
189 * is a ChoiceFormat pattern; otherwise it is a static string
190 * @param pluralCount plural count
191 * @param len fill-in parameter to receive length of result
192 * @param ec error code
193 * @return pointer to display string of 'len' UChars. If the resource
194 * data contains no entry for 'currency', then 'currency' itself is
198 U_STABLE
const UChar
* U_EXPORT2
199 ucurr_getPluralName(const UChar
* currency
,
201 UBool
* isChoiceFormat
,
202 const char* pluralCount
,
207 * Returns the number of the number of fraction digits that should
208 * be displayed for the given currency.
209 * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
210 * @param currency null-terminated 3-letter ISO 4217 code
211 * @param ec input-output error code
212 * @return a non-negative number of fraction digits to be
213 * displayed, or 0 if there is an error
216 U_STABLE
int32_t U_EXPORT2
217 ucurr_getDefaultFractionDigits(const UChar
* currency
,
221 * Returns the number of the number of fraction digits that should
222 * be displayed for the given currency with usage.
223 * @param currency null-terminated 3-letter ISO 4217 code
224 * @param usage enum usage for the currency
225 * @param ec input-output error code
226 * @return a non-negative number of fraction digits to be
227 * displayed, or 0 if there is an error
230 U_STABLE
int32_t U_EXPORT2
231 ucurr_getDefaultFractionDigitsForUsage(const UChar
* currency
,
232 const UCurrencyUsage usage
,
236 * Returns the rounding increment for the given currency, or 0.0 if no
237 * rounding is done by the currency.
238 * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec);
239 * @param currency null-terminated 3-letter ISO 4217 code
240 * @param ec input-output error code
241 * @return the non-negative rounding increment, or 0.0 if none,
242 * or 0.0 if there is an error
245 U_STABLE
double U_EXPORT2
246 ucurr_getRoundingIncrement(const UChar
* currency
,
250 * Returns the rounding increment for the given currency, or 0.0 if no
251 * rounding is done by the currency given usage.
252 * @param currency null-terminated 3-letter ISO 4217 code
253 * @param usage enum usage for the currency
254 * @param ec input-output error code
255 * @return the non-negative rounding increment, or 0.0 if none,
256 * or 0.0 if there is an error
259 U_STABLE
double U_EXPORT2
260 ucurr_getRoundingIncrementForUsage(const UChar
* currency
,
261 const UCurrencyUsage usage
,
265 * Selector constants for ucurr_openCurrencies().
267 * @see ucurr_openCurrencies
270 typedef enum UCurrCurrencyType
{
272 * Select all ISO-4217 currency codes.
275 UCURR_ALL
= INT32_MAX
,
277 * Select only ISO-4217 commonly used currency codes.
278 * These currencies can be found in common use, and they usually have
279 * bank notes or coins associated with the currency code.
280 * This does not include fund codes, precious metals and other
281 * various ISO-4217 codes limited to special financial products.
286 * Select ISO-4217 uncommon currency codes.
287 * These codes respresent fund codes, precious metals and other
288 * various ISO-4217 codes limited to special financial products.
289 * A fund code is a monetary resource associated with a currency.
294 * Select only deprecated ISO-4217 codes.
295 * These codes are no longer in general public use.
298 UCURR_DEPRECATED
= 4,
300 * Select only non-deprecated ISO-4217 codes.
301 * These codes are in general public use.
304 UCURR_NON_DEPRECATED
= 8
308 * Provides a UEnumeration object for listing ISO-4217 codes.
309 * @param currType You can use one of several UCurrCurrencyType values for this
310 * variable. You can also | (or) them together to get a specific list of
311 * currencies. Most people will want to use the (UCURR_CURRENCY|UCURR_NON_DEPRECATED) value to
312 * get a list of current currencies.
313 * @param pErrorCode Error code
316 U_STABLE UEnumeration
* U_EXPORT2
317 ucurr_openISOCurrencies(uint32_t currType
, UErrorCode
*pErrorCode
);
320 * Queries if the given ISO 4217 3-letter code is available on the specified date range.
322 * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
324 * When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time.
325 * If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date.
328 * The ISO 4217 3-letter code.
331 * The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability
332 * of the currency any date before 'to'
335 * The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of
336 * the currency any date after 'from'
341 * @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range.
345 U_STABLE UBool U_EXPORT2
346 ucurr_isAvailable(const UChar
* isoCode
,
349 UErrorCode
* errorCode
);
352 * Finds the number of valid currency codes for the
353 * given locale and date.
354 * @param locale the locale for which to retrieve the
356 * @param date the date for which to retrieve the
357 * currency count for the given locale.
358 * @param ec error code
359 * @return the number of currency codes for the
360 * given locale and date. If 0, currency
361 * codes couldn't be found for the input
362 * values are invalid.
365 U_STABLE
int32_t U_EXPORT2
366 ucurr_countCurrencies(const char* locale
,
371 * Finds a currency code for the given locale and date
372 * @param locale the locale for which to retrieve a currency code.
373 * Currency can be specified by the "currency" keyword
374 * in which case it overrides the default currency code
375 * @param date the date for which to retrieve a currency code for
377 * @param index the index within the available list of currency codes
378 * for the given locale on the given date.
379 * @param buff fill in buffer. Can be NULL for preflighting.
380 * @param buffCapacity capacity of the fill in buffer. Can be 0 for
381 * preflighting. If it is non-zero, the buff parameter
383 * @param ec error code
384 * @return length of the currency string. It should always be 3.
385 * If 0, currency couldn't be found or the input values are
389 U_STABLE
int32_t U_EXPORT2
390 ucurr_forLocaleAndDate(const char* locale
,
394 int32_t buffCapacity
,
398 * Given a key and a locale, returns an array of string values in a preferred
399 * order that would make a difference. These are all and only those values where
400 * the open (creation) of the service with the locale formed from the input locale
401 * plus input keyword and that value has different behavior than creation with the
402 * input locale alone.
403 * @param key one of the keys supported by this service. For now, only
404 * "currency" is supported.
405 * @param locale the locale
406 * @param commonlyUsed if set to true it will return only commonly used values
407 * with the given locale in preferred order. Otherwise,
408 * it will return all the available values for the locale.
409 * @param status error status
410 * @return a string enumeration over keyword values for the given key and the locale.
413 U_STABLE UEnumeration
* U_EXPORT2
414 ucurr_getKeywordValuesForLocale(const char* key
,
420 * Returns the ISO 4217 numeric code for the currency.
421 * <p>Note: If the ISO 4217 numeric code is not assigned for the currency or
422 * the currency is unknown, this function returns 0.
424 * @param currency null-terminated 3-letter ISO 4217 code
425 * @return The ISO 4217 numeric code of the currency
428 U_STABLE
int32_t U_EXPORT2
429 ucurr_getNumericCode(const UChar
* currency
);
431 #endif /* #if !UCONFIG_NO_FORMATTING */