unum.h 48 KB

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