]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/ucurr.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / ucurr.h
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 typedef enum UCurrencyUsage UCurrencyUsage;
64
65 /**
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.
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
77 * invalid.
78 * @stable ICU 2.8
79 */
80 U_STABLE int32_t U_EXPORT2
81 ucurr_forLocale(const char* locale,
82 UChar* buff,
83 int32_t buffCapacity,
84 UErrorCode* ec);
85
86 /**
87 * Selector constants for ucurr_getName().
88 *
89 * @see ucurr_getName
90 * @stable ICU 2.6
91 */
92 typedef enum UCurrNameStyle {
93 /**
94 * Selector for ucurr_getName indicating a symbolic name for a
95 * currency, such as "$" for USD.
96 * @stable ICU 2.6
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.
103 * @stable ICU 2.6
104 */
105 UCURR_LONG_NAME
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
119 } UCurrNameStyle;
120
121 #if !UCONFIG_NO_SERVICE
122 /**
123 * @stable ICU 2.6
124 */
125 typedef const void* UCurrRegistryKey;
126
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.
136 * @stable ICU 2.6
137 */
138 U_STABLE UCurrRegistryKey U_EXPORT2
139 ucurr_register(const UChar* isoCode,
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
151 * @stable ICU 2.6
152 */
153 U_STABLE UBool U_EXPORT2
154 ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
155 #endif /* UCONFIG_NO_SERVICE */
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.
172 * @stable ICU 2.6
173 */
174 U_STABLE const UChar* U_EXPORT2
175 ucurr_getName(const UChar* currency,
176 const char* locale,
177 UCurrNameStyle nameStyle,
178 UBool* isChoiceFormat,
179 int32_t* len,
180 UErrorCode* ec);
181
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 */
198 U_STABLE const UChar* U_EXPORT2
199 ucurr_getPluralName(const UChar* currency,
200 const char* locale,
201 UBool* isChoiceFormat,
202 const char* pluralCount,
203 int32_t* len,
204 UErrorCode* ec);
205
206 /**
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
214 * @stable ICU 3.0
215 */
216 U_STABLE int32_t U_EXPORT2
217 ucurr_getDefaultFractionDigits(const UChar* currency,
218 UErrorCode* ec);
219
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
228 * @stable ICU 54
229 */
230 U_STABLE int32_t U_EXPORT2
231 ucurr_getDefaultFractionDigitsForUsage(const UChar* currency,
232 const UCurrencyUsage usage,
233 UErrorCode* ec);
234
235 /**
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
243 * @stable ICU 3.0
244 */
245 U_STABLE double U_EXPORT2
246 ucurr_getRoundingIncrement(const UChar* currency,
247 UErrorCode* ec);
248
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
257 * @stable ICU 54
258 */
259 U_STABLE double U_EXPORT2
260 ucurr_getRoundingIncrementForUsage(const UChar* currency,
261 const UCurrencyUsage usage,
262 UErrorCode* ec);
263
264 /**
265 * Selector constants for ucurr_openCurrencies().
266 *
267 * @see ucurr_openCurrencies
268 * @stable ICU 3.2
269 */
270 typedef 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 */
316 U_STABLE UEnumeration * U_EXPORT2
317 ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode);
318
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 */
345 U_STABLE UBool U_EXPORT2
346 ucurr_isAvailable(const UChar* isoCode,
347 UDate from,
348 UDate to,
349 UErrorCode* errorCode);
350
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.
363 * @stable ICU 4.0
364 */
365 U_STABLE int32_t U_EXPORT2
366 ucurr_countCurrencies(const char* locale,
367 UDate date,
368 UErrorCode* ec);
369
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.
387 * @stable ICU 4.0
388 */
389 U_STABLE int32_t U_EXPORT2
390 ucurr_forLocaleAndDate(const char* locale,
391 UDate date,
392 int32_t index,
393 UChar* buff,
394 int32_t buffCapacity,
395 UErrorCode* ec);
396
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 */
413 U_STABLE UEnumeration* U_EXPORT2
414 ucurr_getKeywordValuesForLocale(const char* key,
415 const char* locale,
416 UBool commonlyUsed,
417 UErrorCode* status);
418
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
426 * @stable ICU 49
427 */
428 U_STABLE int32_t U_EXPORT2
429 ucurr_getNumericCode(const UChar* currency);
430
431 #endif /* #if !UCONFIG_NO_FORMATTING */
432
433 #endif