ucurr.h 15 KB

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