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_STABLE 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 | } UCurrNameStyle; |
118 | |
119 | #if !UCONFIG_NO_SERVICE |
120 | /** |
121 | * @stable ICU 2.6 |
122 | */ |
123 | typedef const void* UCurrRegistryKey; |
124 | |
125 | /** |
126 | * Register an (existing) ISO 4217 currency code for the given locale. |
127 | * Only the country code and the two variants EURO and PRE_EURO are |
128 | * recognized. |
129 | * @param isoCode the three-letter ISO 4217 currency code |
130 | * @param locale the locale for which to register this currency code |
131 | * @param status the in/out status code |
132 | * @return a registry key that can be used to unregister this currency code, or NULL |
133 | * if there was an error. |
134 | * @stable ICU 2.6 |
135 | */ |
136 | U_STABLE UCurrRegistryKey U_EXPORT2 |
137 | ucurr_register(const UChar* isoCode, |
138 | const char* locale, |
139 | UErrorCode* status); |
140 | /** |
141 | * Unregister the previously-registered currency definitions using the |
142 | * URegistryKey returned from ucurr_register. Key becomes invalid after |
143 | * a successful call and should not be used again. Any currency |
144 | * that might have been hidden by the original ucurr_register call is |
145 | * restored. |
146 | * @param key the registry key returned by a previous call to ucurr_register |
147 | * @param status the in/out status code, no special meanings are assigned |
148 | * @return TRUE if the currency for this key was successfully unregistered |
149 | * @stable ICU 2.6 |
150 | */ |
151 | U_STABLE UBool U_EXPORT2 |
152 | ucurr_unregister(UCurrRegistryKey key, UErrorCode* status); |
153 | #endif /* UCONFIG_NO_SERVICE */ |
154 | |
155 | /** |
156 | * Returns the display name for the given currency in the |
157 | * given locale. For example, the display name for the USD |
158 | * currency object in the en_US locale is "$". |
159 | * @param currency null-terminated 3-letter ISO 4217 code |
160 | * @param locale locale in which to display currency |
161 | * @param nameStyle selector for which kind of name to return |
162 | * @param isChoiceFormat fill-in set to TRUE if the returned value |
163 | * is a ChoiceFormat pattern; otherwise it is a static string |
164 | * @param len fill-in parameter to receive length of result |
165 | * @param ec error code |
166 | * @return pointer to display string of 'len' UChars. If the resource |
167 | * data contains no entry for 'currency', then 'currency' itself is |
168 | * returned. If *isChoiceFormat is TRUE, then the result is a |
169 | * ChoiceFormat pattern. Otherwise it is a static string. |
170 | * @stable ICU 2.6 |
171 | */ |
172 | U_STABLE const UChar* U_EXPORT2 |
173 | ucurr_getName(const UChar* currency, |
174 | const char* locale, |
175 | UCurrNameStyle nameStyle, |
176 | UBool* isChoiceFormat, |
177 | int32_t* len, |
178 | UErrorCode* ec); |
179 | |
180 | /** |
181 | * Returns the plural name for the given currency in the |
182 | * given locale. For example, the plural name for the USD |
183 | * currency object in the en_US locale is "US dollar" or "US dollars". |
184 | * @param currency null-terminated 3-letter ISO 4217 code |
185 | * @param locale locale in which to display currency |
186 | * @param isChoiceFormat fill-in set to TRUE if the returned value |
187 | * is a ChoiceFormat pattern; otherwise it is a static string |
188 | * @param pluralCount plural count |
189 | * @param len fill-in parameter to receive length of result |
190 | * @param ec error code |
191 | * @return pointer to display string of 'len' UChars. If the resource |
192 | * data contains no entry for 'currency', then 'currency' itself is |
193 | * returned. |
194 | * @stable ICU 4.2 |
195 | */ |
196 | U_STABLE const UChar* U_EXPORT2 |
197 | ucurr_getPluralName(const UChar* currency, |
198 | const char* locale, |
199 | UBool* isChoiceFormat, |
200 | const char* pluralCount, |
201 | int32_t* len, |
202 | UErrorCode* ec); |
203 | |
204 | /** |
205 | * Returns the number of the number of fraction digits that should |
206 | * be displayed for the given currency. |
207 | * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec); |
208 | * |
209 | * Important: The number of fraction digits for a given currency is NOT |
210 | * guaranteed to be constant across versions of ICU or CLDR. For example, |
211 | * do NOT use this value as a mechanism for deciding the magnitude used |
212 | * to store currency values in a database. You should use this value for |
213 | * display purposes only. |
214 | * |
215 | * @param currency null-terminated 3-letter ISO 4217 code |
216 | * @param ec input-output error code |
217 | * @return a non-negative number of fraction digits to be |
218 | * displayed, or 0 if there is an error |
219 | * @stable ICU 3.0 |
220 | */ |
221 | U_STABLE int32_t U_EXPORT2 |
222 | ucurr_getDefaultFractionDigits(const UChar* currency, |
223 | UErrorCode* ec); |
224 | |
225 | /** |
226 | * Returns the number of the number of fraction digits that should |
227 | * be displayed for the given currency with usage. |
228 | * |
229 | * Important: The number of fraction digits for a given currency is NOT |
230 | * guaranteed to be constant across versions of ICU or CLDR. For example, |
231 | * do NOT use this value as a mechanism for deciding the magnitude used |
232 | * to store currency values in a database. You should use this value for |
233 | * display purposes only. |
234 | * |
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 a non-negative number of fraction digits to be |
239 | * displayed, or 0 if there is an error |
240 | * @stable ICU 54 |
241 | */ |
242 | U_STABLE int32_t U_EXPORT2 |
243 | ucurr_getDefaultFractionDigitsForUsage(const UChar* currency, |
244 | const UCurrencyUsage usage, |
245 | UErrorCode* ec); |
246 | |
247 | /** |
248 | * Returns the rounding increment for the given currency, or 0.0 if no |
249 | * rounding is done by the currency. |
250 | * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec); |
251 | * @param currency null-terminated 3-letter ISO 4217 code |
252 | * @param ec input-output error code |
253 | * @return the non-negative rounding increment, or 0.0 if none, |
254 | * or 0.0 if there is an error |
255 | * @stable ICU 3.0 |
256 | */ |
257 | U_STABLE double U_EXPORT2 |
258 | ucurr_getRoundingIncrement(const UChar* currency, |
259 | UErrorCode* ec); |
260 | |
261 | /** |
262 | * Returns the rounding increment for the given currency, or 0.0 if no |
263 | * rounding is done by the currency given usage. |
264 | * @param currency null-terminated 3-letter ISO 4217 code |
265 | * @param usage enum usage for the currency |
266 | * @param ec input-output error code |
267 | * @return the non-negative rounding increment, or 0.0 if none, |
268 | * or 0.0 if there is an error |
269 | * @stable ICU 54 |
270 | */ |
271 | U_STABLE double U_EXPORT2 |
272 | ucurr_getRoundingIncrementForUsage(const UChar* currency, |
273 | const UCurrencyUsage usage, |
274 | UErrorCode* ec); |
275 | |
276 | /** |
277 | * Selector constants for ucurr_openCurrencies(). |
278 | * |
279 | * @see ucurr_openCurrencies |
280 | * @stable ICU 3.2 |
281 | */ |
282 | typedef enum UCurrCurrencyType { |
283 | /** |
284 | * Select all ISO-4217 currency codes. |
285 | * @stable ICU 3.2 |
286 | */ |
287 | UCURR_ALL = INT32_MAX, |
288 | /** |
289 | * Select only ISO-4217 commonly used currency codes. |
290 | * These currencies can be found in common use, and they usually have |
291 | * bank notes or coins associated with the currency code. |
292 | * This does not include fund codes, precious metals and other |
293 | * various ISO-4217 codes limited to special financial products. |
294 | * @stable ICU 3.2 |
295 | */ |
296 | UCURR_COMMON = 1, |
297 | /** |
298 | * Select ISO-4217 uncommon currency codes. |
299 | * These codes respresent fund codes, precious metals and other |
300 | * various ISO-4217 codes limited to special financial products. |
301 | * A fund code is a monetary resource associated with a currency. |
302 | * @stable ICU 3.2 |
303 | */ |
304 | UCURR_UNCOMMON = 2, |
305 | /** |
306 | * Select only deprecated ISO-4217 codes. |
307 | * These codes are no longer in general public use. |
308 | * @stable ICU 3.2 |
309 | */ |
310 | UCURR_DEPRECATED = 4, |
311 | /** |
312 | * Select only non-deprecated ISO-4217 codes. |
313 | * These codes are in general public use. |
314 | * @stable ICU 3.2 |
315 | */ |
316 | UCURR_NON_DEPRECATED = 8 |
317 | } UCurrCurrencyType; |
318 | |
319 | /** |
320 | * Provides a UEnumeration object for listing ISO-4217 codes. |
321 | * @param currType You can use one of several UCurrCurrencyType values for this |
322 | * variable. You can also | (or) them together to get a specific list of |
323 | * currencies. Most people will want to use the (UCURR_CURRENCY|UCURR_NON_DEPRECATED) value to |
324 | * get a list of current currencies. |
325 | * @param pErrorCode Error code |
326 | * @stable ICU 3.2 |
327 | */ |
328 | U_STABLE UEnumeration * U_EXPORT2 |
329 | ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode); |
330 | |
331 | /** |
332 | * Queries if the given ISO 4217 3-letter code is available on the specified date range. |
333 | * |
334 | * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to' |
335 | * |
336 | * When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time. |
337 | * If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date. |
338 | * |
339 | * @param isoCode |
340 | * The ISO 4217 3-letter code. |
341 | * |
342 | * @param from |
343 | * The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability |
344 | * of the currency any date before 'to' |
345 | * |
346 | * @param to |
347 | * The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of |
348 | * the currency any date after 'from' |
349 | * |
350 | * @param errorCode |
351 | * ICU error code |
352 | * |
353 | * @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range. |
354 | * |
355 | * @stable ICU 4.8 |
356 | */ |
357 | U_STABLE UBool U_EXPORT2 |
358 | ucurr_isAvailable(const UChar* isoCode, |
359 | UDate from, |
360 | UDate to, |
361 | UErrorCode* errorCode); |
362 | |
363 | /** |
364 | * Finds the number of valid currency codes for the |
365 | * given locale and date. |
366 | * @param locale the locale for which to retrieve the |
367 | * currency count. |
368 | * @param date the date for which to retrieve the |
369 | * currency count for the given locale. |
370 | * @param ec error code |
371 | * @return the number of currency codes for the |
372 | * given locale and date. If 0, currency |
373 | * codes couldn't be found for the input |
374 | * values are invalid. |
375 | * @stable ICU 4.0 |
376 | */ |
377 | U_STABLE int32_t U_EXPORT2 |
378 | ucurr_countCurrencies(const char* locale, |
379 | UDate date, |
380 | UErrorCode* ec); |
381 | |
382 | /** |
383 | * Finds a currency code for the given locale and date |
384 | * @param locale the locale for which to retrieve a currency code. |
385 | * Currency can be specified by the "currency" keyword |
386 | * in which case it overrides the default currency code |
387 | * @param date the date for which to retrieve a currency code for |
388 | * the given locale. |
389 | * @param index the index within the available list of currency codes |
390 | * for the given locale on the given date. |
391 | * @param buff fill in buffer. Can be NULL for preflighting. |
392 | * @param buffCapacity capacity of the fill in buffer. Can be 0 for |
393 | * preflighting. If it is non-zero, the buff parameter |
394 | * must not be NULL. |
395 | * @param ec error code |
396 | * @return length of the currency string. It should always be 3. |
397 | * If 0, currency couldn't be found or the input values are |
398 | * invalid. |
399 | * @stable ICU 4.0 |
400 | */ |
401 | U_STABLE int32_t U_EXPORT2 |
402 | ucurr_forLocaleAndDate(const char* locale, |
403 | UDate date, |
404 | int32_t index, |
405 | UChar* buff, |
406 | int32_t buffCapacity, |
407 | UErrorCode* ec); |
408 | |
409 | /** |
410 | * Given a key and a locale, returns an array of string values in a preferred |
411 | * order that would make a difference. These are all and only those values where |
412 | * the open (creation) of the service with the locale formed from the input locale |
413 | * plus input keyword and that value has different behavior than creation with the |
414 | * input locale alone. |
415 | * @param key one of the keys supported by this service. For now, only |
416 | * "currency" is supported. |
417 | * @param locale the locale |
418 | * @param commonlyUsed if set to true it will return only commonly used values |
419 | * with the given locale in preferred order. Otherwise, |
420 | * it will return all the available values for the locale. |
421 | * @param status error status |
422 | * @return a string enumeration over keyword values for the given key and the locale. |
423 | * @stable ICU 4.2 |
424 | */ |
425 | U_STABLE UEnumeration* U_EXPORT2 |
426 | ucurr_getKeywordValuesForLocale(const char* key, |
427 | const char* locale, |
428 | UBool commonlyUsed, |
429 | UErrorCode* status); |
430 | |
431 | /** |
432 | * Returns the ISO 4217 numeric code for the currency. |
433 | * <p>Note: If the ISO 4217 numeric code is not assigned for the currency or |
434 | * the currency is unknown, this function returns 0. |
435 | * |
436 | * @param currency null-terminated 3-letter ISO 4217 code |
437 | * @return The ISO 4217 numeric code of the currency |
438 | * @stable ICU 49 |
439 | */ |
440 | U_STABLE int32_t U_EXPORT2 |
441 | ucurr_getNumericCode(const UChar* currency); |
442 | |
443 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
444 | |
445 | #endif |
446 | |