PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/i18n/unicode/ucurr.h

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