unum.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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) 1997-2015, International Business Machines Corporation and others.
  6. * All Rights Reserved.
  7. * Modification History:
  8. *
  9. * Date Name Description
  10. * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
  11. *******************************************************************************
  12. */
  13. #ifndef _UNUM
  14. #define _UNUM
  15. #include "unicode/utypes.h"
  16. #if !UCONFIG_NO_FORMATTING
  17. #include "unicode/localpointer.h"
  18. #include "unicode/uloc.h"
  19. #include "unicode/ucurr.h"
  20. #include "unicode/umisc.h"
  21. #include "unicode/parseerr.h"
  22. #include "unicode/uformattable.h"
  23. #include "unicode/udisplaycontext.h"
  24. /**
  25. * \file
  26. * \brief C API: NumberFormat
  27. *
  28. * <h2> Number Format C API </h2>
  29. *
  30. * Number Format C API Provides functions for
  31. * formatting and parsing a number. Also provides methods for
  32. * determining which locales have number formats, and what their names
  33. * are.
  34. * <P>
  35. * UNumberFormat helps you to format and parse numbers for any locale.
  36. * Your code can be completely independent of the locale conventions
  37. * for decimal points, thousands-separators, or even the particular
  38. * decimal digits used, or whether the number format is even decimal.
  39. * There are different number format styles like decimal, currency,
  40. * percent and spellout.
  41. * <P>
  42. * To format a number for the current Locale, use one of the static
  43. * factory methods:
  44. * <pre>
  45. * \code
  46. * UChar myString[20];
  47. * double myNumber = 7.0;
  48. * UErrorCode status = U_ZERO_ERROR;
  49. * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
  50. * unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
  51. * printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
  52. * \endcode
  53. * </pre>
  54. * If you are formatting multiple numbers, it is more efficient to get
  55. * the format and use it multiple times so that the system doesn't
  56. * have to fetch the information about the local language and country
  57. * conventions multiple times.
  58. * <pre>
  59. * \code
  60. * uint32_t i, resultlength, reslenneeded;
  61. * UErrorCode status = U_ZERO_ERROR;
  62. * UFieldPosition pos;
  63. * uint32_t a[] = { 123, 3333, -1234567 };
  64. * const uint32_t a_len = sizeof(a) / sizeof(a[0]);
  65. * UNumberFormat* nf;
  66. * UChar* result = NULL;
  67. *
  68. * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
  69. * for (i = 0; i < a_len; i++) {
  70. * resultlength=0;
  71. * reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
  72. * result = NULL;
  73. * if(status==U_BUFFER_OVERFLOW_ERROR){
  74. * status=U_ZERO_ERROR;
  75. * resultlength=reslenneeded+1;
  76. * result=(UChar*)malloc(sizeof(UChar) * resultlength);
  77. * unum_format(nf, a[i], result, resultlength, &pos, &status);
  78. * }
  79. * printf( " Example 2: %s\n", austrdup(result));
  80. * free(result);
  81. * }
  82. * \endcode
  83. * </pre>
  84. * To format a number for a different Locale, specify it in the
  85. * call to unum_open().
  86. * <pre>
  87. * \code
  88. * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
  89. * \endcode
  90. * </pre>
  91. * You can use a NumberFormat API unum_parse() to parse.
  92. * <pre>
  93. * \code
  94. * UErrorCode status = U_ZERO_ERROR;
  95. * int32_t pos=0;
  96. * int32_t num;
  97. * num = unum_parse(nf, str, u_strlen(str), &pos, &status);
  98. * \endcode
  99. * </pre>
  100. * Use UNUM_DECIMAL to get the normal number format for that country.
  101. * There are other static options available. Use UNUM_CURRENCY
  102. * to get the currency number format for that country. Use UNUM_PERCENT
  103. * to get a format for displaying percentages. With this format, a
  104. * fraction from 0.53 is displayed as 53%.
  105. * <P>
  106. * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat
  107. * formatter. The pattern must conform to the syntax defined for those
  108. * formatters.
  109. * <P>
  110. * You can also control the display of numbers with such function as
  111. * unum_getAttributes() and unum_setAttributes(), which let you set the
  112. * miminum fraction digits, grouping, etc.
  113. * @see UNumberFormatAttributes for more details
  114. * <P>
  115. * You can also use forms of the parse and format methods with
  116. * ParsePosition and UFieldPosition to allow you to:
  117. * <ul type=round>
  118. * <li>(a) progressively parse through pieces of a string.
  119. * <li>(b) align the decimal point and other areas.
  120. * </ul>
  121. * <p>
  122. * It is also possible to change or set the symbols used for a particular
  123. * locale like the currency symbol, the grouping seperator , monetary seperator
  124. * etc by making use of functions unum_setSymbols() and unum_getSymbols().
  125. */
  126. /** A number formatter.
  127. * For usage in C programs.
  128. * @stable ICU 2.0
  129. */
  130. typedef void* UNumberFormat;
  131. /** The possible number format styles.
  132. * @stable ICU 2.0
  133. */
  134. typedef enum UNumberFormatStyle {
  135. /**
  136. * Decimal format defined by a pattern string.
  137. * @stable ICU 3.0
  138. */
  139. UNUM_PATTERN_DECIMAL=0,
  140. /**
  141. * Decimal format ("normal" style).
  142. * @stable ICU 2.0
  143. */
  144. UNUM_DECIMAL=1,
  145. /**
  146. * Currency format (generic).
  147. * Defaults to UNUM_CURRENCY_STANDARD style
  148. * (using currency symbol, e.g., "$1.00", with non-accounting
  149. * style for negative values e.g. using minus sign).
  150. * The specific style may be specified using the -cf- locale key.
  151. * @stable ICU 2.0
  152. */
  153. UNUM_CURRENCY=2,
  154. /**
  155. * Percent format
  156. * @stable ICU 2.0
  157. */
  158. UNUM_PERCENT=3,
  159. /**
  160. * Scientific format
  161. * @stable ICU 2.1
  162. */
  163. UNUM_SCIENTIFIC=4,
  164. /**
  165. * Spellout rule-based format. The default ruleset can be specified/changed using
  166. * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
  167. * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
  168. * @stable ICU 2.0
  169. */
  170. UNUM_SPELLOUT=5,
  171. /**
  172. * Ordinal rule-based format . The default ruleset can be specified/changed using
  173. * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
  174. * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
  175. * @stable ICU 3.0
  176. */
  177. UNUM_ORDINAL=6,
  178. /**
  179. * Duration rule-based format
  180. * @stable ICU 3.0
  181. */
  182. UNUM_DURATION=7,
  183. /**
  184. * Numbering system rule-based format
  185. * @stable ICU 4.2
  186. */
  187. UNUM_NUMBERING_SYSTEM=8,
  188. /**
  189. * Rule-based format defined by a pattern string.
  190. * @stable ICU 3.0
  191. */
  192. UNUM_PATTERN_RULEBASED=9,
  193. /**
  194. * Currency format with an ISO currency code, e.g., "USD1.00".
  195. * @stable ICU 4.8
  196. */
  197. UNUM_CURRENCY_ISO=10,
  198. /**
  199. * Currency format with a pluralized currency name,
  200. * e.g., "1.00 US dollar" and "3.00 US dollars".
  201. * @stable ICU 4.8
  202. */
  203. UNUM_CURRENCY_PLURAL=11,
  204. /**
  205. * Currency format for accounting, e.g., "($3.00)" for
  206. * negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}).
  207. * Overrides any style specified using -cf- key in locale.
  208. * @stable ICU 53
  209. */
  210. UNUM_CURRENCY_ACCOUNTING=12,
  211. /**
  212. * Currency format with a currency symbol given CASH usage, e.g.,
  213. * "NT$3" instead of "NT$3.23".
  214. * @stable ICU 54
  215. */
  216. UNUM_CASH_CURRENCY=13,
  217. /**
  218. * Decimal format expressed using compact notation
  219. * (short form, corresponds to UNumberCompactStyle=UNUM_SHORT)
  220. * e.g. "23K", "45B"
  221. * @stable ICU 56
  222. */
  223. UNUM_DECIMAL_COMPACT_SHORT=14,
  224. /**
  225. * Decimal format expressed using compact notation
  226. * (long form, corresponds to UNumberCompactStyle=UNUM_LONG)
  227. * e.g. "23 thousand", "45 billion"
  228. * @stable ICU 56
  229. */
  230. UNUM_DECIMAL_COMPACT_LONG=15,
  231. /**
  232. * Currency format with a currency symbol, e.g., "$1.00",
  233. * using non-accounting style for negative values (e.g. minus sign).
  234. * Overrides any style specified using -cf- key in locale.
  235. * @stable ICU 56
  236. */
  237. UNUM_CURRENCY_STANDARD=16,
  238. #ifndef U_HIDE_DEPRECATED_API
  239. /**
  240. * One more than the highest normal UNumberFormatStyle value.
  241. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  242. */
  243. UNUM_FORMAT_STYLE_COUNT=17,
  244. #endif // U_HIDE_DEPRECATED_API
  245. /**
  246. * Default format
  247. * @stable ICU 2.0
  248. */
  249. UNUM_DEFAULT = UNUM_DECIMAL,
  250. /**
  251. * Alias for UNUM_PATTERN_DECIMAL
  252. * @stable ICU 3.0
  253. */
  254. UNUM_IGNORE = UNUM_PATTERN_DECIMAL
  255. } UNumberFormatStyle;
  256. /** The possible number format rounding modes.
  257. * @stable ICU 2.0
  258. */
  259. typedef enum UNumberFormatRoundingMode {
  260. UNUM_ROUND_CEILING,
  261. UNUM_ROUND_FLOOR,
  262. UNUM_ROUND_DOWN,
  263. UNUM_ROUND_UP,
  264. /**
  265. * Half-even rounding
  266. * @stable, ICU 3.8
  267. */
  268. UNUM_ROUND_HALFEVEN,
  269. #ifndef U_HIDE_DEPRECATED_API
  270. /**
  271. * Half-even rounding, misspelled name
  272. * @deprecated, ICU 3.8
  273. */
  274. UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN,
  275. #endif /* U_HIDE_DEPRECATED_API */
  276. UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
  277. UNUM_ROUND_HALFUP,
  278. /**
  279. * ROUND_UNNECESSARY reports an error if formatted result is not exact.
  280. * @stable ICU 4.8
  281. */
  282. UNUM_ROUND_UNNECESSARY
  283. } UNumberFormatRoundingMode;
  284. /** The possible number format pad positions.
  285. * @stable ICU 2.0
  286. */
  287. typedef enum UNumberFormatPadPosition {
  288. UNUM_PAD_BEFORE_PREFIX,
  289. UNUM_PAD_AFTER_PREFIX,
  290. UNUM_PAD_BEFORE_SUFFIX,
  291. UNUM_PAD_AFTER_SUFFIX
  292. } UNumberFormatPadPosition;
  293. /**
  294. * Constants for specifying short or long format.
  295. * @stable ICU 51
  296. */
  297. typedef enum UNumberCompactStyle {
  298. /** @stable ICU 51 */
  299. UNUM_SHORT,
  300. /** @stable ICU 51 */
  301. UNUM_LONG
  302. /** @stable ICU 51 */
  303. } UNumberCompactStyle;
  304. /**
  305. * Constants for specifying currency spacing
  306. * @stable ICU 4.8
  307. */
  308. enum UCurrencySpacing {
  309. /** @stable ICU 4.8 */
  310. UNUM_CURRENCY_MATCH,
  311. /** @stable ICU 4.8 */
  312. UNUM_CURRENCY_SURROUNDING_MATCH,
  313. /** @stable ICU 4.8 */
  314. UNUM_CURRENCY_INSERT,
  315. // Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
  316. // it is needed for layout of DecimalFormatSymbols object.
  317. /**
  318. * One more than the highest normal UCurrencySpacing value.
  319. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  320. */
  321. UNUM_CURRENCY_SPACING_COUNT
  322. };
  323. typedef enum UCurrencySpacing UCurrencySpacing; /**< @stable ICU 4.8 */
  324. /**
  325. * FieldPosition and UFieldPosition selectors for format fields
  326. * defined by NumberFormat and UNumberFormat.
  327. * @stable ICU 49
  328. */
  329. typedef enum UNumberFormatFields {
  330. /** @stable ICU 49 */
  331. UNUM_INTEGER_FIELD,
  332. /** @stable ICU 49 */
  333. UNUM_FRACTION_FIELD,
  334. /** @stable ICU 49 */
  335. UNUM_DECIMAL_SEPARATOR_FIELD,
  336. /** @stable ICU 49 */
  337. UNUM_EXPONENT_SYMBOL_FIELD,
  338. /** @stable ICU 49 */
  339. UNUM_EXPONENT_SIGN_FIELD,
  340. /** @stable ICU 49 */
  341. UNUM_EXPONENT_FIELD,
  342. /** @stable ICU 49 */
  343. UNUM_GROUPING_SEPARATOR_FIELD,
  344. /** @stable ICU 49 */
  345. UNUM_CURRENCY_FIELD,
  346. /** @stable ICU 49 */
  347. UNUM_PERCENT_FIELD,
  348. /** @stable ICU 49 */
  349. UNUM_PERMILL_FIELD,
  350. /** @stable ICU 49 */
  351. UNUM_SIGN_FIELD,
  352. #ifndef U_HIDE_DEPRECATED_API
  353. /**
  354. * One more than the highest normal UNumberFormatFields value.
  355. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  356. */
  357. UNUM_FIELD_COUNT
  358. #endif // U_HIDE_DEPRECATED_API
  359. } UNumberFormatFields;
  360. /**
  361. * Create and return a new UNumberFormat for formatting and parsing
  362. * numbers. A UNumberFormat may be used to format numbers by calling
  363. * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
  364. * The caller must call {@link #unum_close } when done to release resources
  365. * used by this object.
  366. * @param style The type of number format to open: one of
  367. * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC,
  368. * UNUM_CURRENCY_ISO, UNUM_CURRENCY_PLURAL, UNUM_SPELLOUT,
  369. * UNUM_ORDINAL, UNUM_DURATION, UNUM_NUMBERING_SYSTEM,
  370. * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
  371. * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
  372. * number format is opened using the given pattern, which must conform
  373. * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
  374. * respectively.
  375. * @param pattern A pattern specifying the format to use.
  376. * This parameter is ignored unless the style is
  377. * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
  378. * @param patternLength The number of characters in the pattern, or -1
  379. * if null-terminated. This parameter is ignored unless the style is
  380. * UNUM_PATTERN.
  381. * @param locale A locale identifier to use to determine formatting
  382. * and parsing conventions, or NULL to use the default locale.
  383. * @param parseErr A pointer to a UParseError struct to receive the
  384. * details of any parsing errors, or NULL if no parsing error details
  385. * are desired.
  386. * @param status A pointer to an input-output UErrorCode.
  387. * @return A pointer to a newly created UNumberFormat, or NULL if an
  388. * error occurred.
  389. * @see unum_close
  390. * @see DecimalFormat
  391. * @stable ICU 2.0
  392. */
  393. U_STABLE UNumberFormat* U_EXPORT2
  394. unum_open( UNumberFormatStyle style,
  395. const UChar* pattern,
  396. int32_t patternLength,
  397. const char* locale,
  398. UParseError* parseErr,
  399. UErrorCode* status);
  400. /**
  401. * Close a UNumberFormat.
  402. * Once closed, a UNumberFormat may no longer be used.
  403. * @param fmt The formatter to close.
  404. * @stable ICU 2.0
  405. */
  406. U_STABLE void U_EXPORT2
  407. unum_close(UNumberFormat* fmt);
  408. #if U_SHOW_CPLUSPLUS_API
  409. U_NAMESPACE_BEGIN
  410. /**
  411. * \class LocalUNumberFormatPointer
  412. * "Smart pointer" class, closes a UNumberFormat via unum_close().
  413. * For most methods see the LocalPointerBase base class.
  414. *
  415. * @see LocalPointerBase
  416. * @see LocalPointer
  417. * @stable ICU 4.4
  418. */
  419. U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
  420. U_NAMESPACE_END
  421. #endif
  422. /**
  423. * Open a copy of a UNumberFormat.
  424. * This function performs a deep copy.
  425. * @param fmt The format to copy
  426. * @param status A pointer to an UErrorCode to receive any errors.
  427. * @return A pointer to a UNumberFormat identical to fmt.
  428. * @stable ICU 2.0
  429. */
  430. U_STABLE UNumberFormat* U_EXPORT2
  431. unum_clone(const UNumberFormat *fmt,
  432. UErrorCode *status);
  433. /**
  434. * Format an integer using a UNumberFormat.
  435. * The integer will be formatted according to the UNumberFormat's locale.
  436. * @param fmt The formatter to use.
  437. * @param number The number to format.
  438. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  439. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  440. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  441. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  442. * @param resultLength The maximum size of result.
  443. * @param pos A pointer to a UFieldPosition. On input, position->field
  444. * is read. On output, position->beginIndex and position->endIndex indicate
  445. * the beginning and ending indices of field number position->field, if such
  446. * a field exists. This parameter may be NULL, in which case no field
  447. * @param status A pointer to an UErrorCode to receive any errors
  448. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  449. * @see unum_formatInt64
  450. * @see unum_formatDouble
  451. * @see unum_parse
  452. * @see unum_parseInt64
  453. * @see unum_parseDouble
  454. * @see UFieldPosition
  455. * @stable ICU 2.0
  456. */
  457. U_STABLE int32_t U_EXPORT2
  458. unum_format( const UNumberFormat* fmt,
  459. int32_t number,
  460. UChar* result,
  461. int32_t resultLength,
  462. UFieldPosition *pos,
  463. UErrorCode* status);
  464. /**
  465. * Format an int64 using a UNumberFormat.
  466. * The int64 will be formatted according to the UNumberFormat's locale.
  467. * @param fmt The formatter to use.
  468. * @param number The number to format.
  469. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  470. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  471. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  472. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  473. * @param resultLength The maximum size of result.
  474. * @param pos A pointer to a UFieldPosition. On input, position->field
  475. * is read. On output, position->beginIndex and position->endIndex indicate
  476. * the beginning and ending indices of field number position->field, if such
  477. * a field exists. This parameter may be NULL, in which case no field
  478. * @param status A pointer to an UErrorCode to receive any errors
  479. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  480. * @see unum_format
  481. * @see unum_formatDouble
  482. * @see unum_parse
  483. * @see unum_parseInt64
  484. * @see unum_parseDouble
  485. * @see UFieldPosition
  486. * @stable ICU 2.0
  487. */
  488. U_STABLE int32_t U_EXPORT2
  489. unum_formatInt64(const UNumberFormat *fmt,
  490. int64_t number,
  491. UChar* result,
  492. int32_t resultLength,
  493. UFieldPosition *pos,
  494. UErrorCode* status);
  495. /**
  496. * Format a double using a UNumberFormat.
  497. * The double will be formatted according to the UNumberFormat's locale.
  498. * @param fmt The formatter to use.
  499. * @param number The number to format.
  500. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  501. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  502. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  503. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  504. * @param resultLength The maximum size of result.
  505. * @param pos A pointer to a UFieldPosition. On input, position->field
  506. * is read. On output, position->beginIndex and position->endIndex indicate
  507. * the beginning and ending indices of field number position->field, if such
  508. * a field exists. This parameter may be NULL, in which case no field
  509. * @param status A pointer to an UErrorCode to receive any errors
  510. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  511. * @see unum_format
  512. * @see unum_formatInt64
  513. * @see unum_parse
  514. * @see unum_parseInt64
  515. * @see unum_parseDouble
  516. * @see UFieldPosition
  517. * @stable ICU 2.0
  518. */
  519. U_STABLE int32_t U_EXPORT2
  520. unum_formatDouble( const UNumberFormat* fmt,
  521. double number,
  522. UChar* result,
  523. int32_t resultLength,
  524. UFieldPosition *pos, /* 0 if ignore */
  525. UErrorCode* status);
  526. /**
  527. * Format a decimal number using a UNumberFormat.
  528. * The number will be formatted according to the UNumberFormat's locale.
  529. * The syntax of the input number is a "numeric string"
  530. * as defined in the Decimal Arithmetic Specification, available at
  531. * http://speleotrove.com/decimal
  532. * @param fmt The formatter to use.
  533. * @param number The number to format.
  534. * @param length The length of the input number, or -1 if the input is nul-terminated.
  535. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  536. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  537. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  538. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  539. * @param resultLength The maximum size of result.
  540. * @param pos A pointer to a UFieldPosition. On input, position->field
  541. * is read. On output, position->beginIndex and position->endIndex indicate
  542. * the beginning and ending indices of field number position->field, if such
  543. * a field exists. This parameter may be NULL, in which case it is ignored.
  544. * @param status A pointer to an UErrorCode to receive any errors
  545. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  546. * @see unum_format
  547. * @see unum_formatInt64
  548. * @see unum_parse
  549. * @see unum_parseInt64
  550. * @see unum_parseDouble
  551. * @see UFieldPosition
  552. * @stable ICU 4.4
  553. */
  554. U_STABLE int32_t U_EXPORT2
  555. unum_formatDecimal( const UNumberFormat* fmt,
  556. const char * number,
  557. int32_t length,
  558. UChar* result,
  559. int32_t resultLength,
  560. UFieldPosition *pos, /* 0 if ignore */
  561. UErrorCode* status);
  562. /**
  563. * Format a double currency amount using a UNumberFormat.
  564. * The double will be formatted according to the UNumberFormat's locale.
  565. * @param fmt the formatter to use
  566. * @param number the number to format
  567. * @param currency the 3-letter null-terminated ISO 4217 currency code
  568. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  569. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  570. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  571. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  572. * @param resultLength the maximum number of UChars to write to result
  573. * @param pos a pointer to a UFieldPosition. On input,
  574. * position->field is read. On output, position->beginIndex and
  575. * position->endIndex indicate the beginning and ending indices of
  576. * field number position->field, if such a field exists. This
  577. * parameter may be NULL, in which case it is ignored.
  578. * @param status a pointer to an input-output UErrorCode
  579. * @return the total buffer size needed; if greater than resultLength,
  580. * the output was truncated.
  581. * @see unum_formatDouble
  582. * @see unum_parseDoubleCurrency
  583. * @see UFieldPosition
  584. * @stable ICU 3.0
  585. */
  586. U_STABLE int32_t U_EXPORT2
  587. unum_formatDoubleCurrency(const UNumberFormat* fmt,
  588. double number,
  589. UChar* currency,
  590. UChar* result,
  591. int32_t resultLength,
  592. UFieldPosition* pos,
  593. UErrorCode* status);
  594. /**
  595. * Format a UFormattable into a string.
  596. * @param fmt the formatter to use
  597. * @param number the number to format, as a UFormattable
  598. * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
  599. * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
  600. * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
  601. * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  602. * @param resultLength the maximum number of UChars to write to result
  603. * @param pos a pointer to a UFieldPosition. On input,
  604. * position->field is read. On output, position->beginIndex and
  605. * position->endIndex indicate the beginning and ending indices of
  606. * field number position->field, if such a field exists. This
  607. * parameter may be NULL, in which case it is ignored.
  608. * @param status a pointer to an input-output UErrorCode
  609. * @return the total buffer size needed; if greater than resultLength,
  610. * the output was truncated. Will return 0 on error.
  611. * @see unum_parseToUFormattable
  612. * @stable ICU 52
  613. */
  614. U_STABLE int32_t U_EXPORT2
  615. unum_formatUFormattable(const UNumberFormat* fmt,
  616. const UFormattable *number,
  617. UChar *result,
  618. int32_t resultLength,
  619. UFieldPosition *pos,
  620. UErrorCode *status);
  621. /**
  622. * Parse a string into an integer using a UNumberFormat.
  623. * The string will be parsed according to the UNumberFormat's locale.
  624. * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
  625. * and UNUM_DECIMAL_COMPACT_LONG.
  626. * @param fmt The formatter to use.
  627. * @param text The text to parse.
  628. * @param textLength The length of text, or -1 if null-terminated.
  629. * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
  630. * to begin parsing. If not NULL, on output the offset at which parsing ended.
  631. * @param status A pointer to an UErrorCode to receive any errors
  632. * @return The value of the parsed integer
  633. * @see unum_parseInt64
  634. * @see unum_parseDouble
  635. * @see unum_format
  636. * @see unum_formatInt64
  637. * @see unum_formatDouble
  638. * @stable ICU 2.0
  639. */
  640. U_STABLE int32_t U_EXPORT2
  641. unum_parse( const UNumberFormat* fmt,
  642. const UChar* text,
  643. int32_t textLength,
  644. int32_t *parsePos /* 0 = start */,
  645. UErrorCode *status);
  646. /**
  647. * Parse a string into an int64 using a UNumberFormat.
  648. * The string will be parsed according to the UNumberFormat's locale.
  649. * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
  650. * and UNUM_DECIMAL_COMPACT_LONG.
  651. * @param fmt The formatter to use.
  652. * @param text The text to parse.
  653. * @param textLength The length of text, or -1 if null-terminated.
  654. * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
  655. * to begin parsing. If not NULL, on output the offset at which parsing ended.
  656. * @param status A pointer to an UErrorCode to receive any errors
  657. * @return The value of the parsed integer
  658. * @see unum_parse
  659. * @see unum_parseDouble
  660. * @see unum_format
  661. * @see unum_formatInt64
  662. * @see unum_formatDouble
  663. * @stable ICU 2.8
  664. */
  665. U_STABLE int64_t U_EXPORT2
  666. unum_parseInt64(const UNumberFormat* fmt,
  667. const UChar* text,
  668. int32_t textLength,
  669. int32_t *parsePos /* 0 = start */,
  670. UErrorCode *status);
  671. /**
  672. * Parse a string into a double using a UNumberFormat.
  673. * The string will be parsed according to the UNumberFormat's locale.
  674. * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
  675. * and UNUM_DECIMAL_COMPACT_LONG.
  676. * @param fmt The formatter to use.
  677. * @param text The text to parse.
  678. * @param textLength The length of text, or -1 if null-terminated.
  679. * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
  680. * to begin parsing. If not NULL, on output the offset at which parsing ended.
  681. * @param status A pointer to an UErrorCode to receive any errors
  682. * @return The value of the parsed double
  683. * @see unum_parse
  684. * @see unum_parseInt64
  685. * @see unum_format
  686. * @see unum_formatInt64
  687. * @see unum_formatDouble
  688. * @stable ICU 2.0
  689. */
  690. U_STABLE double U_EXPORT2
  691. unum_parseDouble( const UNumberFormat* fmt,
  692. const UChar* text,
  693. int32_t textLength,
  694. int32_t *parsePos /* 0 = start */,
  695. UErrorCode *status);
  696. /**
  697. * Parse a number from a string into an unformatted numeric string using a UNumberFormat.
  698. * The input string will be parsed according to the UNumberFormat's locale.
  699. * The syntax of the output is a "numeric string"
  700. * as defined in the Decimal Arithmetic Specification, available at
  701. * http://speleotrove.com/decimal
  702. * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
  703. * and UNUM_DECIMAL_COMPACT_LONG.
  704. * @param fmt The formatter to use.
  705. * @param text The text to parse.
  706. * @param textLength The length of text, or -1 if null-terminated.
  707. * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
  708. * to begin parsing. If not NULL, on output the offset at which parsing ended.
  709. * @param outBuf A (char *) buffer to receive the parsed number as a string. The output string
  710. * will be nul-terminated if there is sufficient space.
  711. * @param outBufLength The size of the output buffer. May be zero, in which case
  712. * the outBuf pointer may be NULL, and the function will return the
  713. * size of the output string.
  714. * @param status A pointer to an UErrorCode to receive any errors
  715. * @return the length of the output string, not including any terminating nul.
  716. * @see unum_parse
  717. * @see unum_parseInt64
  718. * @see unum_format
  719. * @see unum_formatInt64
  720. * @see unum_formatDouble
  721. * @stable ICU 4.4
  722. */
  723. U_STABLE int32_t U_EXPORT2
  724. unum_parseDecimal(const UNumberFormat* fmt,
  725. const UChar* text,
  726. int32_t textLength,
  727. int32_t *parsePos /* 0 = start */,
  728. char *outBuf,
  729. int32_t outBufLength,
  730. UErrorCode *status);
  731. /**
  732. * Parse a string into a double and a currency using a UNumberFormat.
  733. * The string will be parsed according to the UNumberFormat's locale.
  734. * @param fmt the formatter to use
  735. * @param text the text to parse
  736. * @param textLength the length of text, or -1 if null-terminated
  737. * @param parsePos a pointer to an offset index into text at which to
  738. * begin parsing. On output, *parsePos will point after the last
  739. * parsed character. This parameter may be NULL, in which case parsing
  740. * begins at offset 0.
  741. * @param currency a pointer to the buffer to receive the parsed null-
  742. * terminated currency. This buffer must have a capacity of at least
  743. * 4 UChars.
  744. * @param status a pointer to an input-output UErrorCode
  745. * @return the parsed double
  746. * @see unum_parseDouble
  747. * @see unum_formatDoubleCurrency
  748. * @stable ICU 3.0
  749. */
  750. U_STABLE double U_EXPORT2
  751. unum_parseDoubleCurrency(const UNumberFormat* fmt,
  752. const UChar* text,
  753. int32_t textLength,
  754. int32_t* parsePos, /* 0 = start */
  755. UChar* currency,
  756. UErrorCode* status);
  757. /**
  758. * Parse a UChar string into a UFormattable.
  759. * Example code:
  760. * \snippet test/cintltst/cnumtst.c unum_parseToUFormattable
  761. * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
  762. * and UNUM_DECIMAL_COMPACT_LONG.
  763. * @param fmt the formatter to use
  764. * @param result the UFormattable to hold the result. If NULL, a new UFormattable will be allocated (which the caller must close with ufmt_close).
  765. * @param text the text to parse
  766. * @param textLength the length of text, or -1 if null-terminated
  767. * @param parsePos a pointer to an offset index into text at which to
  768. * begin parsing. On output, *parsePos will point after the last
  769. * parsed character. This parameter may be NULL in which case parsing
  770. * begins at offset 0.
  771. * @param status a pointer to an input-output UErrorCode
  772. * @return the UFormattable. Will be ==result unless NULL was passed in for result, in which case it will be the newly opened UFormattable.
  773. * @see ufmt_getType
  774. * @see ufmt_close
  775. * @stable ICU 52
  776. */
  777. U_STABLE UFormattable* U_EXPORT2
  778. unum_parseToUFormattable(const UNumberFormat* fmt,
  779. UFormattable *result,
  780. const UChar* text,
  781. int32_t textLength,
  782. int32_t* parsePos, /* 0 = start */
  783. UErrorCode* status);
  784. /**
  785. * Set the pattern used by a UNumberFormat. This can only be used
  786. * on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR
  787. * in the status.
  788. * @param format The formatter to set.
  789. * @param localized TRUE if the pattern is localized, FALSE otherwise.
  790. * @param pattern The new pattern
  791. * @param patternLength The length of pattern, or -1 if null-terminated.
  792. * @param parseError A pointer to UParseError to recieve information
  793. * about errors occurred during parsing, or NULL if no parse error
  794. * information is desired.
  795. * @param status A pointer to an input-output UErrorCode.
  796. * @see unum_toPattern
  797. * @see DecimalFormat
  798. * @stable ICU 2.0
  799. */
  800. U_STABLE void U_EXPORT2
  801. unum_applyPattern( UNumberFormat *format,
  802. UBool localized,
  803. const UChar *pattern,
  804. int32_t patternLength,
  805. UParseError *parseError,
  806. UErrorCode *status
  807. );
  808. /**
  809. * Get a locale for which decimal formatting patterns are available.
  810. * A UNumberFormat in a locale returned by this function will perform the correct
  811. * formatting and parsing for the locale. The results of this call are not
  812. * valid for rule-based number formats.
  813. * @param localeIndex The index of the desired locale.
  814. * @return A locale for which number formatting patterns are available, or 0 if none.
  815. * @see unum_countAvailable
  816. * @stable ICU 2.0
  817. */
  818. U_STABLE const char* U_EXPORT2
  819. unum_getAvailable(int32_t localeIndex);
  820. /**
  821. * Determine how many locales have decimal formatting patterns available. The
  822. * results of this call are not valid for rule-based number formats.
  823. * This function is useful for determining the loop ending condition for
  824. * calls to {@link #unum_getAvailable }.
  825. * @return The number of locales for which decimal formatting patterns are available.
  826. * @see unum_getAvailable
  827. * @stable ICU 2.0
  828. */
  829. U_STABLE int32_t U_EXPORT2
  830. unum_countAvailable(void);
  831. #if UCONFIG_HAVE_PARSEALLINPUT
  832. /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
  833. /**
  834. * @internal
  835. */
  836. typedef enum UNumberFormatAttributeValue {
  837. #ifndef U_HIDE_INTERNAL_API
  838. /** @internal */
  839. UNUM_NO = 0,
  840. /** @internal */
  841. UNUM_YES = 1,
  842. /** @internal */
  843. UNUM_MAYBE = 2
  844. #else
  845. /** @internal */
  846. UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
  847. #endif /* U_HIDE_INTERNAL_API */
  848. } UNumberFormatAttributeValue;
  849. #endif
  850. /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
  851. typedef enum UNumberFormatAttribute {
  852. /** Parse integers only */
  853. UNUM_PARSE_INT_ONLY,
  854. /** Use grouping separator */
  855. UNUM_GROUPING_USED,
  856. /** Always show decimal point */
  857. UNUM_DECIMAL_ALWAYS_SHOWN,
  858. /** Maximum integer digits */
  859. UNUM_MAX_INTEGER_DIGITS,
  860. /** Minimum integer digits */
  861. UNUM_MIN_INTEGER_DIGITS,
  862. /** Integer digits */
  863. UNUM_INTEGER_DIGITS,
  864. /** Maximum fraction digits */
  865. UNUM_MAX_FRACTION_DIGITS,
  866. /** Minimum fraction digits */
  867. UNUM_MIN_FRACTION_DIGITS,
  868. /** Fraction digits */
  869. UNUM_FRACTION_DIGITS,
  870. /** Multiplier */
  871. UNUM_MULTIPLIER,
  872. /** Grouping size */
  873. UNUM_GROUPING_SIZE,
  874. /** Rounding Mode */
  875. UNUM_ROUNDING_MODE,
  876. /** Rounding increment */
  877. UNUM_ROUNDING_INCREMENT,
  878. /** The width to which the output of <code>format()</code> is padded. */
  879. UNUM_FORMAT_WIDTH,
  880. /** The position at which padding will take place. */
  881. UNUM_PADDING_POSITION,
  882. /** Secondary grouping size */
  883. UNUM_SECONDARY_GROUPING_SIZE,
  884. /** Use significant digits
  885. * @stable ICU 3.0 */
  886. UNUM_SIGNIFICANT_DIGITS_USED,
  887. /** Minimum significant digits
  888. * @stable ICU 3.0 */
  889. UNUM_MIN_SIGNIFICANT_DIGITS,
  890. /** Maximum significant digits
  891. * @stable ICU 3.0 */
  892. UNUM_MAX_SIGNIFICANT_DIGITS,
  893. /** Lenient parse mode used by rule-based formats.
  894. * @stable ICU 3.0
  895. */
  896. UNUM_LENIENT_PARSE,
  897. #if UCONFIG_HAVE_PARSEALLINPUT
  898. /** Consume all input. (may use fastpath). Set to UNUM_YES (require fastpath), UNUM_NO (skip fastpath), or UNUM_MAYBE (heuristic).
  899. * This is an internal ICU API. Do not use.
  900. * @internal
  901. */
  902. UNUM_PARSE_ALL_INPUT = 20,
  903. #endif
  904. /**
  905. * Scale, which adjusts the position of the
  906. * decimal point when formatting. Amounts will be multiplied by 10 ^ (scale)
  907. * before they are formatted. The default value for the scale is 0 ( no adjustment ).
  908. *
  909. * <p>Example: setting the scale to 3, 123 formats as "123,000"
  910. * <p>Example: setting the scale to -4, 123 formats as "0.0123"
  911. *
  912. * @stable ICU 51 */
  913. UNUM_SCALE = 21,
  914. #ifndef U_HIDE_INTERNAL_API
  915. /**
  916. * Minimum grouping digits, technology preview.
  917. * See DecimalFormat::getMinimumGroupingDigits().
  918. *
  919. * @internal technology preview
  920. */
  921. UNUM_MINIMUM_GROUPING_DIGITS = 22,
  922. /* TODO: test C API when it becomes @draft */
  923. #endif /* U_HIDE_INTERNAL_API */
  924. /**
  925. * if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose,
  926. * otherwise it is UNUM_CURRENCY_CASH purpose
  927. * Default: 0 (UNUM_CURRENCY_STANDARD purpose)
  928. * @stable ICU 54
  929. */
  930. UNUM_CURRENCY_USAGE = 23,
  931. /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
  932. /** One below the first bitfield-boolean item.
  933. * All items after this one are stored in boolean form.
  934. * @internal */
  935. UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF,
  936. /** If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating.
  937. * For example, formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing.
  938. * Default: 0 (not set)
  939. * @stable ICU 50
  940. */
  941. UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000,
  942. /**
  943. * if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed. If the pattern does contain an exponent, this attribute has no effect.
  944. * Has no effect on formatting.
  945. * Default: 0 (unset)
  946. * @stable ICU 50
  947. */
  948. UNUM_PARSE_NO_EXPONENT,
  949. /**
  950. * if this attribute is set to 1, specifies that, if the pattern contains a
  951. * decimal mark the input is required to have one. If this attribute is set to 0,
  952. * specifies that input does not have to contain a decimal mark.
  953. * Has no effect on formatting.
  954. * Default: 0 (unset)
  955. * @stable ICU 54
  956. */
  957. UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002,
  958. /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
  959. /** Limit of boolean attributes.
  960. * @internal */
  961. UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003
  962. } UNumberFormatAttribute;
  963. /**
  964. * Get a numeric attribute associated with a UNumberFormat.
  965. * An example of a numeric attribute is the number of integer digits a formatter will produce.
  966. * @param fmt The formatter to query.
  967. * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
  968. * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
  969. * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
  970. * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
  971. * UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
  972. * @return The value of attr.
  973. * @see unum_setAttribute
  974. * @see unum_getDoubleAttribute
  975. * @see unum_setDoubleAttribute
  976. * @see unum_getTextAttribute
  977. * @see unum_setTextAttribute
  978. * @stable ICU 2.0
  979. */
  980. U_STABLE int32_t U_EXPORT2
  981. unum_getAttribute(const UNumberFormat* fmt,
  982. UNumberFormatAttribute attr);
  983. /**
  984. * Set a numeric attribute associated with a UNumberFormat.
  985. * An example of a numeric attribute is the number of integer digits a formatter will produce. If the
  986. * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
  987. * the lenient-parse attribute.
  988. * @param fmt The formatter to set.
  989. * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
  990. * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
  991. * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
  992. * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
  993. * UNUM_LENIENT_PARSE, UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
  994. * @param newValue The new value of attr.
  995. * @see unum_getAttribute
  996. * @see unum_getDoubleAttribute
  997. * @see unum_setDoubleAttribute
  998. * @see unum_getTextAttribute
  999. * @see unum_setTextAttribute
  1000. * @stable ICU 2.0
  1001. */
  1002. U_STABLE void U_EXPORT2
  1003. unum_setAttribute( UNumberFormat* fmt,
  1004. UNumberFormatAttribute attr,
  1005. int32_t newValue);
  1006. /**
  1007. * Get a numeric attribute associated with a UNumberFormat.
  1008. * An example of a numeric attribute is the number of integer digits a formatter will produce.
  1009. * If the formatter does not understand the attribute, -1 is returned.
  1010. * @param fmt The formatter to query.
  1011. * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
  1012. * @return The value of attr.
  1013. * @see unum_getAttribute
  1014. * @see unum_setAttribute
  1015. * @see unum_setDoubleAttribute
  1016. * @see unum_getTextAttribute
  1017. * @see unum_setTextAttribute
  1018. * @stable ICU 2.0
  1019. */
  1020. U_STABLE double U_EXPORT2
  1021. unum_getDoubleAttribute(const UNumberFormat* fmt,
  1022. UNumberFormatAttribute attr);
  1023. /**
  1024. * Set a numeric attribute associated with a UNumberFormat.
  1025. * An example of a numeric attribute is the number of integer digits a formatter will produce.
  1026. * If the formatter does not understand the attribute, this call is ignored.
  1027. * @param fmt The formatter to set.
  1028. * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
  1029. * @param newValue The new value of attr.
  1030. * @see unum_getAttribute
  1031. * @see unum_setAttribute
  1032. * @see unum_getDoubleAttribute
  1033. * @see unum_getTextAttribute
  1034. * @see unum_setTextAttribute
  1035. * @stable ICU 2.0
  1036. */
  1037. U_STABLE void U_EXPORT2
  1038. unum_setDoubleAttribute( UNumberFormat* fmt,
  1039. UNumberFormatAttribute attr,
  1040. double newValue);
  1041. /** The possible UNumberFormat text attributes @stable ICU 2.0*/
  1042. typedef enum UNumberFormatTextAttribute {
  1043. /** Positive prefix */
  1044. UNUM_POSITIVE_PREFIX,
  1045. /** Positive suffix */
  1046. UNUM_POSITIVE_SUFFIX,
  1047. /** Negative prefix */
  1048. UNUM_NEGATIVE_PREFIX,
  1049. /** Negative suffix */
  1050. UNUM_NEGATIVE_SUFFIX,
  1051. /** The character used to pad to the format width. */
  1052. UNUM_PADDING_CHARACTER,
  1053. /** The ISO currency code */
  1054. UNUM_CURRENCY_CODE,
  1055. /**
  1056. * The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:",
  1057. * "%spellout-ordinal-masculine-plural:", "%spellout-ordinal-feminine:", or
  1058. * "%spellout-ordinal-neuter:". The available public rulesets can be listed using
  1059. * unum_getTextAttribute with UNUM_PUBLIC_RULESETS. This is only available with
  1060. * rule-based formatters.
  1061. * @stable ICU 3.0
  1062. */
  1063. UNUM_DEFAULT_RULESET,
  1064. /**
  1065. * The public rule sets. This is only available with rule-based formatters.
  1066. * This is a read-only attribute. The public rulesets are returned as a
  1067. * single string, with each ruleset name delimited by ';' (semicolon). See the
  1068. * CLDR LDML spec for more information about RBNF rulesets:
  1069. * http://www.unicode.org/reports/tr35/tr35-numbers.html#Rule-Based_Number_Formatting
  1070. * @stable ICU 3.0
  1071. */
  1072. UNUM_PUBLIC_RULESETS
  1073. } UNumberFormatTextAttribute;
  1074. /**
  1075. * Get a text attribute associated with a UNumberFormat.
  1076. * An example of a text attribute is the suffix for positive numbers. If the formatter
  1077. * does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status.
  1078. * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
  1079. * @param fmt The formatter to query.
  1080. * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
  1081. * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
  1082. * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
  1083. * @param result A pointer to a buffer to receive the attribute.
  1084. * @param resultLength The maximum size of result.
  1085. * @param status A pointer to an UErrorCode to receive any errors
  1086. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  1087. * @see unum_setTextAttribute
  1088. * @see unum_getAttribute
  1089. * @see unum_setAttribute
  1090. * @stable ICU 2.0
  1091. */
  1092. U_STABLE int32_t U_EXPORT2
  1093. unum_getTextAttribute( const UNumberFormat* fmt,
  1094. UNumberFormatTextAttribute tag,
  1095. UChar* result,
  1096. int32_t resultLength,
  1097. UErrorCode* status);
  1098. /**
  1099. * Set a text attribute associated with a UNumberFormat.
  1100. * An example of a text attribute is the suffix for positive numbers. Rule-based formatters
  1101. * only understand UNUM_DEFAULT_RULESET.
  1102. * @param fmt The formatter to set.
  1103. * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
  1104. * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
  1105. * or UNUM_DEFAULT_RULESET.
  1106. * @param newValue The new value of attr.
  1107. * @param newValueLength The length of newValue, or -1 if null-terminated.
  1108. * @param status A pointer to an UErrorCode to receive any errors
  1109. * @see unum_getTextAttribute
  1110. * @see unum_getAttribute
  1111. * @see unum_setAttribute
  1112. * @stable ICU 2.0
  1113. */
  1114. U_STABLE void U_EXPORT2
  1115. unum_setTextAttribute( UNumberFormat* fmt,
  1116. UNumberFormatTextAttribute tag,
  1117. const UChar* newValue,
  1118. int32_t newValueLength,
  1119. UErrorCode *status);
  1120. /**
  1121. * Extract the pattern from a UNumberFormat. The pattern will follow
  1122. * the DecimalFormat pattern syntax.
  1123. * @param fmt The formatter to query.
  1124. * @param isPatternLocalized TRUE if the pattern should be localized,
  1125. * FALSE otherwise. This is ignored if the formatter is a rule-based
  1126. * formatter.
  1127. * @param result A pointer to a buffer to receive the pattern.
  1128. * @param resultLength The maximum size of result.
  1129. * @param status A pointer to an input-output UErrorCode.
  1130. * @return The total buffer size needed; if greater than resultLength,
  1131. * the output was truncated.
  1132. * @see unum_applyPattern
  1133. * @see DecimalFormat
  1134. * @stable ICU 2.0
  1135. */
  1136. U_STABLE int32_t U_EXPORT2
  1137. unum_toPattern( const UNumberFormat* fmt,
  1138. UBool isPatternLocalized,
  1139. UChar* result,
  1140. int32_t resultLength,
  1141. UErrorCode* status);
  1142. /**
  1143. * Constants for specifying a number format symbol.
  1144. * @stable ICU 2.0
  1145. */
  1146. typedef enum UNumberFormatSymbol {
  1147. /** The decimal separator */
  1148. UNUM_DECIMAL_SEPARATOR_SYMBOL = 0,
  1149. /** The grouping separator */
  1150. UNUM_GROUPING_SEPARATOR_SYMBOL = 1,
  1151. /** The pattern separator */
  1152. UNUM_PATTERN_SEPARATOR_SYMBOL = 2,
  1153. /** The percent sign */
  1154. UNUM_PERCENT_SYMBOL = 3,
  1155. /** Zero*/
  1156. UNUM_ZERO_DIGIT_SYMBOL = 4,
  1157. /** Character representing a digit in the pattern */
  1158. UNUM_DIGIT_SYMBOL = 5,
  1159. /** The minus sign */
  1160. UNUM_MINUS_SIGN_SYMBOL = 6,
  1161. /** The plus sign */
  1162. UNUM_PLUS_SIGN_SYMBOL = 7,
  1163. /** The currency symbol */
  1164. UNUM_CURRENCY_SYMBOL = 8,
  1165. /** The international currency symbol */
  1166. UNUM_INTL_CURRENCY_SYMBOL = 9,
  1167. /** The monetary separator */
  1168. UNUM_MONETARY_SEPARATOR_SYMBOL = 10,
  1169. /** The exponential symbol */
  1170. UNUM_EXPONENTIAL_SYMBOL = 11,
  1171. /** Per mill symbol */
  1172. UNUM_PERMILL_SYMBOL = 12,
  1173. /** Escape padding character */
  1174. UNUM_PAD_ESCAPE_SYMBOL = 13,
  1175. /** Infinity symbol */
  1176. UNUM_INFINITY_SYMBOL = 14,
  1177. /** Nan symbol */
  1178. UNUM_NAN_SYMBOL = 15,
  1179. /** Significant digit symbol
  1180. * @stable ICU 3.0 */
  1181. UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16,
  1182. /** The monetary grouping separator
  1183. * @stable ICU 3.6
  1184. */
  1185. UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17,
  1186. /** One
  1187. * @stable ICU 4.6
  1188. */
  1189. UNUM_ONE_DIGIT_SYMBOL = 18,
  1190. /** Two
  1191. * @stable ICU 4.6
  1192. */
  1193. UNUM_TWO_DIGIT_SYMBOL = 19,
  1194. /** Three
  1195. * @stable ICU 4.6
  1196. */
  1197. UNUM_THREE_DIGIT_SYMBOL = 20,
  1198. /** Four
  1199. * @stable ICU 4.6
  1200. */
  1201. UNUM_FOUR_DIGIT_SYMBOL = 21,
  1202. /** Five
  1203. * @stable ICU 4.6
  1204. */
  1205. UNUM_FIVE_DIGIT_SYMBOL = 22,
  1206. /** Six
  1207. * @stable ICU 4.6
  1208. */
  1209. UNUM_SIX_DIGIT_SYMBOL = 23,
  1210. /** Seven
  1211. * @stable ICU 4.6
  1212. */
  1213. UNUM_SEVEN_DIGIT_SYMBOL = 24,
  1214. /** Eight
  1215. * @stable ICU 4.6
  1216. */
  1217. UNUM_EIGHT_DIGIT_SYMBOL = 25,
  1218. /** Nine
  1219. * @stable ICU 4.6
  1220. */
  1221. UNUM_NINE_DIGIT_SYMBOL = 26,
  1222. /** Multiplication sign
  1223. * @stable ICU 54
  1224. */
  1225. UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27,
  1226. #ifndef U_HIDE_DEPRECATED_API
  1227. /**
  1228. * One more than the highest normal UNumberFormatSymbol value.
  1229. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  1230. */
  1231. UNUM_FORMAT_SYMBOL_COUNT = 28
  1232. #endif // U_HIDE_DEPRECATED_API
  1233. } UNumberFormatSymbol;
  1234. /**
  1235. * Get a symbol associated with a UNumberFormat.
  1236. * A UNumberFormat uses symbols to represent the special locale-dependent
  1237. * characters in a number, for example the percent sign. This API is not
  1238. * supported for rule-based formatters.
  1239. * @param fmt The formatter to query.
  1240. * @param symbol The UNumberFormatSymbol constant for the symbol to get
  1241. * @param buffer The string buffer that will receive the symbol string;
  1242. * if it is NULL, then only the length of the symbol is returned
  1243. * @param size The size of the string buffer
  1244. * @param status A pointer to an UErrorCode to receive any errors
  1245. * @return The length of the symbol; the buffer is not modified if
  1246. * <code>length&gt;=size</code>
  1247. * @see unum_setSymbol
  1248. * @stable ICU 2.0
  1249. */
  1250. U_STABLE int32_t U_EXPORT2
  1251. unum_getSymbol(const UNumberFormat *fmt,
  1252. UNumberFormatSymbol symbol,
  1253. UChar *buffer,
  1254. int32_t size,
  1255. UErrorCode *status);
  1256. /**
  1257. * Set a symbol associated with a UNumberFormat.
  1258. * A UNumberFormat uses symbols to represent the special locale-dependent
  1259. * characters in a number, for example the percent sign. This API is not
  1260. * supported for rule-based formatters.
  1261. * @param fmt The formatter to set.
  1262. * @param symbol The UNumberFormatSymbol constant for the symbol to set
  1263. * @param value The string to set the symbol to
  1264. * @param length The length of the string, or -1 for a zero-terminated string
  1265. * @param status A pointer to an UErrorCode to receive any errors.
  1266. * @see unum_getSymbol
  1267. * @stable ICU 2.0
  1268. */
  1269. U_STABLE void U_EXPORT2
  1270. unum_setSymbol(UNumberFormat *fmt,
  1271. UNumberFormatSymbol symbol,
  1272. const UChar *value,
  1273. int32_t length,
  1274. UErrorCode *status);
  1275. /**
  1276. * Get the locale for this number format object.
  1277. * You can choose between valid and actual locale.
  1278. * @param fmt The formatter to get the locale from
  1279. * @param type type of the locale we're looking for (valid or actual)
  1280. * @param status error code for the operation
  1281. * @return the locale name
  1282. * @stable ICU 2.8
  1283. */
  1284. U_STABLE const char* U_EXPORT2
  1285. unum_getLocaleByType(const UNumberFormat *fmt,
  1286. ULocDataLocaleType type,
  1287. UErrorCode* status);
  1288. /**
  1289. * Set a particular UDisplayContext value in the formatter, such as
  1290. * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
  1291. * @param fmt The formatter for which to set a UDisplayContext value.
  1292. * @param value The UDisplayContext value to set.
  1293. * @param status A pointer to an UErrorCode to receive any errors
  1294. * @stable ICU 53
  1295. */
  1296. U_STABLE void U_EXPORT2
  1297. unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status);
  1298. /**
  1299. * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
  1300. * such as UDISPCTX_TYPE_CAPITALIZATION.
  1301. * @param fmt The formatter to query.
  1302. * @param type The UDisplayContextType whose value to return
  1303. * @param status A pointer to an UErrorCode to receive any errors
  1304. * @return The UDisplayContextValue for the specified type.
  1305. * @stable ICU 53
  1306. */
  1307. U_STABLE UDisplayContext U_EXPORT2
  1308. unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
  1309. #endif /* #if !UCONFIG_NO_FORMATTING */
  1310. #endif