1 /* 2 ******************************************************************************* 3 * Copyright (C) 1997-2009, 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 12 #ifndef _UNUM 13 #define _UNUM 14 15 #include "unicode/utypes.h" 16 17 #if !UCONFIG_NO_FORMATTING 18 19 #include "unicode/uloc.h" 20 #include "unicode/umisc.h" 21 #include "unicode/parseerr.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_getAttribues() and unum_setAtributes(), 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 125 /** A number formatter. 126 * For usage in C programs. 127 * @stable ICU 2.0 128 */ 129 typedef void* UNumberFormat; 130 131 /** The possible number format styles. 132 * @stable ICU 2.0 133 */ 134 typedef enum UNumberFormatStyle { 135 /** 136 * Decimal format defined by pattern 137 * @stable ICU 3.0 138 */ 139 UNUM_PATTERN_DECIMAL=0, 140 /** Decimal format */ 141 UNUM_DECIMAL=1, 142 /** Currency format */ 143 UNUM_CURRENCY, 144 /** Percent format */ 145 UNUM_PERCENT, 146 /** Scientific format */ 147 UNUM_SCIENTIFIC, 148 /** Spellout rule-based format */ 149 UNUM_SPELLOUT, 150 /** 151 * Ordinal rule-based format 152 * @stable ICU 3.0 153 */ 154 UNUM_ORDINAL, 155 /** 156 * Duration rule-based format 157 * @stable ICU 3.0 158 */ 159 UNUM_DURATION, 160 /** 161 * Numbering system rule-based format 162 * @draft ICU 4.2 163 */ 164 UNUM_NUMBERING_SYSTEM, 165 /** 166 * Rule-based format defined by pattern 167 * @stable ICU 3.0 168 */ 169 UNUM_PATTERN_RULEBASED, 170 /** Default format */ 171 UNUM_DEFAULT = UNUM_DECIMAL, 172 /** (Alias for UNUM_PATTERN_DECIMAL) */ 173 UNUM_IGNORE = UNUM_PATTERN_DECIMAL 174 } UNumberFormatStyle; 175 176 /** The possible number format rounding modes. 177 * @stable ICU 2.0 178 */ 179 typedef enum UNumberFormatRoundingMode { 180 UNUM_ROUND_CEILING, 181 UNUM_ROUND_FLOOR, 182 UNUM_ROUND_DOWN, 183 UNUM_ROUND_UP, 184 /** 185 * Half-even rounding, misspelled name 186 * @deprecated, ICU 3.8 187 */ 188 UNUM_FOUND_HALFEVEN, 189 UNUM_ROUND_HALFDOWN, 190 UNUM_ROUND_HALFUP, 191 /** 192 * Half-even rounding 193 * @stable, ICU 3.8 194 */ 195 UNUM_ROUND_HALFEVEN = UNUM_FOUND_HALFEVEN 196 } UNumberFormatRoundingMode; 197 198 /** The possible number format pad positions. 199 * @stable ICU 2.0 200 */ 201 typedef enum UNumberFormatPadPosition { 202 UNUM_PAD_BEFORE_PREFIX, 203 UNUM_PAD_AFTER_PREFIX, 204 UNUM_PAD_BEFORE_SUFFIX, 205 UNUM_PAD_AFTER_SUFFIX 206 } UNumberFormatPadPosition; 207 208 /** 209 * Create and return a new UNumberFormat for formatting and parsing 210 * numbers. A UNumberFormat may be used to format numbers by calling 211 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }. 212 * The caller must call {@link #unum_close } when done to release resources 213 * used by this object. 214 * @param style The type of number format to open: one of 215 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT, 216 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT. 217 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the 218 * number format is opened using the given pattern, which must conform 219 * to the syntax described in DecimalFormat or RuleBasedNumberFormat, 220 * respectively. 221 * @param pattern A pattern specifying the format to use. 222 * This parameter is ignored unless the style is 223 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED. 224 * @param patternLength The number of characters in the pattern, or -1 225 * if null-terminated. This parameter is ignored unless the style is 226 * UNUM_PATTERN. 227 * @param locale A locale identifier to use to determine formatting 228 * and parsing conventions, or NULL to use the default locale. 229 * @param parseErr A pointer to a UParseError struct to receive the 230 * details of any parsing errors, or NULL if no parsing error details 231 * are desired. 232 * @param status A pointer to an input-output UErrorCode. 233 * @return A pointer to a newly created UNumberFormat, or NULL if an 234 * error occurred. 235 * @see unum_close 236 * @see DecimalFormat 237 * @stable ICU 2.0 238 */ 239 U_STABLE UNumberFormat* U_EXPORT2 240 unum_open( UNumberFormatStyle style, 241 const UChar* pattern, 242 int32_t patternLength, 243 const char* locale, 244 UParseError* parseErr, 245 UErrorCode* status); 246 247 248 /** 249 * Close a UNumberFormat. 250 * Once closed, a UNumberFormat may no longer be used. 251 * @param fmt The formatter to close. 252 * @stable ICU 2.0 253 */ 254 U_STABLE void U_EXPORT2 255 unum_close(UNumberFormat* fmt); 256 257 /** 258 * Open a copy of a UNumberFormat. 259 * This function performs a deep copy. 260 * @param fmt The format to copy 261 * @param status A pointer to an UErrorCode to receive any errors. 262 * @return A pointer to a UNumberFormat identical to fmt. 263 * @stable ICU 2.0 264 */ 265 U_STABLE UNumberFormat* U_EXPORT2 266 unum_clone(const UNumberFormat *fmt, 267 UErrorCode *status); 268 269 /** 270 * Format an integer using a UNumberFormat. 271 * The integer will be formatted according to the UNumberFormat's locale. 272 * @param fmt The formatter to use. 273 * @param number The number to format. 274 * @param result A pointer to a buffer to receive the formatted number. 275 * @param resultLength The maximum size of result. 276 * @param pos A pointer to a UFieldPosition. On input, position->field 277 * is read. On output, position->beginIndex and position->endIndex indicate 278 * the beginning and ending indices of field number position->field, if such 279 * a field exists. This parameter may be NULL, in which case no field 280 * @param status A pointer to an UErrorCode to receive any errors 281 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 282 * @see unum_formatInt64 283 * @see unum_formatDouble 284 * @see unum_parse 285 * @see unum_parseInt64 286 * @see unum_parseDouble 287 * @see UFieldPosition 288 * @stable ICU 2.0 289 */ 290 U_STABLE int32_t U_EXPORT2 291 unum_format( const UNumberFormat* fmt, 292 int32_t number, 293 UChar* result, 294 int32_t resultLength, 295 UFieldPosition *pos, 296 UErrorCode* status); 297 298 /** 299 * Format an int64 using a UNumberFormat. 300 * The int64 will be formatted according to the UNumberFormat's locale. 301 * @param fmt The formatter to use. 302 * @param number The number to format. 303 * @param result A pointer to a buffer to receive the formatted number. 304 * @param resultLength The maximum size of result. 305 * @param pos A pointer to a UFieldPosition. On input, position->field 306 * is read. On output, position->beginIndex and position->endIndex indicate 307 * the beginning and ending indices of field number position->field, if such 308 * a field exists. This parameter may be NULL, in which case no field 309 * @param status A pointer to an UErrorCode to receive any errors 310 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 311 * @see unum_format 312 * @see unum_formatDouble 313 * @see unum_parse 314 * @see unum_parseInt64 315 * @see unum_parseDouble 316 * @see UFieldPosition 317 * @stable ICU 2.0 318 */ 319 U_STABLE int32_t U_EXPORT2 320 unum_formatInt64(const UNumberFormat *fmt, 321 int64_t number, 322 UChar* result, 323 int32_t resultLength, 324 UFieldPosition *pos, 325 UErrorCode* status); 326 327 /** 328 * Format a double using a UNumberFormat. 329 * The double will be formatted according to the UNumberFormat's locale. 330 * @param fmt The formatter to use. 331 * @param number The number to format. 332 * @param result A pointer to a buffer to receive the formatted number. 333 * @param resultLength The maximum size of result. 334 * @param pos A pointer to a UFieldPosition. On input, position->field 335 * is read. On output, position->beginIndex and position->endIndex indicate 336 * the beginning and ending indices of field number position->field, if such 337 * a field exists. This parameter may be NULL, in which case no field 338 * @param status A pointer to an UErrorCode to receive any errors 339 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 340 * @see unum_format 341 * @see unum_formatInt64 342 * @see unum_parse 343 * @see unum_parseInt64 344 * @see unum_parseDouble 345 * @see UFieldPosition 346 * @stable ICU 2.0 347 */ 348 U_STABLE int32_t U_EXPORT2 349 unum_formatDouble( const UNumberFormat* fmt, 350 double number, 351 UChar* result, 352 int32_t resultLength, 353 UFieldPosition *pos, /* 0 if ignore */ 354 UErrorCode* status); 355 356 /** 357 * Format a double currency amount using a UNumberFormat. 358 * The double will be formatted according to the UNumberFormat's locale. 359 * @param fmt the formatter to use 360 * @param number the number to format 361 * @param currency the 3-letter null-terminated ISO 4217 currency code 362 * @param result a pointer to the buffer to receive the formatted number 363 * @param resultLength the maximum number of UChars to write to result 364 * @param pos a pointer to a UFieldPosition. On input, 365 * position->field is read. On output, position->beginIndex and 366 * position->endIndex indicate the beginning and ending indices of 367 * field number position->field, if such a field exists. This 368 * parameter may be NULL, in which case it is ignored. 369 * @param status a pointer to an input-output UErrorCode 370 * @return the total buffer size needed; if greater than resultLength, 371 * the output was truncated. 372 * @see unum_formatDouble 373 * @see unum_parseDoubleCurrency 374 * @see UFieldPosition 375 * @stable ICU 3.0 376 */ 377 U_STABLE int32_t U_EXPORT2 378 unum_formatDoubleCurrency(const UNumberFormat* fmt, 379 double number, 380 UChar* currency, 381 UChar* result, 382 int32_t resultLength, 383 UFieldPosition* pos, /* ignored if 0 */ 384 UErrorCode* status); 385 386 /** 387 * Parse a string into an integer using a UNumberFormat. 388 * The string will be parsed according to the UNumberFormat's locale. 389 * @param fmt The formatter to use. 390 * @param text The text to parse. 391 * @param textLength The length of text, or -1 if null-terminated. 392 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 393 * to begin parsing. If not 0, on output the offset at which parsing ended. 394 * @param status A pointer to an UErrorCode to receive any errors 395 * @return The value of the parsed integer 396 * @see unum_parseInt64 397 * @see unum_parseDouble 398 * @see unum_format 399 * @see unum_formatInt64 400 * @see unum_formatDouble 401 * @stable ICU 2.0 402 */ 403 U_STABLE int32_t U_EXPORT2 404 unum_parse( const UNumberFormat* fmt, 405 const UChar* text, 406 int32_t textLength, 407 int32_t *parsePos /* 0 = start */, 408 UErrorCode *status); 409 410 /** 411 * Parse a string into an int64 using a UNumberFormat. 412 * The string will be parsed according to the UNumberFormat's locale. 413 * @param fmt The formatter to use. 414 * @param text The text to parse. 415 * @param textLength The length of text, or -1 if null-terminated. 416 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 417 * to begin parsing. If not 0, on output the offset at which parsing ended. 418 * @param status A pointer to an UErrorCode to receive any errors 419 * @return The value of the parsed integer 420 * @see unum_parse 421 * @see unum_parseDouble 422 * @see unum_format 423 * @see unum_formatInt64 424 * @see unum_formatDouble 425 * @stable ICU 2.8 426 */ 427 U_STABLE int64_t U_EXPORT2 428 unum_parseInt64(const UNumberFormat* fmt, 429 const UChar* text, 430 int32_t textLength, 431 int32_t *parsePos /* 0 = start */, 432 UErrorCode *status); 433 434 /** 435 * Parse a string into a double using a UNumberFormat. 436 * The string will be parsed according to the UNumberFormat's locale. 437 * @param fmt The formatter to use. 438 * @param text The text to parse. 439 * @param textLength The length of text, or -1 if null-terminated. 440 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 441 * to begin parsing. If not 0, on output the offset at which parsing ended. 442 * @param status A pointer to an UErrorCode to receive any errors 443 * @return The value of the parsed double 444 * @see unum_parse 445 * @see unum_parseInt64 446 * @see unum_format 447 * @see unum_formatInt64 448 * @see unum_formatDouble 449 * @stable ICU 2.0 450 */ 451 U_STABLE double U_EXPORT2 452 unum_parseDouble( const UNumberFormat* fmt, 453 const UChar* text, 454 int32_t textLength, 455 int32_t *parsePos /* 0 = start */, 456 UErrorCode *status); 457 458 /** 459 * Parse a string into a double and a currency using a UNumberFormat. 460 * The string will be parsed according to the UNumberFormat's locale. 461 * @param fmt the formatter to use 462 * @param text the text to parse 463 * @param textLength the length of text, or -1 if null-terminated 464 * @param parsePos a pointer to an offset index into text at which to 465 * begin parsing. On output, *parsePos will point after the last 466 * parsed character. This parameter may be 0, in which case parsing 467 * begins at offset 0. 468 * @param currency a pointer to the buffer to receive the parsed null- 469 * terminated currency. This buffer must have a capacity of at least 470 * 4 UChars. 471 * @param status a pointer to an input-output UErrorCode 472 * @return the parsed double 473 * @see unum_parseDouble 474 * @see unum_formatDoubleCurrency 475 * @stable ICU 3.0 476 */ 477 U_STABLE double U_EXPORT2 478 unum_parseDoubleCurrency(const UNumberFormat* fmt, 479 const UChar* text, 480 int32_t textLength, 481 int32_t* parsePos, /* 0 = start */ 482 UChar* currency, 483 UErrorCode* status); 484 485 /** 486 * Set the pattern used by a UNumberFormat. This can only be used 487 * on a DecimalFormat, other formats return U_ILLEGAL_ARGUMENT_ERROR 488 * in the status. 489 * @param format The formatter to set. 490 * @param localized TRUE if the pattern is localized, FALSE otherwise. 491 * @param pattern The new pattern 492 * @param patternLength The length of pattern, or -1 if null-terminated. 493 * @param parseError A pointer to UParseError to recieve information 494 * about errors occurred during parsing, or NULL if no parse error 495 * information is desired. 496 * @param status A pointer to an input-output UErrorCode. 497 * @see unum_toPattern 498 * @see DecimalFormat 499 * @stable ICU 2.0 500 */ 501 U_STABLE void U_EXPORT2 502 unum_applyPattern( UNumberFormat *format, 503 UBool localized, 504 const UChar *pattern, 505 int32_t patternLength, 506 UParseError *parseError, 507 UErrorCode *status 508 ); 509 510 /** 511 * Get a locale for which decimal formatting patterns are available. 512 * A UNumberFormat in a locale returned by this function will perform the correct 513 * formatting and parsing for the locale. The results of this call are not 514 * valid for rule-based number formats. 515 * @param localeIndex The index of the desired locale. 516 * @return A locale for which number formatting patterns are available, or 0 if none. 517 * @see unum_countAvailable 518 * @stable ICU 2.0 519 */ 520 U_STABLE const char* U_EXPORT2 521 unum_getAvailable(int32_t localeIndex); 522 523 /** 524 * Determine how many locales have decimal formatting patterns available. The 525 * results of this call are not valid for rule-based number formats. 526 * This function is useful for determining the loop ending condition for 527 * calls to {@link #unum_getAvailable }. 528 * @return The number of locales for which decimal formatting patterns are available. 529 * @see unum_getAvailable 530 * @stable ICU 2.0 531 */ 532 U_STABLE int32_t U_EXPORT2 533 unum_countAvailable(void); 534 535 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */ 536 typedef enum UNumberFormatAttribute { 537 /** Parse integers only */ 538 UNUM_PARSE_INT_ONLY, 539 /** Use grouping separator */ 540 UNUM_GROUPING_USED, 541 /** Always show decimal point */ 542 UNUM_DECIMAL_ALWAYS_SHOWN, 543 /** Maximum integer digits */ 544 UNUM_MAX_INTEGER_DIGITS, 545 /** Minimum integer digits */ 546 UNUM_MIN_INTEGER_DIGITS, 547 /** Integer digits */ 548 UNUM_INTEGER_DIGITS, 549 /** Maximum fraction digits */ 550 UNUM_MAX_FRACTION_DIGITS, 551 /** Minimum fraction digits */ 552 UNUM_MIN_FRACTION_DIGITS, 553 /** Fraction digits */ 554 UNUM_FRACTION_DIGITS, 555 /** Multiplier */ 556 UNUM_MULTIPLIER, 557 /** Grouping size */ 558 UNUM_GROUPING_SIZE, 559 /** Rounding Mode */ 560 UNUM_ROUNDING_MODE, 561 /** Rounding increment */ 562 UNUM_ROUNDING_INCREMENT, 563 /** The width to which the output of <code>format()</code> is padded. */ 564 UNUM_FORMAT_WIDTH, 565 /** The position at which padding will take place. */ 566 UNUM_PADDING_POSITION, 567 /** Secondary grouping size */ 568 UNUM_SECONDARY_GROUPING_SIZE, 569 /** Use significant digits 570 * @stable ICU 3.0 */ 571 UNUM_SIGNIFICANT_DIGITS_USED, 572 /** Minimum significant digits 573 * @stable ICU 3.0 */ 574 UNUM_MIN_SIGNIFICANT_DIGITS, 575 /** Maximum significant digits 576 * @stable ICU 3.0 */ 577 UNUM_MAX_SIGNIFICANT_DIGITS, 578 /** Lenient parse mode used by rule-based formats. 579 * @stable ICU 3.0 580 */ 581 UNUM_LENIENT_PARSE 582 } UNumberFormatAttribute; 583 584 /** 585 * Get a numeric attribute associated with a UNumberFormat. 586 * An example of a numeric attribute is the number of integer digits a formatter will produce. 587 * @param fmt The formatter to query. 588 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, 589 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, 590 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, 591 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE. 592 * @return The value of attr. 593 * @see unum_setAttribute 594 * @see unum_getDoubleAttribute 595 * @see unum_setDoubleAttribute 596 * @see unum_getTextAttribute 597 * @see unum_setTextAttribute 598 * @stable ICU 2.0 599 */ 600 U_STABLE int32_t U_EXPORT2 601 unum_getAttribute(const UNumberFormat* fmt, 602 UNumberFormatAttribute attr); 603 604 /** 605 * Set a numeric attribute associated with a UNumberFormat. 606 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the 607 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand 608 * the lenient-parse attribute. 609 * @param fmt The formatter to set. 610 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, 611 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, 612 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, 613 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, 614 * or UNUM_LENIENT_PARSE. 615 * @param newValue The new value of attr. 616 * @see unum_getAttribute 617 * @see unum_getDoubleAttribute 618 * @see unum_setDoubleAttribute 619 * @see unum_getTextAttribute 620 * @see unum_setTextAttribute 621 * @stable ICU 2.0 622 */ 623 U_STABLE void U_EXPORT2 624 unum_setAttribute( UNumberFormat* fmt, 625 UNumberFormatAttribute attr, 626 int32_t newValue); 627 628 629 /** 630 * Get a numeric attribute associated with a UNumberFormat. 631 * An example of a numeric attribute is the number of integer digits a formatter will produce. 632 * If the formatter does not understand the attribute, -1 is returned. 633 * @param fmt The formatter to query. 634 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT. 635 * @return The value of attr. 636 * @see unum_getAttribute 637 * @see unum_setAttribute 638 * @see unum_setDoubleAttribute 639 * @see unum_getTextAttribute 640 * @see unum_setTextAttribute 641 * @stable ICU 2.0 642 */ 643 U_STABLE double U_EXPORT2 644 unum_getDoubleAttribute(const UNumberFormat* fmt, 645 UNumberFormatAttribute attr); 646 647 /** 648 * Set a numeric attribute associated with a UNumberFormat. 649 * An example of a numeric attribute is the number of integer digits a formatter will produce. 650 * If the formatter does not understand the attribute, this call is ignored. 651 * @param fmt The formatter to set. 652 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT. 653 * @param newValue The new value of attr. 654 * @see unum_getAttribute 655 * @see unum_setAttribute 656 * @see unum_getDoubleAttribute 657 * @see unum_getTextAttribute 658 * @see unum_setTextAttribute 659 * @stable ICU 2.0 660 */ 661 U_STABLE void U_EXPORT2 662 unum_setDoubleAttribute( UNumberFormat* fmt, 663 UNumberFormatAttribute attr, 664 double newValue); 665 666 /** The possible UNumberFormat text attributes @stable ICU 2.0*/ 667 typedef enum UNumberFormatTextAttribute { 668 /** Positive prefix */ 669 UNUM_POSITIVE_PREFIX, 670 /** Positive suffix */ 671 UNUM_POSITIVE_SUFFIX, 672 /** Negative prefix */ 673 UNUM_NEGATIVE_PREFIX, 674 /** Negative suffix */ 675 UNUM_NEGATIVE_SUFFIX, 676 /** The character used to pad to the format width. */ 677 UNUM_PADDING_CHARACTER, 678 /** The ISO currency code */ 679 UNUM_CURRENCY_CODE, 680 /** 681 * The default rule set. This is only available with rule-based formatters. 682 * @stable ICU 3.0 683 */ 684 UNUM_DEFAULT_RULESET, 685 /** 686 * The public rule sets. This is only available with rule-based formatters. 687 * This is a read-only attribute. The public rulesets are returned as a 688 * single string, with each ruleset name delimited by ';' (semicolon). 689 * @stable ICU 3.0 690 */ 691 UNUM_PUBLIC_RULESETS 692 } UNumberFormatTextAttribute; 693 694 /** 695 * Get a text attribute associated with a UNumberFormat. 696 * An example of a text attribute is the suffix for positive numbers. If the formatter 697 * does not understand the attributre, U_UNSUPPORTED_ERROR is returned as the status. 698 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS. 699 * @param fmt The formatter to query. 700 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, 701 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, 702 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS. 703 * @param result A pointer to a buffer to receive the attribute. 704 * @param resultLength The maximum size of result. 705 * @param status A pointer to an UErrorCode to receive any errors 706 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 707 * @see unum_setTextAttribute 708 * @see unum_getAttribute 709 * @see unum_setAttribute 710 * @stable ICU 2.0 711 */ 712 U_STABLE int32_t U_EXPORT2 713 unum_getTextAttribute( const UNumberFormat* fmt, 714 UNumberFormatTextAttribute tag, 715 UChar* result, 716 int32_t resultLength, 717 UErrorCode* status); 718 719 /** 720 * Set a text attribute associated with a UNumberFormat. 721 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters 722 * only understand UNUM_DEFAULT_RULESET. 723 * @param fmt The formatter to set. 724 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, 725 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, 726 * or UNUM_DEFAULT_RULESET. 727 * @param newValue The new value of attr. 728 * @param newValueLength The length of newValue, or -1 if null-terminated. 729 * @param status A pointer to an UErrorCode to receive any errors 730 * @see unum_getTextAttribute 731 * @see unum_getAttribute 732 * @see unum_setAttribute 733 * @stable ICU 2.0 734 */ 735 U_STABLE void U_EXPORT2 736 unum_setTextAttribute( UNumberFormat* fmt, 737 UNumberFormatTextAttribute tag, 738 const UChar* newValue, 739 int32_t newValueLength, 740 UErrorCode *status); 741 742 /** 743 * Extract the pattern from a UNumberFormat. The pattern will follow 744 * the DecimalFormat pattern syntax. 745 * @param fmt The formatter to query. 746 * @param isPatternLocalized TRUE if the pattern should be localized, 747 * FALSE otherwise. This is ignored if the formatter is a rule-based 748 * formatter. 749 * @param result A pointer to a buffer to receive the pattern. 750 * @param resultLength The maximum size of result. 751 * @param status A pointer to an input-output UErrorCode. 752 * @return The total buffer size needed; if greater than resultLength, 753 * the output was truncated. 754 * @see unum_applyPattern 755 * @see DecimalFormat 756 * @stable ICU 2.0 757 */ 758 U_STABLE int32_t U_EXPORT2 759 unum_toPattern( const UNumberFormat* fmt, 760 UBool isPatternLocalized, 761 UChar* result, 762 int32_t resultLength, 763 UErrorCode* status); 764 765 766 /** 767 * Constants for specifying a number format symbol. 768 * @stable ICU 2.0 769 */ 770 typedef enum UNumberFormatSymbol { 771 /** The decimal separator */ 772 UNUM_DECIMAL_SEPARATOR_SYMBOL = 0, 773 /** The grouping separator */ 774 UNUM_GROUPING_SEPARATOR_SYMBOL = 1, 775 /** The pattern separator */ 776 UNUM_PATTERN_SEPARATOR_SYMBOL = 2, 777 /** The percent sign */ 778 UNUM_PERCENT_SYMBOL = 3, 779 /** Zero*/ 780 UNUM_ZERO_DIGIT_SYMBOL = 4, 781 /** Character representing a digit in the pattern */ 782 UNUM_DIGIT_SYMBOL = 5, 783 /** The minus sign */ 784 UNUM_MINUS_SIGN_SYMBOL = 6, 785 /** The plus sign */ 786 UNUM_PLUS_SIGN_SYMBOL = 7, 787 /** The currency symbol */ 788 UNUM_CURRENCY_SYMBOL = 8, 789 /** The international currency symbol */ 790 UNUM_INTL_CURRENCY_SYMBOL = 9, 791 /** The monetary separator */ 792 UNUM_MONETARY_SEPARATOR_SYMBOL = 10, 793 /** The exponential symbol */ 794 UNUM_EXPONENTIAL_SYMBOL = 11, 795 /** Per mill symbol */ 796 UNUM_PERMILL_SYMBOL = 12, 797 /** Escape padding character */ 798 UNUM_PAD_ESCAPE_SYMBOL = 13, 799 /** Infinity symbol */ 800 UNUM_INFINITY_SYMBOL = 14, 801 /** Nan symbol */ 802 UNUM_NAN_SYMBOL = 15, 803 /** Significant digit symbol 804 * @stable ICU 3.0 */ 805 UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16, 806 /** The monetary grouping separator 807 * @stable ICU 3.6 808 */ 809 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, 810 /** count symbol constants */ 811 UNUM_FORMAT_SYMBOL_COUNT = 18 812 } UNumberFormatSymbol; 813 814 /** 815 * Get a symbol associated with a UNumberFormat. 816 * A UNumberFormat uses symbols to represent the special locale-dependent 817 * characters in a number, for example the percent sign. This API is not 818 * supported for rule-based formatters. 819 * @param fmt The formatter to query. 820 * @param symbol The UNumberFormatSymbol constant for the symbol to get 821 * @param buffer The string buffer that will receive the symbol string; 822 * if it is NULL, then only the length of the symbol is returned 823 * @param size The size of the string buffer 824 * @param status A pointer to an UErrorCode to receive any errors 825 * @return The length of the symbol; the buffer is not modified if 826 * <code>length>=size</code> 827 * @see unum_setSymbol 828 * @stable ICU 2.0 829 */ 830 U_STABLE int32_t U_EXPORT2 831 unum_getSymbol(const UNumberFormat *fmt, 832 UNumberFormatSymbol symbol, 833 UChar *buffer, 834 int32_t size, 835 UErrorCode *status); 836 837 /** 838 * Set a symbol associated with a UNumberFormat. 839 * A UNumberFormat uses symbols to represent the special locale-dependent 840 * characters in a number, for example the percent sign. This API is not 841 * supported for rule-based formatters. 842 * @param fmt The formatter to set. 843 * @param symbol The UNumberFormatSymbol constant for the symbol to set 844 * @param value The string to set the symbol to 845 * @param length The length of the string, or -1 for a zero-terminated string 846 * @param status A pointer to an UErrorCode to receive any errors. 847 * @see unum_getSymbol 848 * @stable ICU 2.0 849 */ 850 U_STABLE void U_EXPORT2 851 unum_setSymbol(UNumberFormat *fmt, 852 UNumberFormatSymbol symbol, 853 const UChar *value, 854 int32_t length, 855 UErrorCode *status); 856 857 858 /** 859 * Get the locale for this number format object. 860 * You can choose between valid and actual locale. 861 * @param fmt The formatter to get the locale from 862 * @param type type of the locale we're looking for (valid or actual) 863 * @param status error code for the operation 864 * @return the locale name 865 * @stable ICU 2.8 866 */ 867 U_STABLE const char* U_EXPORT2 868 unum_getLocaleByType(const UNumberFormat *fmt, 869 ULocDataLocaleType type, 870 UErrorCode* status); 871 872 #endif /* #if !UCONFIG_NO_FORMATTING */ 873 874 #endif 875