ucurr.h 15 KB

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