ucurr.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. #include "unicode/utypes.h"
  12. #include "unicode/uenum.h"
  13. /**
  14. * \file
  15. * \brief C API: Encapsulates information about a currency.
  16. *
  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:
  21. *
  22. * <ul><li>A display symbol, for a specific locale
  23. * <li>The number of fraction digits to display
  24. * <li>A rounding increment
  25. * </ul>
  26. *
  27. * The <tt>DecimalFormat</tt> class uses these data to display
  28. * currencies.
  29. * @author Alan Liu
  30. * @since ICU 2.2
  31. */
  32. #if !UCONFIG_NO_FORMATTING
  33. /**
  34. * Currency Usage used for Decimal Format
  35. * @stable ICU 54
  36. */
  37. enum UCurrencyUsage {
  38. /**
  39. * a setting to specify currency usage which determines currency digit
  40. * and rounding for standard usage, for example: "50.00 NT$"
  41. * used as DEFAULT value
  42. * @stable ICU 54
  43. */
  44. UCURR_USAGE_STANDARD=0,
  45. /**
  46. * a setting to specify currency usage which determines currency digit
  47. * and rounding for cash usage, for example: "50 NT$"
  48. * @stable ICU 54
  49. */
  50. UCURR_USAGE_CASH=1,
  51. #ifndef U_HIDE_DEPRECATED_API
  52. /**
  53. * One higher than the last enum UCurrencyUsage constant.
  54. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  55. */
  56. UCURR_USAGE_COUNT=2
  57. #endif // U_HIDE_DEPRECATED_API
  58. };
  59. /** Currency Usage used for Decimal Format */
  60. typedef enum UCurrencyUsage UCurrencyUsage;
  61. /**
  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
  69. * must not be NULL.
  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
  73. * invalid.
  74. * @stable ICU 2.8
  75. */
  76. U_CAPI int32_t U_EXPORT2
  77. ucurr_forLocale(const char* locale,
  78. UChar* buff,
  79. int32_t buffCapacity,
  80. UErrorCode* ec);
  81. /**
  82. * Selector constants for ucurr_getName().
  83. *
  84. * @see ucurr_getName
  85. * @stable ICU 2.6
  86. */
  87. typedef enum UCurrNameStyle {
  88. /**
  89. * Selector for ucurr_getName indicating a symbolic name for a
  90. * currency, such as "$" for USD.
  91. * @stable ICU 2.6
  92. */
  93. UCURR_SYMBOL_NAME,
  94. /**
  95. * Selector for ucurr_getName indicating the long name for a
  96. * currency, such as "US Dollar" for USD.
  97. * @stable ICU 2.6
  98. */
  99. UCURR_LONG_NAME,
  100. /**
  101. * Selector for getName() indicating the narrow currency symbol.
  102. * The narrow currency symbol is similar to the regular currency
  103. * symbol, but it always takes the shortest form: for example,
  104. * "$" instead of "US$" for USD in en-CA.
  105. *
  106. * @stable ICU 61
  107. */
  108. UCURR_NARROW_SYMBOL_NAME,
  109. /**
  110. * Selector for getName() indicating the formal currency symbol.
  111. * The formal currency symbol is similar to the regular currency
  112. * symbol, but it always takes the form used in formal settings
  113. * such as banking; for example, "NT$" instead of "$" for TWD in zh-TW.
  114. *
  115. * @stable ICU 68
  116. */
  117. UCURR_FORMAL_SYMBOL_NAME,
  118. /**
  119. * Selector for getName() indicating the variant currency symbol.
  120. * The variant symbol for a currency is an alternative symbol
  121. * that is not necessarily as widely used as the regular symbol.
  122. *
  123. * @stable ICU 68
  124. */
  125. UCURR_VARIANT_SYMBOL_NAME
  126. } UCurrNameStyle;
  127. #if !UCONFIG_NO_SERVICE
  128. /**
  129. * @stable ICU 2.6
  130. */
  131. typedef const void* UCurrRegistryKey;
  132. /**
  133. * Register an (existing) ISO 4217 currency code for the given locale.
  134. * Only the country code and the two variants EURO and PRE_EURO are
  135. * recognized.
  136. * @param isoCode the three-letter ISO 4217 currency code
  137. * @param locale the locale for which to register this currency code
  138. * @param status the in/out status code
  139. * @return a registry key that can be used to unregister this currency code, or NULL
  140. * if there was an error.
  141. * @stable ICU 2.6
  142. */
  143. U_CAPI UCurrRegistryKey U_EXPORT2
  144. ucurr_register(const UChar* isoCode,
  145. const char* locale,
  146. UErrorCode* status);
  147. /**
  148. * Unregister the previously-registered currency definitions using the
  149. * URegistryKey returned from ucurr_register. Key becomes invalid after
  150. * a successful call and should not be used again. Any currency
  151. * that might have been hidden by the original ucurr_register call is
  152. * restored.
  153. * @param key the registry key returned by a previous call to ucurr_register
  154. * @param status the in/out status code, no special meanings are assigned
  155. * @return true if the currency for this key was successfully unregistered
  156. * @stable ICU 2.6
  157. */
  158. U_CAPI UBool U_EXPORT2
  159. ucurr_unregister(UCurrRegistryKey key, UErrorCode* status);
  160. #endif /* UCONFIG_NO_SERVICE */
  161. /**
  162. * Returns the display name for the given currency in the
  163. * given locale. For example, the display name for the USD
  164. * currency object in the en_US locale is "$".
  165. * @param currency null-terminated 3-letter ISO 4217 code
  166. * @param locale locale in which to display currency
  167. * @param nameStyle selector for which kind of name to return
  168. * @param isChoiceFormat always set to false, or can be NULL;
  169. * display names are static strings;
  170. * since ICU 4.4, ChoiceFormat patterns are no longer supported
  171. * @param len fill-in parameter to receive length of result
  172. * @param ec error code
  173. * @return pointer to display string of 'len' UChars. If the resource
  174. * data contains no entry for 'currency', then 'currency' itself is
  175. * returned.
  176. * @stable ICU 2.6
  177. */
  178. U_CAPI const UChar* U_EXPORT2
  179. ucurr_getName(const UChar* currency,
  180. const char* locale,
  181. UCurrNameStyle nameStyle,
  182. UBool* isChoiceFormat,
  183. int32_t* len,
  184. UErrorCode* ec);
  185. /**
  186. * Returns the plural name for the given currency in the
  187. * given locale. For example, the plural name for the USD
  188. * currency object in the en_US locale is "US dollar" or "US dollars".
  189. * @param currency null-terminated 3-letter ISO 4217 code
  190. * @param locale locale in which to display currency
  191. * @param isChoiceFormat always set to false, or can be NULL;
  192. * display names are static strings;
  193. * since ICU 4.4, ChoiceFormat patterns are no longer supported
  194. * @param pluralCount plural count
  195. * @param len fill-in parameter to receive length of result
  196. * @param ec error code
  197. * @return pointer to display string of 'len' UChars. If the resource
  198. * data contains no entry for 'currency', then 'currency' itself is
  199. * returned.
  200. * @stable ICU 4.2
  201. */
  202. U_CAPI const UChar* U_EXPORT2
  203. ucurr_getPluralName(const UChar* currency,
  204. const char* locale,
  205. UBool* isChoiceFormat,
  206. const char* pluralCount,
  207. int32_t* len,
  208. UErrorCode* ec);
  209. /**
  210. * Returns the number of the number of fraction digits that should
  211. * be displayed for the given currency.
  212. * This is equivalent to ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
  213. *
  214. * Important: The number of fraction digits for a given currency is NOT
  215. * guaranteed to be constant across versions of ICU or CLDR. For example,
  216. * do NOT use this value as a mechanism for deciding the magnitude used
  217. * to store currency values in a database. You should use this value for
  218. * display purposes only.
  219. *
  220. * @param currency null-terminated 3-letter ISO 4217 code
  221. * @param ec input-output error code
  222. * @return a non-negative number of fraction digits to be
  223. * displayed, or 0 if there is an error
  224. * @stable ICU 3.0
  225. */
  226. U_CAPI int32_t U_EXPORT2
  227. ucurr_getDefaultFractionDigits(const UChar* currency,
  228. UErrorCode* ec);
  229. /**
  230. * Returns the number of the number of fraction digits that should
  231. * be displayed for the given currency with usage.
  232. *
  233. * Important: The number of fraction digits for a given currency is NOT
  234. * guaranteed to be constant across versions of ICU or CLDR. For example,
  235. * do NOT use this value as a mechanism for deciding the magnitude used
  236. * to store currency values in a database. You should use this value for
  237. * display purposes only.
  238. *
  239. * @param currency null-terminated 3-letter ISO 4217 code
  240. * @param usage enum usage for the currency
  241. * @param ec input-output error code
  242. * @return a non-negative number of fraction digits to be
  243. * displayed, or 0 if there is an error
  244. * @stable ICU 54
  245. */
  246. U_CAPI int32_t U_EXPORT2
  247. ucurr_getDefaultFractionDigitsForUsage(const UChar* currency,
  248. const UCurrencyUsage usage,
  249. UErrorCode* ec);
  250. /**
  251. * Returns the rounding increment for the given currency, or 0.0 if no
  252. * rounding is done by the currency.
  253. * This is equivalent to ucurr_getRoundingIncrementForUsage(currency,UCURR_USAGE_STANDARD,ec);
  254. * @param currency null-terminated 3-letter ISO 4217 code
  255. * @param ec input-output error code
  256. * @return the non-negative rounding increment, or 0.0 if none,
  257. * or 0.0 if there is an error
  258. * @stable ICU 3.0
  259. */
  260. U_CAPI double U_EXPORT2
  261. ucurr_getRoundingIncrement(const UChar* currency,
  262. UErrorCode* ec);
  263. /**
  264. * Returns the rounding increment for the given currency, or 0.0 if no
  265. * rounding is done by the currency given usage.
  266. * @param currency null-terminated 3-letter ISO 4217 code
  267. * @param usage enum usage for the currency
  268. * @param ec input-output error code
  269. * @return the non-negative rounding increment, or 0.0 if none,
  270. * or 0.0 if there is an error
  271. * @stable ICU 54
  272. */
  273. U_CAPI double U_EXPORT2
  274. ucurr_getRoundingIncrementForUsage(const UChar* currency,
  275. const UCurrencyUsage usage,
  276. UErrorCode* ec);
  277. /**
  278. * Selector constants for ucurr_openCurrencies().
  279. *
  280. * @see ucurr_openCurrencies
  281. * @stable ICU 3.2
  282. */
  283. typedef enum UCurrCurrencyType {
  284. /**
  285. * Select all ISO-4217 currency codes.
  286. * @stable ICU 3.2
  287. */
  288. UCURR_ALL = INT32_MAX,
  289. /**
  290. * Select only ISO-4217 commonly used currency codes.
  291. * These currencies can be found in common use, and they usually have
  292. * bank notes or coins associated with the currency code.
  293. * This does not include fund codes, precious metals and other
  294. * various ISO-4217 codes limited to special financial products.
  295. * @stable ICU 3.2
  296. */
  297. UCURR_COMMON = 1,
  298. /**
  299. * Select ISO-4217 uncommon currency codes.
  300. * These codes respresent fund codes, precious metals and other
  301. * various ISO-4217 codes limited to special financial products.
  302. * A fund code is a monetary resource associated with a currency.
  303. * @stable ICU 3.2
  304. */
  305. UCURR_UNCOMMON = 2,
  306. /**
  307. * Select only deprecated ISO-4217 codes.
  308. * These codes are no longer in general public use.
  309. * @stable ICU 3.2
  310. */
  311. UCURR_DEPRECATED = 4,
  312. /**
  313. * Select only non-deprecated ISO-4217 codes.
  314. * These codes are in general public use.
  315. * @stable ICU 3.2
  316. */
  317. UCURR_NON_DEPRECATED = 8
  318. } UCurrCurrencyType;
  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_COMMON|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_CAPI UEnumeration * U_EXPORT2
  329. ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode);
  330. /**
  331. * Queries if the given ISO 4217 3-letter code is available on the specified date range.
  332. *
  333. * Note: For checking availability of a currency on a specific date, specify the date on both 'from' and 'to'
  334. *
  335. * When 'from' is U_DATE_MIN and 'to' is U_DATE_MAX, this method checks if the specified currency is available any time.
  336. * If 'from' and 'to' are same UDate value, this method checks if the specified currency is available on that date.
  337. *
  338. * @param isoCode
  339. * The ISO 4217 3-letter code.
  340. *
  341. * @param from
  342. * The lower bound of the date range, inclusive. When 'from' is U_DATE_MIN, check the availability
  343. * of the currency any date before 'to'
  344. *
  345. * @param to
  346. * The upper bound of the date range, inclusive. When 'to' is U_DATE_MAX, check the availability of
  347. * the currency any date after 'from'
  348. *
  349. * @param errorCode
  350. * ICU error code
  351. *
  352. * @return true if the given ISO 4217 3-letter code is supported on the specified date range.
  353. *
  354. * @stable ICU 4.8
  355. */
  356. U_CAPI UBool U_EXPORT2
  357. ucurr_isAvailable(const UChar* isoCode,
  358. UDate from,
  359. UDate to,
  360. UErrorCode* errorCode);
  361. /**
  362. * Finds the number of valid currency codes for the
  363. * given locale and date.
  364. * @param locale the locale for which to retrieve the
  365. * currency count.
  366. * @param date the date for which to retrieve the
  367. * currency count for the given locale.
  368. * @param ec error code
  369. * @return the number of currency codes for the
  370. * given locale and date. If 0, currency
  371. * codes couldn't be found for the input
  372. * values are invalid.
  373. * @stable ICU 4.0
  374. */
  375. U_CAPI int32_t U_EXPORT2
  376. ucurr_countCurrencies(const char* locale,
  377. UDate date,
  378. UErrorCode* ec);
  379. /**
  380. * Finds a currency code for the given locale and date
  381. * @param locale the locale for which to retrieve a currency code.
  382. * Currency can be specified by the "currency" keyword
  383. * in which case it overrides the default currency code
  384. * @param date the date for which to retrieve a currency code for
  385. * the given locale.
  386. * @param index the index within the available list of currency codes
  387. * for the given locale on the given date.
  388. * @param buff fill in buffer. Can be NULL for preflighting.
  389. * @param buffCapacity capacity of the fill in buffer. Can be 0 for
  390. * preflighting. If it is non-zero, the buff parameter
  391. * must not be NULL.
  392. * @param ec error code
  393. * @return length of the currency string. It should always be 3.
  394. * If 0, currency couldn't be found or the input values are
  395. * invalid.
  396. * @stable ICU 4.0
  397. */
  398. U_CAPI int32_t U_EXPORT2
  399. ucurr_forLocaleAndDate(const char* locale,
  400. UDate date,
  401. int32_t index,
  402. UChar* buff,
  403. int32_t buffCapacity,
  404. UErrorCode* ec);
  405. /**
  406. * Given a key and a locale, returns an array of string values in a preferred
  407. * order that would make a difference. These are all and only those values where
  408. * the open (creation) of the service with the locale formed from the input locale
  409. * plus input keyword and that value has different behavior than creation with the
  410. * input locale alone.
  411. * @param key one of the keys supported by this service. For now, only
  412. * "currency" is supported.
  413. * @param locale the locale
  414. * @param commonlyUsed if set to true it will return only commonly used values
  415. * with the given locale in preferred order. Otherwise,
  416. * it will return all the available values for the locale.
  417. * @param status error status
  418. * @return a string enumeration over keyword values for the given key and the locale.
  419. * @stable ICU 4.2
  420. */
  421. U_CAPI UEnumeration* U_EXPORT2
  422. ucurr_getKeywordValuesForLocale(const char* key,
  423. const char* locale,
  424. UBool commonlyUsed,
  425. UErrorCode* status);
  426. /**
  427. * Returns the ISO 4217 numeric code for the currency.
  428. * <p>Note: If the ISO 4217 numeric code is not assigned for the currency or
  429. * the currency is unknown, this function returns 0.
  430. *
  431. * @param currency null-terminated 3-letter ISO 4217 code
  432. * @return The ISO 4217 numeric code of the currency
  433. * @stable ICU 49
  434. */
  435. U_CAPI int32_t U_EXPORT2
  436. ucurr_getNumericCode(const UChar* currency);
  437. #endif /* #if !UCONFIG_NO_FORMATTING */
  438. #endif