unum.h 49 KB

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