ucurr.h 15 KB

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