2 **********************************************************************
3 * Copyright (c) 2002-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
10 #include "unicode/utypes.h"
11 #include "unicode/uenum.h"
15 * \brief C API: Encapsulates information about a currency.
17 * The ucurr API encapsulates information about a currency, as defined by
18 * ISO 4217. A currency is represented by a 3-character string
19 * containing its ISO 4217 code. This API can return various data
20 * necessary the proper display of a currency:
22 * <ul><li>A display symbol, for a specific locale
23 * <li>The number of fraction digits to display
24 * <li>A rounding increment
27 * The <tt>DecimalFormat</tt> class uses these data to display
33 #if !UCONFIG_NO_FORMATTING
36 * Currency Usage used for Decimal Format
41 * a setting to specify currency usage which determines currency digit
42 * and rounding for standard usage, for example: "50.00 NT$"
43 * used as DEFAULT value
46 UCURR_USAGE_STANDARD
=0,
48 * a setting to specify currency usage which determines currency digit
49 * and rounding for cash usage, for example: "50 NT$"
54 * One higher than the last enum UCurrencyUsage constant.
59 typedef enum UCurrencyUsage UCurrencyUsage
;
62 * Finds a currency code for the given locale.
63 * @param locale the locale for which to retrieve a currency code.
64 * Currency can be specified by the "currency" keyword
65 * in which case it overrides the default currency code
66 * @param buff fill in buffer. Can be NULL for preflighting.
67 * @param buffCapacity capacity of the fill in buffer. Can be 0 for
68 * preflighting. If it is non-zero, the buff parameter
70 * @param ec error code
71 * @return length of the currency string. It should always be 3. If 0,
72 * currency couldn't be found or the input values are
76 U_STABLE
int32_t U_EXPORT2
77 ucurr_forLocale(const char* locale
,
83 * Selector constants for ucurr_getName().
88 typedef enum UCurrNameStyle
{
90 * Selector for ucurr_getName indicating a symbolic name for a
91 * currency, such as "$" for USD.
97 * Selector for ucurr_getName indicating the long name for a
98 * currency, such as "US Dollar" for USD.
104 #if !UCONFIG_NO_SERVICE
108 typedef const void* UCurrRegistryKey
;
111 * Register an (existing) ISO 4217 currency code for the given locale.
112 * Only the country code and the two variants EURO and PRE_EURO are
114 * @param isoCode the three-letter ISO 4217 currency code
115 * @param locale the locale for which to register this currency code
116 * @param status the in/out status code
117 * @return a registry key that can be used to unregister this currency code, or NULL
118 * if there was an error.
121 U_STABLE UCurrRegistryKey U_EXPORT2
122 ucurr_register(const UChar
* isoCode
,
126 * Unregister the previously-registered currency definitions using the
127 * URegistryKey returned from ucurr_register. Key becomes invalid after
128 * a successful call and should not be used again. Any currency
129 * that might have been hidden by the original ucurr_register call is
131 * @param key the registry key returned by a previous call to ucurr_register
132 * @param status the in/out status code, no special meanings are assigned
133 * @return TRUE if the currency for this key was successfully unregistered
136 U_STABLE UBool U_EXPORT2
137 ucurr_unregister(UCurrRegistryKey key
, UErrorCode
* status
);
138 #endif /* UCONFIG_NO_SERVICE */
141 * Returns the display name for the given currency in the
142 * given locale. For example, the display name for the USD
143 * currency object in the en_US locale is "$".
144 * @param currency null-terminated 3-letter ISO 4217 code
145 * @param locale locale in which to display currency
146 * @param nameStyle selector for which kind of name to return
147 * @param isChoiceFormat fill-in set to TRUE if the returned value
148 * is a ChoiceFormat pattern; otherwise it is a static string
149 * @param len fill-in parameter to receive length of result
150 * @param ec error code
151 * @return pointer to display string of 'len' UChars. If the resource
152 * data contains no entry for 'currency', then 'currency' itself is
153 * returned. If *isChoiceFormat is TRUE, then the result is a
154 * ChoiceFormat pattern. Otherwise it is a static string.
157 U_STABLE
const UChar
* U_EXPORT2
158 ucurr_getName(const UChar
* currency
,
160 UCurrNameStyle nameStyle
,
161 UBool
* isChoiceFormat
,
166 * Returns the plural name for the given currency in the
167 * given locale. For example, the plural name for the USD
168 * currency object in the en_US locale is "US dollar" or "US dollars".
169 * @param currency null-terminated 3-letter ISO 4217 code
170 * @param locale locale in which to display currency
171 * @param isChoiceFormat fill-in set to TRUE if the returned value
172 * is a ChoiceFormat pattern; otherwise it is a static string
173 * @param pluralCount plural count
174 * @param len fill-in parameter to receive length of result
175 * @param ec error code
176 * @return pointer to display string of 'len' UChars. If the resource
177 * data contains no entry for 'currency', then 'currency' itself is
181 U_STABLE
const UChar
* U_EXPORT2
182 ucurr_getPluralName(const UChar
* currency
,
184 UBool
* isChoiceFormat
,
185 const char* pluralCount
,
190 * Returns the number of the number of fraction digits that should
191 * be displayed for the given currency.
192 * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
193 * @param currency null-terminated 3-letter ISO 4217 code
194 * @param ec input-output error code
195 * @return a non-negative number of fraction digits to be
196 * displayed, or 0 if there is an error
199 U_STABLE
int32_t U_EXPORT2
200 ucurr_getDefaultFractionDigits(const UChar
* currency
,
204 * Returns the number of the number of fraction digits that should
205 * be displayed for the given currency with usage.
206 * @param currency null-terminated 3-letter ISO 4217 code
207 * @param usage enum usage for the currency
208 * @param ec input-output error code
209 * @return a non-negative number of fraction digits to be
210 * displayed, or 0 if there is an error
213 U_STABLE
int32_t U_EXPORT2
214 ucurr_getDefaultFractionDigitsForUsage(const UChar
* currency
,
215 const UCurrencyUsage usage
,
219 * Returns the rounding increment for the given currency, or 0.0 if no
220 * rounding is done by the currency.
221 * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec);
222 * @param currency null-terminated 3-letter ISO 4217 code
223 * @param ec input-output error code
224 * @return the non-negative rounding increment, or 0.0 if none,
225 * or 0.0 if there is an error
228 U_STABLE
double U_EXPORT2
229 ucurr_getRoundingIncrement(const UChar
* currency
,
233 * Returns the rounding increment for the given currency, or 0.0 if no
234 * rounding is done by the currency given usage.
235 * @param currency null-terminated 3-letter ISO 4217 code
236 * @param usage enum usage for the currency
237 * @param ec input-output error code
238 * @return the non-negative rounding increment, or 0.0 if none,
239 * or 0.0 if there is an error
242 U_STABLE
double U_EXPORT2
243 ucurr_getRoundingIncrementForUsage(const UChar
* currency
,
244 const UCurrencyUsage usage
,
248 * Selector constants for ucurr_openCurrencies().
250 * @see ucurr_openCurrencies
253 typedef enum UCurrCurrencyType
{
255 * Select all ISO-4217 currency codes.
258 UCURR_ALL
= INT32_MAX
,
260 * Select only ISO-4217 commonly used currency codes.
261 * These currencies can be found in common use, and they usually have
262 * bank notes or coins associated with the currency code.
263 * This does not include fund codes, precious metals and other
264 * various ISO-4217 codes limited to special financial products.
269 * Select ISO-4217 uncommon currency codes.
270 * These codes respresent fund codes, precious metals and other
271 * various ISO-4217 codes limited to special financial products.
272 * A fund code is a monetary resource associated with a currency.
277 * Select only deprecated ISO-4217 codes.
278 * These codes are no longer in general public use.
281 UCURR_DEPRECATED
= 4,
283 * Select only non-deprecated ISO-4217 codes.
284 * These codes are in general public use.
287 UCURR_NON_DEPRECATED
= 8
291 * Provides a UEnumeration object for listing ISO-4217 codes.
292 * @param currType You can use one of several UCurrCurrencyType values for this
293 * variable. You can also | (or) them together to get a specific list of
294 * currencies. Most people will want to use the (UCURR_CURRENCY|UCURR_NON_DEPRECATED) value to
295 * get a list of current currencies.
296 * @param pErrorCode Error code
299 U_STABLE UEnumeration
* U_EXPORT2
300 ucurr_openISOCurrencies(uint32_t currType
, UErrorCode
*pErrorCode
);
303 * Queries if the given ISO 4217 3-letter code is available on the specified date range.
305 * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
307 * When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time.
308 * If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date.
311 * The ISO 4217 3-letter code.
314 * The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability
315 * of the currency any date before 'to'
318 * The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of
319 * the currency any date after 'from'
324 * @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range.
328 U_STABLE UBool U_EXPORT2
329 ucurr_isAvailable(const UChar
* isoCode
,
332 UErrorCode
* errorCode
);
335 * Finds the number of valid currency codes for the
336 * given locale and date.
337 * @param locale the locale for which to retrieve the
339 * @param date the date for which to retrieve the
340 * currency count for the given locale.
341 * @param ec error code
342 * @return the number of currency codes for the
343 * given locale and date. If 0, currency
344 * codes couldn't be found for the input
345 * values are invalid.
348 U_STABLE
int32_t U_EXPORT2
349 ucurr_countCurrencies(const char* locale
,
354 * Finds a currency code for the given locale and date
355 * @param locale the locale for which to retrieve a currency code.
356 * Currency can be specified by the "currency" keyword
357 * in which case it overrides the default currency code
358 * @param date the date for which to retrieve a currency code for
360 * @param index the index within the available list of currency codes
361 * for the given locale on the given date.
362 * @param buff fill in buffer. Can be NULL for preflighting.
363 * @param buffCapacity capacity of the fill in buffer. Can be 0 for
364 * preflighting. If it is non-zero, the buff parameter
366 * @param ec error code
367 * @return length of the currency string. It should always be 3.
368 * If 0, currency couldn't be found or the input values are
372 U_STABLE
int32_t U_EXPORT2
373 ucurr_forLocaleAndDate(const char* locale
,
377 int32_t buffCapacity
,
381 * Given a key and a locale, returns an array of string values in a preferred
382 * order that would make a difference. These are all and only those values where
383 * the open (creation) of the service with the locale formed from the input locale
384 * plus input keyword and that value has different behavior than creation with the
385 * input locale alone.
386 * @param key one of the keys supported by this service. For now, only
387 * "currency" is supported.
388 * @param locale the locale
389 * @param commonlyUsed if set to true it will return only commonly used values
390 * with the given locale in preferred order. Otherwise,
391 * it will return all the available values for the locale.
392 * @param status error status
393 * @return a string enumeration over keyword values for the given key and the locale.
396 U_STABLE UEnumeration
* U_EXPORT2
397 ucurr_getKeywordValuesForLocale(const char* key
,
403 * Returns the ISO 4217 numeric code for the currency.
404 * <p>Note: If the ISO 4217 numeric code is not assigned for the currency or
405 * the currency is unknown, this function returns 0.
407 * @param currency null-terminated 3-letter ISO 4217 code
408 * @return The ISO 4217 numeric code of the currency
411 U_STABLE
int32_t U_EXPORT2
412 ucurr_getNumericCode(const UChar
* currency
);
414 #endif /* #if !UCONFIG_NO_FORMATTING */