]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/ucurr.h
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / ucurr.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4**********************************************************************
2ca993e8 5* Copyright (c) 2002-2016, International Business Machines
b75a7d8f
A
6* Corporation and others. All Rights Reserved.
7**********************************************************************
b75a7d8f
A
8*/
9#ifndef _UCURR_H_
10#define _UCURR_H_
11
12#include "unicode/utypes.h"
73c04bcf
A
13#include "unicode/uenum.h"
14
15/**
16 * \file
17 * \brief C API: Encapsulates information about a currency.
2ca993e8
A
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
73c04bcf 33 */
b75a7d8f
A
34
35#if !UCONFIG_NO_FORMATTING
36
b331163b
A
37/**
38 * Currency Usage used for Decimal Format
2ca993e8 39 * @stable ICU 54
b331163b
A
40 */
41enum UCurrencyUsage {
b331163b
A
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
2ca993e8 46 * @stable ICU 54
b331163b
A
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$"
2ca993e8 52 * @stable ICU 54
b331163b
A
53 */
54 UCURR_USAGE_CASH=1,
f3c0d7a5 55#ifndef U_HIDE_DEPRECATED_API
b331163b
A
56 /**
57 * One higher than the last enum UCurrencyUsage constant.
f3c0d7a5 58 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
b331163b
A
59 */
60 UCURR_USAGE_COUNT=2
f3c0d7a5 61#endif // U_HIDE_DEPRECATED_API
b331163b
A
62};
63typedef enum UCurrencyUsage UCurrencyUsage;
64
b75a7d8f 65/**
374ca955
A
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
73 * must not be NULL.
b75a7d8f 74 * @param ec error code
374ca955
A
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
77 * invalid.
73c04bcf 78 * @stable ICU 2.8
b75a7d8f 79 */
73c04bcf 80U_STABLE int32_t U_EXPORT2
b75a7d8f 81ucurr_forLocale(const char* locale,
374ca955
A
82 UChar* buff,
83 int32_t buffCapacity,
b75a7d8f
A
84 UErrorCode* ec);
85
86/**
87 * Selector constants for ucurr_getName().
88 *
89 * @see ucurr_getName
374ca955 90 * @stable ICU 2.6
b75a7d8f
A
91 */
92typedef enum UCurrNameStyle {
93 /**
94 * Selector for ucurr_getName indicating a symbolic name for a
95 * currency, such as "$" for USD.
374ca955 96 * @stable ICU 2.6
b75a7d8f
A
97 */
98 UCURR_SYMBOL_NAME,
99
100 /**
101 * Selector for ucurr_getName indicating the long name for a
102 * currency, such as "US Dollar" for USD.
374ca955 103 * @stable ICU 2.6
b75a7d8f
A
104 */
105 UCURR_LONG_NAME
0f5d89e8
A
106
107#ifndef U_HIDE_DRAFT_API
108 ,
109 /**
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.
114 *
115 * @draft ICU 61
116 */
117 UCURR_NARROW_SYMBOL_NAME
118#endif // U_HIDE_DRAFT_API
b75a7d8f
A
119} UCurrNameStyle;
120
374ca955
A
121#if !UCONFIG_NO_SERVICE
122/**
73c04bcf 123 * @stable ICU 2.6
374ca955
A
124 */
125typedef const void* UCurrRegistryKey;
126
b75a7d8f
A
127/**
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
130 * recognized.
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.
374ca955 136 * @stable ICU 2.6
b75a7d8f 137 */
374ca955
A
138U_STABLE UCurrRegistryKey U_EXPORT2
139ucurr_register(const UChar* isoCode,
b75a7d8f
A
140 const char* locale,
141 UErrorCode* status);
142/**
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
147 * restored.
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
374ca955 151 * @stable ICU 2.6
b75a7d8f 152 */
374ca955
A
153U_STABLE UBool U_EXPORT2
154ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
155#endif /* UCONFIG_NO_SERVICE */
b75a7d8f
A
156
157/**
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.
374ca955 172 * @stable ICU 2.6
b75a7d8f 173 */
374ca955 174U_STABLE const UChar* U_EXPORT2
b75a7d8f
A
175ucurr_getName(const UChar* currency,
176 const char* locale,
177 UCurrNameStyle nameStyle,
178 UBool* isChoiceFormat,
179 int32_t* len,
180 UErrorCode* ec);
181
729e4ab9
A
182/**
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
195 * returned.
196 * @stable ICU 4.2
197 */
198U_STABLE const UChar* U_EXPORT2
199ucurr_getPluralName(const UChar* currency,
200 const char* locale,
201 UBool* isChoiceFormat,
202 const char* pluralCount,
203 int32_t* len,
204 UErrorCode* ec);
205
b75a7d8f
A
206/**
207 * Returns the number of the number of fraction digits that should
208 * be displayed for the given currency.
b331163b 209 * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
b75a7d8f 210 * @param currency null-terminated 3-letter ISO 4217 code
374ca955 211 * @param ec input-output error code
b75a7d8f 212 * @return a non-negative number of fraction digits to be
374ca955 213 * displayed, or 0 if there is an error
73c04bcf 214 * @stable ICU 3.0
b75a7d8f 215 */
73c04bcf 216U_STABLE int32_t U_EXPORT2
374ca955
A
217ucurr_getDefaultFractionDigits(const UChar* currency,
218 UErrorCode* ec);
b75a7d8f 219
b331163b
A
220/**
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
2ca993e8 228 * @stable ICU 54
b331163b 229 */
2ca993e8 230U_STABLE int32_t U_EXPORT2
b331163b
A
231ucurr_getDefaultFractionDigitsForUsage(const UChar* currency,
232 const UCurrencyUsage usage,
233 UErrorCode* ec);
b331163b 234
b75a7d8f
A
235/**
236 * Returns the rounding increment for the given currency, or 0.0 if no
237 * rounding is done by the currency.
b331163b 238 * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec);
b75a7d8f 239 * @param currency null-terminated 3-letter ISO 4217 code
374ca955
A
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
73c04bcf 243 * @stable ICU 3.0
b75a7d8f 244 */
73c04bcf 245U_STABLE double U_EXPORT2
374ca955
A
246ucurr_getRoundingIncrement(const UChar* currency,
247 UErrorCode* ec);
248
b331163b
A
249/**
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
2ca993e8 257 * @stable ICU 54
b331163b 258 */
2ca993e8 259U_STABLE double U_EXPORT2
b331163b
A
260ucurr_getRoundingIncrementForUsage(const UChar* currency,
261 const UCurrencyUsage usage,
262 UErrorCode* ec);
b331163b 263
73c04bcf
A
264/**
265 * Selector constants for ucurr_openCurrencies().
266 *
267 * @see ucurr_openCurrencies
268 * @stable ICU 3.2
269 */
270typedef enum UCurrCurrencyType {
271 /**
272 * Select all ISO-4217 currency codes.
273 * @stable ICU 3.2
274 */
275 UCURR_ALL = INT32_MAX,
276 /**
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.
282 * @stable ICU 3.2
283 */
284 UCURR_COMMON = 1,
285 /**
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.
290 * @stable ICU 3.2
291 */
292 UCURR_UNCOMMON = 2,
293 /**
294 * Select only deprecated ISO-4217 codes.
295 * These codes are no longer in general public use.
296 * @stable ICU 3.2
297 */
298 UCURR_DEPRECATED = 4,
299 /**
300 * Select only non-deprecated ISO-4217 codes.
301 * These codes are in general public use.
302 * @stable ICU 3.2
303 */
304 UCURR_NON_DEPRECATED = 8
305} UCurrCurrencyType;
306
307/**
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
314 * @stable ICU 3.2
315 */
316U_STABLE UEnumeration * U_EXPORT2
317ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode);
318
4388f060
A
319/**
320 * Queries if the given ISO 4217 3-letter code is available on the specified date range.
321 *
322 * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
323 *
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.
326 *
327 * @param isoCode
328 * The ISO 4217 3-letter code.
329 *
330 * @param from
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'
333 *
334 * @param 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'
337 *
338 * @param errorCode
339 * ICU error code
340 *
341 * @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range.
342 *
343 * @stable ICU 4.8
344 */
51004dcb 345U_STABLE UBool U_EXPORT2
4388f060
A
346ucurr_isAvailable(const UChar* isoCode,
347 UDate from,
348 UDate to,
349 UErrorCode* errorCode);
350
46f4442e
A
351/**
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
355 * currency count.
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.
729e4ab9 363 * @stable ICU 4.0
374ca955 364 */
729e4ab9 365U_STABLE int32_t U_EXPORT2
46f4442e
A
366ucurr_countCurrencies(const char* locale,
367 UDate date,
368 UErrorCode* ec);
374ca955 369
46f4442e
A
370/**
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
376 * the given locale.
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
382 * must not be NULL.
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
386 * invalid.
729e4ab9 387 * @stable ICU 4.0
46f4442e 388 */
729e4ab9 389U_STABLE int32_t U_EXPORT2
46f4442e
A
390ucurr_forLocaleAndDate(const char* locale,
391 UDate date,
392 int32_t index,
393 UChar* buff,
394 int32_t buffCapacity,
395 UErrorCode* ec);
b75a7d8f 396
729e4ab9
A
397/**
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.
411 * @stable ICU 4.2
412 */
413U_STABLE UEnumeration* U_EXPORT2
414ucurr_getKeywordValuesForLocale(const char* key,
415 const char* locale,
416 UBool commonlyUsed,
417 UErrorCode* status);
418
4388f060
A
419/**
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.
423 *
424 * @param currency null-terminated 3-letter ISO 4217 code
425 * @return The ISO 4217 numeric code of the currency
51004dcb 426 * @stable ICU 49
4388f060 427 */
51004dcb 428U_STABLE int32_t U_EXPORT2
4388f060 429ucurr_getNumericCode(const UChar* currency);
4388f060 430
b75a7d8f
A
431#endif /* #if !UCONFIG_NO_FORMATTING */
432
433#endif