|
||||
File indexing completed on 2025-01-18 10:13:13
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 1997-2015, International Business Machines Corporation and others. 0006 * All Rights Reserved. 0007 * Modification History: 0008 * 0009 * Date Name Description 0010 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes 0011 ******************************************************************************* 0012 */ 0013 0014 #ifndef _UNUM 0015 #define _UNUM 0016 0017 #include "unicode/utypes.h" 0018 0019 #if !UCONFIG_NO_FORMATTING 0020 0021 #include "unicode/uloc.h" 0022 #include "unicode/ucurr.h" 0023 #include "unicode/umisc.h" 0024 #include "unicode/parseerr.h" 0025 #include "unicode/uformattable.h" 0026 #include "unicode/udisplaycontext.h" 0027 #include "unicode/ufieldpositer.h" 0028 #include "unicode/unumberoptions.h" 0029 0030 #if U_SHOW_CPLUSPLUS_API 0031 #include "unicode/localpointer.h" 0032 #endif // U_SHOW_CPLUSPLUS_API 0033 0034 /** 0035 * \file 0036 * \brief C API: Compatibility APIs for number formatting. 0037 * 0038 * <h2> Number Format C API </h2> 0039 * 0040 * <p><strong>IMPORTANT:</strong> New users with are strongly encouraged to 0041 * see if unumberformatter.h fits their use case. Although not deprecated, 0042 * this header is provided for backwards compatibility only. 0043 * 0044 * Number Format C API Provides functions for 0045 * formatting and parsing a number. Also provides methods for 0046 * determining which locales have number formats, and what their names 0047 * are. 0048 * <P> 0049 * UNumberFormat helps you to format and parse numbers for any locale. 0050 * Your code can be completely independent of the locale conventions 0051 * for decimal points, thousands-separators, or even the particular 0052 * decimal digits used, or whether the number format is even decimal. 0053 * There are different number format styles like decimal, currency, 0054 * percent and spellout. 0055 * <P> 0056 * To format a number for the current Locale, use one of the static 0057 * factory methods: 0058 * <pre> 0059 * \code 0060 * UChar myString[20]; 0061 * double myNumber = 7.0; 0062 * UErrorCode status = U_ZERO_ERROR; 0063 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status); 0064 * unum_formatDouble(nf, myNumber, myString, 20, NULL, &status); 0065 * printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*) 0066 * \endcode 0067 * </pre> 0068 * If you are formatting multiple numbers, it is more efficient to get 0069 * the format and use it multiple times so that the system doesn't 0070 * have to fetch the information about the local language and country 0071 * conventions multiple times. 0072 * <pre> 0073 * \code 0074 * uint32_t i, resultlength, reslenneeded; 0075 * UErrorCode status = U_ZERO_ERROR; 0076 * UFieldPosition pos; 0077 * uint32_t a[] = { 123, 3333, -1234567 }; 0078 * const uint32_t a_len = sizeof(a) / sizeof(a[0]); 0079 * UNumberFormat* nf; 0080 * UChar* result = NULL; 0081 * 0082 * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status); 0083 * for (i = 0; i < a_len; i++) { 0084 * resultlength=0; 0085 * reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status); 0086 * result = NULL; 0087 * if(status==U_BUFFER_OVERFLOW_ERROR){ 0088 * status=U_ZERO_ERROR; 0089 * resultlength=reslenneeded+1; 0090 * result=(UChar*)malloc(sizeof(UChar) * resultlength); 0091 * unum_format(nf, a[i], result, resultlength, &pos, &status); 0092 * } 0093 * printf( " Example 2: %s\n", austrdup(result)); 0094 * free(result); 0095 * } 0096 * \endcode 0097 * </pre> 0098 * To format a number for a different Locale, specify it in the 0099 * call to unum_open(). 0100 * <pre> 0101 * \code 0102 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success) 0103 * \endcode 0104 * </pre> 0105 * You can use a NumberFormat API unum_parse() to parse. 0106 * <pre> 0107 * \code 0108 * UErrorCode status = U_ZERO_ERROR; 0109 * int32_t pos=0; 0110 * int32_t num; 0111 * num = unum_parse(nf, str, u_strlen(str), &pos, &status); 0112 * \endcode 0113 * </pre> 0114 * Use UNUM_DECIMAL to get the normal number format for that country. 0115 * There are other static options available. Use UNUM_CURRENCY 0116 * to get the currency number format for that country. Use UNUM_PERCENT 0117 * to get a format for displaying percentages. With this format, a 0118 * fraction from 0.53 is displayed as 53%. 0119 * <P> 0120 * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat 0121 * formatter. The pattern must conform to the syntax defined for those 0122 * formatters. 0123 * <P> 0124 * You can also control the display of numbers with such function as 0125 * unum_getAttributes() and unum_setAttributes(), which let you set the 0126 * minimum fraction digits, grouping, etc. 0127 * @see UNumberFormatAttributes for more details 0128 * <P> 0129 * You can also use forms of the parse and format methods with 0130 * ParsePosition and UFieldPosition to allow you to: 0131 * <ul type=round> 0132 * <li>(a) progressively parse through pieces of a string. 0133 * <li>(b) align the decimal point and other areas. 0134 * </ul> 0135 * <p> 0136 * It is also possible to change or set the symbols used for a particular 0137 * locale like the currency symbol, the grouping separator , monetary separator 0138 * etc by making use of functions unum_setSymbols() and unum_getSymbols(). 0139 */ 0140 0141 /** A number formatter. 0142 * For usage in C programs. 0143 * @stable ICU 2.0 0144 */ 0145 typedef void* UNumberFormat; 0146 0147 /** The possible number format styles. 0148 * @stable ICU 2.0 0149 */ 0150 typedef enum UNumberFormatStyle { 0151 /** 0152 * Decimal format defined by a pattern string. 0153 * @stable ICU 3.0 0154 */ 0155 UNUM_PATTERN_DECIMAL=0, 0156 /** 0157 * Decimal format ("normal" style). 0158 * @stable ICU 2.0 0159 */ 0160 UNUM_DECIMAL=1, 0161 /** 0162 * Currency format (generic). 0163 * Defaults to UNUM_CURRENCY_STANDARD style 0164 * (using currency symbol, e.g., "$1.00", with non-accounting 0165 * style for negative values e.g. using minus sign). 0166 * The specific style may be specified using the -cf- locale key. 0167 * @stable ICU 2.0 0168 */ 0169 UNUM_CURRENCY=2, 0170 /** 0171 * Percent format 0172 * @stable ICU 2.0 0173 */ 0174 UNUM_PERCENT=3, 0175 /** 0176 * Scientific format 0177 * @stable ICU 2.1 0178 */ 0179 UNUM_SCIENTIFIC=4, 0180 /** 0181 * Spellout rule-based format. The default ruleset can be specified/changed using 0182 * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets 0183 * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS. 0184 * @stable ICU 2.0 0185 */ 0186 UNUM_SPELLOUT=5, 0187 /** 0188 * Ordinal rule-based format . The default ruleset can be specified/changed using 0189 * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets 0190 * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS. 0191 * @stable ICU 3.0 0192 */ 0193 UNUM_ORDINAL=6, 0194 /** 0195 * Duration rule-based format 0196 * @stable ICU 3.0 0197 */ 0198 UNUM_DURATION=7, 0199 /** 0200 * Numbering system rule-based format 0201 * @stable ICU 4.2 0202 */ 0203 UNUM_NUMBERING_SYSTEM=8, 0204 /** 0205 * Rule-based format defined by a pattern string. 0206 * @stable ICU 3.0 0207 */ 0208 UNUM_PATTERN_RULEBASED=9, 0209 /** 0210 * Currency format with an ISO currency code, e.g., "USD1.00". 0211 * @stable ICU 4.8 0212 */ 0213 UNUM_CURRENCY_ISO=10, 0214 /** 0215 * Currency format with a pluralized currency name, 0216 * e.g., "1.00 US dollar" and "3.00 US dollars". 0217 * @stable ICU 4.8 0218 */ 0219 UNUM_CURRENCY_PLURAL=11, 0220 /** 0221 * Currency format for accounting, e.g., "($3.00)" for 0222 * negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}). 0223 * Overrides any style specified using -cf- key in locale. 0224 * @stable ICU 53 0225 */ 0226 UNUM_CURRENCY_ACCOUNTING=12, 0227 /** 0228 * Currency format with a currency symbol given CASH usage, e.g., 0229 * "NT$3" instead of "NT$3.23". 0230 * @stable ICU 54 0231 */ 0232 UNUM_CASH_CURRENCY=13, 0233 /** 0234 * Decimal format expressed using compact notation 0235 * (short form, corresponds to UNumberCompactStyle=UNUM_SHORT) 0236 * e.g. "23K", "45B" 0237 * @stable ICU 56 0238 */ 0239 UNUM_DECIMAL_COMPACT_SHORT=14, 0240 /** 0241 * Decimal format expressed using compact notation 0242 * (long form, corresponds to UNumberCompactStyle=UNUM_LONG) 0243 * e.g. "23 thousand", "45 billion" 0244 * @stable ICU 56 0245 */ 0246 UNUM_DECIMAL_COMPACT_LONG=15, 0247 /** 0248 * Currency format with a currency symbol, e.g., "$1.00", 0249 * using non-accounting style for negative values (e.g. minus sign). 0250 * Overrides any style specified using -cf- key in locale. 0251 * @stable ICU 56 0252 */ 0253 UNUM_CURRENCY_STANDARD=16, 0254 0255 #ifndef U_HIDE_DEPRECATED_API 0256 /** 0257 * One more than the highest normal UNumberFormatStyle value. 0258 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0259 */ 0260 UNUM_FORMAT_STYLE_COUNT=17, 0261 #endif /* U_HIDE_DEPRECATED_API */ 0262 0263 /** 0264 * Default format 0265 * @stable ICU 2.0 0266 */ 0267 UNUM_DEFAULT = UNUM_DECIMAL, 0268 /** 0269 * Alias for UNUM_PATTERN_DECIMAL 0270 * @stable ICU 3.0 0271 */ 0272 UNUM_IGNORE = UNUM_PATTERN_DECIMAL 0273 } UNumberFormatStyle; 0274 0275 /** The possible number format pad positions. 0276 * @stable ICU 2.0 0277 */ 0278 typedef enum UNumberFormatPadPosition { 0279 UNUM_PAD_BEFORE_PREFIX, 0280 UNUM_PAD_AFTER_PREFIX, 0281 UNUM_PAD_BEFORE_SUFFIX, 0282 UNUM_PAD_AFTER_SUFFIX 0283 } UNumberFormatPadPosition; 0284 0285 /** 0286 * Constants for specifying short or long format. 0287 * @stable ICU 51 0288 */ 0289 typedef enum UNumberCompactStyle { 0290 /** @stable ICU 51 */ 0291 UNUM_SHORT, 0292 /** @stable ICU 51 */ 0293 UNUM_LONG 0294 /** @stable ICU 51 */ 0295 } UNumberCompactStyle; 0296 0297 /** 0298 * Constants for specifying currency spacing 0299 * @stable ICU 4.8 0300 */ 0301 enum UCurrencySpacing { 0302 /** @stable ICU 4.8 */ 0303 UNUM_CURRENCY_MATCH, 0304 /** @stable ICU 4.8 */ 0305 UNUM_CURRENCY_SURROUNDING_MATCH, 0306 /** @stable ICU 4.8 */ 0307 UNUM_CURRENCY_INSERT, 0308 0309 /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API, 0310 * it is needed for layout of DecimalFormatSymbols object. */ 0311 #ifndef U_FORCE_HIDE_DEPRECATED_API 0312 /** 0313 * One more than the highest normal UCurrencySpacing value. 0314 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0315 */ 0316 UNUM_CURRENCY_SPACING_COUNT 0317 #endif // U_FORCE_HIDE_DEPRECATED_API 0318 }; 0319 typedef enum UCurrencySpacing UCurrencySpacing; /**< @stable ICU 4.8 */ 0320 0321 0322 /** 0323 * FieldPosition and UFieldPosition selectors for format fields 0324 * defined by NumberFormat and UNumberFormat. 0325 * @stable ICU 49 0326 */ 0327 typedef enum UNumberFormatFields { 0328 /** @stable ICU 49 */ 0329 UNUM_INTEGER_FIELD, 0330 /** @stable ICU 49 */ 0331 UNUM_FRACTION_FIELD, 0332 /** @stable ICU 49 */ 0333 UNUM_DECIMAL_SEPARATOR_FIELD, 0334 /** @stable ICU 49 */ 0335 UNUM_EXPONENT_SYMBOL_FIELD, 0336 /** @stable ICU 49 */ 0337 UNUM_EXPONENT_SIGN_FIELD, 0338 /** @stable ICU 49 */ 0339 UNUM_EXPONENT_FIELD, 0340 /** @stable ICU 49 */ 0341 UNUM_GROUPING_SEPARATOR_FIELD, 0342 /** @stable ICU 49 */ 0343 UNUM_CURRENCY_FIELD, 0344 /** @stable ICU 49 */ 0345 UNUM_PERCENT_FIELD, 0346 /** @stable ICU 49 */ 0347 UNUM_PERMILL_FIELD, 0348 /** @stable ICU 49 */ 0349 UNUM_SIGN_FIELD, 0350 /** @stable ICU 64 */ 0351 UNUM_MEASURE_UNIT_FIELD, 0352 /** @stable ICU 64 */ 0353 UNUM_COMPACT_FIELD, 0354 /** 0355 * Approximately sign. In ICU 70, this was categorized under the generic SIGN field. 0356 * @stable ICU 71 0357 */ 0358 UNUM_APPROXIMATELY_SIGN_FIELD, 0359 0360 #ifndef U_HIDE_DEPRECATED_API 0361 /** 0362 * One more than the highest normal UNumberFormatFields value. 0363 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0364 */ 0365 UNUM_FIELD_COUNT 0366 #endif /* U_HIDE_DEPRECATED_API */ 0367 } UNumberFormatFields; 0368 0369 0370 /** 0371 * Selectors with special numeric values to use locale default minimum grouping 0372 * digits for the DecimalFormat/UNumberFormat setMinimumGroupingDigits method. 0373 * Do not use these constants with the [U]NumberFormatter API. 0374 * 0375 * @stable ICU 68 0376 */ 0377 typedef enum UNumberFormatMinimumGroupingDigits { 0378 /** 0379 * Display grouping using the default strategy for all locales. 0380 * @stable ICU 68 0381 */ 0382 UNUM_MINIMUM_GROUPING_DIGITS_AUTO = -2, 0383 /** 0384 * Display grouping using locale defaults, except do not show grouping on 0385 * values smaller than 10000 (such that there is a minimum of two digits 0386 * before the first separator). 0387 * @stable ICU 68 0388 */ 0389 UNUM_MINIMUM_GROUPING_DIGITS_MIN2 = -3, 0390 } UNumberFormatMinimumGroupingDigits; 0391 0392 /** 0393 * Create and return a new UNumberFormat for formatting and parsing 0394 * numbers. A UNumberFormat may be used to format numbers by calling 0395 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }. 0396 * The caller must call {@link #unum_close } when done to release resources 0397 * used by this object. 0398 * @param style The type of number format to open: one of 0399 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, 0400 * UNUM_CURRENCY_ISO, UNUM_CURRENCY_PLURAL, UNUM_SPELLOUT, 0401 * UNUM_ORDINAL, UNUM_DURATION, UNUM_NUMBERING_SYSTEM, 0402 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT. 0403 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the 0404 * number format is opened using the given pattern, which must conform 0405 * to the syntax described in DecimalFormat or RuleBasedNumberFormat, 0406 * respectively. 0407 * 0408 * <p><strong>NOTE::</strong> New users with are strongly encouraged to 0409 * use unumf_openForSkeletonAndLocale instead of unum_open. 0410 * 0411 * @param pattern A pattern specifying the format to use. 0412 * This parameter is ignored unless the style is 0413 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED. 0414 * @param patternLength The number of characters in the pattern, or -1 0415 * if null-terminated. This parameter is ignored unless the style is 0416 * UNUM_PATTERN. 0417 * @param locale A locale identifier to use to determine formatting 0418 * and parsing conventions, or NULL to use the default locale. 0419 * @param parseErr A pointer to a UParseError struct to receive the 0420 * details of any parsing errors, or NULL if no parsing error details 0421 * are desired. 0422 * @param status A pointer to an input-output UErrorCode. 0423 * @return A pointer to a newly created UNumberFormat, or NULL if an 0424 * error occurred. 0425 * @see unum_close 0426 * @see DecimalFormat 0427 * @stable ICU 2.0 0428 */ 0429 U_CAPI UNumberFormat* U_EXPORT2 0430 unum_open( UNumberFormatStyle style, 0431 const UChar* pattern, 0432 int32_t patternLength, 0433 const char* locale, 0434 UParseError* parseErr, 0435 UErrorCode* status); 0436 0437 0438 /** 0439 * Close a UNumberFormat. 0440 * Once closed, a UNumberFormat may no longer be used. 0441 * @param fmt The formatter to close. 0442 * @stable ICU 2.0 0443 */ 0444 U_CAPI void U_EXPORT2 0445 unum_close(UNumberFormat* fmt); 0446 0447 #if U_SHOW_CPLUSPLUS_API 0448 0449 U_NAMESPACE_BEGIN 0450 0451 /** 0452 * \class LocalUNumberFormatPointer 0453 * "Smart pointer" class, closes a UNumberFormat via unum_close(). 0454 * For most methods see the LocalPointerBase base class. 0455 * 0456 * @see LocalPointerBase 0457 * @see LocalPointer 0458 * @stable ICU 4.4 0459 */ 0460 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close); 0461 0462 U_NAMESPACE_END 0463 0464 #endif 0465 0466 /** 0467 * Open a copy of a UNumberFormat. 0468 * This function performs a deep copy. 0469 * @param fmt The format to copy 0470 * @param status A pointer to an UErrorCode to receive any errors. 0471 * @return A pointer to a UNumberFormat identical to fmt. 0472 * @stable ICU 2.0 0473 */ 0474 U_CAPI UNumberFormat* U_EXPORT2 0475 unum_clone(const UNumberFormat *fmt, 0476 UErrorCode *status); 0477 0478 /** 0479 * Format an integer using a UNumberFormat. 0480 * The integer will be formatted according to the UNumberFormat's locale. 0481 * @param fmt The formatter to use. 0482 * @param number The number to format. 0483 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0484 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0485 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0486 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0487 * @param resultLength The maximum size of result. 0488 * @param pos A pointer to a UFieldPosition. On input, position->field 0489 * is read. On output, position->beginIndex and position->endIndex indicate 0490 * the beginning and ending indices of field number position->field, if such 0491 * a field exists. This parameter may be NULL, in which case no field 0492 * @param status A pointer to an UErrorCode to receive any errors 0493 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 0494 * @see unum_formatInt64 0495 * @see unum_formatDouble 0496 * @see unum_parse 0497 * @see unum_parseInt64 0498 * @see unum_parseDouble 0499 * @see UFieldPosition 0500 * @stable ICU 2.0 0501 */ 0502 U_CAPI int32_t U_EXPORT2 0503 unum_format( const UNumberFormat* fmt, 0504 int32_t number, 0505 UChar* result, 0506 int32_t resultLength, 0507 UFieldPosition *pos, 0508 UErrorCode* status); 0509 0510 /** 0511 * Format an int64 using a UNumberFormat. 0512 * The int64 will be formatted according to the UNumberFormat's locale. 0513 * @param fmt The formatter to use. 0514 * @param number The number to format. 0515 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0516 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0517 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0518 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0519 * @param resultLength The maximum size of result. 0520 * @param pos A pointer to a UFieldPosition. On input, position->field 0521 * is read. On output, position->beginIndex and position->endIndex indicate 0522 * the beginning and ending indices of field number position->field, if such 0523 * a field exists. This parameter may be NULL, in which case no field 0524 * @param status A pointer to an UErrorCode to receive any errors 0525 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 0526 * @see unum_format 0527 * @see unum_formatDouble 0528 * @see unum_parse 0529 * @see unum_parseInt64 0530 * @see unum_parseDouble 0531 * @see UFieldPosition 0532 * @stable ICU 2.0 0533 */ 0534 U_CAPI int32_t U_EXPORT2 0535 unum_formatInt64(const UNumberFormat *fmt, 0536 int64_t number, 0537 UChar* result, 0538 int32_t resultLength, 0539 UFieldPosition *pos, 0540 UErrorCode* status); 0541 0542 /** 0543 * Format a double using a UNumberFormat. 0544 * The double will be formatted according to the UNumberFormat's locale. 0545 * @param fmt The formatter to use. 0546 * @param number The number to format. 0547 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0548 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0549 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0550 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0551 * @param resultLength The maximum size of result. 0552 * @param pos A pointer to a UFieldPosition. On input, position->field 0553 * is read. On output, position->beginIndex and position->endIndex indicate 0554 * the beginning and ending indices of field number position->field, if such 0555 * a field exists. This parameter may be NULL, in which case no field 0556 * @param status A pointer to an UErrorCode to receive any errors 0557 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 0558 * @see unum_format 0559 * @see unum_formatInt64 0560 * @see unum_parse 0561 * @see unum_parseInt64 0562 * @see unum_parseDouble 0563 * @see UFieldPosition 0564 * @stable ICU 2.0 0565 */ 0566 U_CAPI int32_t U_EXPORT2 0567 unum_formatDouble( const UNumberFormat* fmt, 0568 double number, 0569 UChar* result, 0570 int32_t resultLength, 0571 UFieldPosition *pos, /* 0 if ignore */ 0572 UErrorCode* status); 0573 0574 /** 0575 * Format a double using a UNumberFormat according to the UNumberFormat's locale, 0576 * and initialize a UFieldPositionIterator that enumerates the subcomponents of 0577 * the resulting string. 0578 * 0579 * @param format 0580 * The formatter to use. 0581 * @param number 0582 * The number to format. 0583 * @param result 0584 * A pointer to a buffer to receive the NULL-terminated formatted 0585 * number. If the formatted number fits into dest but cannot be 0586 * NULL-terminated (length == resultLength) then the error code is set 0587 * to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't 0588 * fit into result then the error code is set to 0589 * U_BUFFER_OVERFLOW_ERROR. 0590 * @param resultLength 0591 * The maximum size of result. 0592 * @param fpositer 0593 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open} 0594 * (may be NULL if field position information is not needed, but in this 0595 * case it's preferable to use {@link #unum_formatDouble}). Iteration 0596 * information already present in the UFieldPositionIterator is deleted, 0597 * and the iterator is reset to apply to the fields in the formatted 0598 * string created by this function call. The field values and indexes 0599 * returned by {@link #ufieldpositer_next} represent fields denoted by 0600 * the UNumberFormatFields enum. Fields are not returned in a guaranteed 0601 * order. Fields cannot overlap, but they may nest. For example, 1234 0602 * could format as "1,234" which might consist of a grouping separator 0603 * field for ',' and an integer field encompassing the entire string. 0604 * @param status 0605 * A pointer to an UErrorCode to receive any errors 0606 * @return 0607 * The total buffer size needed; if greater than resultLength, the 0608 * output was truncated. 0609 * @see unum_formatDouble 0610 * @see unum_parse 0611 * @see unum_parseDouble 0612 * @see UFieldPositionIterator 0613 * @see UNumberFormatFields 0614 * @stable ICU 59 0615 */ 0616 U_CAPI int32_t U_EXPORT2 0617 unum_formatDoubleForFields(const UNumberFormat* format, 0618 double number, 0619 UChar* result, 0620 int32_t resultLength, 0621 UFieldPositionIterator* fpositer, 0622 UErrorCode* status); 0623 0624 0625 /** 0626 * Format a decimal number using a UNumberFormat. 0627 * The number will be formatted according to the UNumberFormat's locale. 0628 * The syntax of the input number is a "numeric string" 0629 * as defined in the Decimal Arithmetic Specification, available at 0630 * http://speleotrove.com/decimal 0631 * @param fmt The formatter to use. 0632 * @param number The number to format. 0633 * @param length The length of the input number, or -1 if the input is nul-terminated. 0634 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0635 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0636 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0637 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0638 * @param resultLength The maximum size of result. 0639 * @param pos A pointer to a UFieldPosition. On input, position->field 0640 * is read. On output, position->beginIndex and position->endIndex indicate 0641 * the beginning and ending indices of field number position->field, if such 0642 * a field exists. This parameter may be NULL, in which case it is ignored. 0643 * @param status A pointer to an UErrorCode to receive any errors 0644 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 0645 * @see unum_format 0646 * @see unum_formatInt64 0647 * @see unum_parse 0648 * @see unum_parseInt64 0649 * @see unum_parseDouble 0650 * @see UFieldPosition 0651 * @stable ICU 4.4 0652 */ 0653 U_CAPI int32_t U_EXPORT2 0654 unum_formatDecimal( const UNumberFormat* fmt, 0655 const char * number, 0656 int32_t length, 0657 UChar* result, 0658 int32_t resultLength, 0659 UFieldPosition *pos, /* 0 if ignore */ 0660 UErrorCode* status); 0661 0662 /** 0663 * Format a double currency amount using a UNumberFormat. 0664 * The double will be formatted according to the UNumberFormat's locale. 0665 * 0666 * To format an exact decimal value with a currency, use 0667 * `unum_setTextAttribute(UNUM_CURRENCY_CODE, ...)` followed by unum_formatDecimal. 0668 * Your UNumberFormat must be created with the UNUM_CURRENCY style. Alternatively, 0669 * consider using unumf_openForSkeletonAndLocale. 0670 * 0671 * @param fmt the formatter to use 0672 * @param number the number to format 0673 * @param currency the 3-letter null-terminated ISO 4217 currency code 0674 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0675 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0676 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0677 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0678 * @param resultLength the maximum number of UChars to write to result 0679 * @param pos a pointer to a UFieldPosition. On input, 0680 * position->field is read. On output, position->beginIndex and 0681 * position->endIndex indicate the beginning and ending indices of 0682 * field number position->field, if such a field exists. This 0683 * parameter may be NULL, in which case it is ignored. 0684 * @param status a pointer to an input-output UErrorCode 0685 * @return the total buffer size needed; if greater than resultLength, 0686 * the output was truncated. 0687 * @see unum_formatDouble 0688 * @see unum_parseDoubleCurrency 0689 * @see UFieldPosition 0690 * @stable ICU 3.0 0691 */ 0692 U_CAPI int32_t U_EXPORT2 0693 unum_formatDoubleCurrency(const UNumberFormat* fmt, 0694 double number, 0695 UChar* currency, 0696 UChar* result, 0697 int32_t resultLength, 0698 UFieldPosition* pos, 0699 UErrorCode* status); 0700 0701 /** 0702 * Format a UFormattable into a string. 0703 * @param fmt the formatter to use 0704 * @param number the number to format, as a UFormattable 0705 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If 0706 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) 0707 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number 0708 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR. 0709 * @param resultLength the maximum number of UChars to write to result 0710 * @param pos a pointer to a UFieldPosition. On input, 0711 * position->field is read. On output, position->beginIndex and 0712 * position->endIndex indicate the beginning and ending indices of 0713 * field number position->field, if such a field exists. This 0714 * parameter may be NULL, in which case it is ignored. 0715 * @param status a pointer to an input-output UErrorCode 0716 * @return the total buffer size needed; if greater than resultLength, 0717 * the output was truncated. Will return 0 on error. 0718 * @see unum_parseToUFormattable 0719 * @stable ICU 52 0720 */ 0721 U_CAPI int32_t U_EXPORT2 0722 unum_formatUFormattable(const UNumberFormat* fmt, 0723 const UFormattable *number, 0724 UChar *result, 0725 int32_t resultLength, 0726 UFieldPosition *pos, 0727 UErrorCode *status); 0728 0729 /** 0730 * Parse a string into an integer using a UNumberFormat. 0731 * The string will be parsed according to the UNumberFormat's locale. 0732 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT 0733 * and UNUM_DECIMAL_COMPACT_LONG. 0734 * @param fmt The formatter to use. 0735 * @param text The text to parse. 0736 * @param textLength The length of text, or -1 if null-terminated. 0737 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which 0738 * to begin parsing. If not NULL, on output the offset at which parsing ended. 0739 * @param status A pointer to an UErrorCode to receive any errors 0740 * @return The value of the parsed integer 0741 * @see unum_parseInt64 0742 * @see unum_parseDouble 0743 * @see unum_format 0744 * @see unum_formatInt64 0745 * @see unum_formatDouble 0746 * @stable ICU 2.0 0747 */ 0748 U_CAPI int32_t U_EXPORT2 0749 unum_parse( const UNumberFormat* fmt, 0750 const UChar* text, 0751 int32_t textLength, 0752 int32_t *parsePos /* 0 = start */, 0753 UErrorCode *status); 0754 0755 /** 0756 * Parse a string into an int64 using a UNumberFormat. 0757 * The string will be parsed according to the UNumberFormat's locale. 0758 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT 0759 * and UNUM_DECIMAL_COMPACT_LONG. 0760 * @param fmt The formatter to use. 0761 * @param text The text to parse. 0762 * @param textLength The length of text, or -1 if null-terminated. 0763 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which 0764 * to begin parsing. If not NULL, on output the offset at which parsing ended. 0765 * @param status A pointer to an UErrorCode to receive any errors 0766 * @return The value of the parsed integer 0767 * @see unum_parse 0768 * @see unum_parseDouble 0769 * @see unum_format 0770 * @see unum_formatInt64 0771 * @see unum_formatDouble 0772 * @stable ICU 2.8 0773 */ 0774 U_CAPI int64_t U_EXPORT2 0775 unum_parseInt64(const UNumberFormat* fmt, 0776 const UChar* text, 0777 int32_t textLength, 0778 int32_t *parsePos /* 0 = start */, 0779 UErrorCode *status); 0780 0781 /** 0782 * Parse a string into a double using a UNumberFormat. 0783 * The string will be parsed according to the UNumberFormat's locale. 0784 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT 0785 * and UNUM_DECIMAL_COMPACT_LONG. 0786 * @param fmt The formatter to use. 0787 * @param text The text to parse. 0788 * @param textLength The length of text, or -1 if null-terminated. 0789 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which 0790 * to begin parsing. If not NULL, on output the offset at which parsing ended. 0791 * @param status A pointer to an UErrorCode to receive any errors 0792 * @return The value of the parsed double 0793 * @see unum_parse 0794 * @see unum_parseInt64 0795 * @see unum_format 0796 * @see unum_formatInt64 0797 * @see unum_formatDouble 0798 * @stable ICU 2.0 0799 */ 0800 U_CAPI double U_EXPORT2 0801 unum_parseDouble( const UNumberFormat* fmt, 0802 const UChar* text, 0803 int32_t textLength, 0804 int32_t *parsePos /* 0 = start */, 0805 UErrorCode *status); 0806 0807 0808 /** 0809 * Parse a number from a string into an unformatted numeric string using a UNumberFormat. 0810 * The input string will be parsed according to the UNumberFormat's locale. 0811 * The syntax of the output is a "numeric string" 0812 * as defined in the Decimal Arithmetic Specification, available at 0813 * http://speleotrove.com/decimal 0814 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT 0815 * and UNUM_DECIMAL_COMPACT_LONG. 0816 * @param fmt The formatter to use. 0817 * @param text The text to parse. 0818 * @param textLength The length of text, or -1 if null-terminated. 0819 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which 0820 * to begin parsing. If not NULL, on output the offset at which parsing ended. 0821 * @param outBuf A (char *) buffer to receive the parsed number as a string. The output string 0822 * will be nul-terminated if there is sufficient space. 0823 * @param outBufLength The size of the output buffer. May be zero, in which case 0824 * the outBuf pointer may be NULL, and the function will return the 0825 * size of the output string. 0826 * @param status A pointer to an UErrorCode to receive any errors 0827 * @return the length of the output string, not including any terminating nul. 0828 * @see unum_parse 0829 * @see unum_parseInt64 0830 * @see unum_format 0831 * @see unum_formatInt64 0832 * @see unum_formatDouble 0833 * @stable ICU 4.4 0834 */ 0835 U_CAPI int32_t U_EXPORT2 0836 unum_parseDecimal(const UNumberFormat* fmt, 0837 const UChar* text, 0838 int32_t textLength, 0839 int32_t *parsePos /* 0 = start */, 0840 char *outBuf, 0841 int32_t outBufLength, 0842 UErrorCode *status); 0843 0844 /** 0845 * Parse a string into a double and a currency using a UNumberFormat. 0846 * The string will be parsed according to the UNumberFormat's locale. 0847 * @param fmt the formatter to use 0848 * @param text the text to parse 0849 * @param textLength the length of text, or -1 if null-terminated 0850 * @param parsePos a pointer to an offset index into text at which to 0851 * begin parsing. On output, *parsePos will point after the last 0852 * parsed character. This parameter may be NULL, in which case parsing 0853 * begins at offset 0. 0854 * @param currency a pointer to the buffer to receive the parsed null- 0855 * terminated currency. This buffer must have a capacity of at least 0856 * 4 UChars. 0857 * @param status a pointer to an input-output UErrorCode 0858 * @return the parsed double 0859 * @see unum_parseDouble 0860 * @see unum_formatDoubleCurrency 0861 * @stable ICU 3.0 0862 */ 0863 U_CAPI double U_EXPORT2 0864 unum_parseDoubleCurrency(const UNumberFormat* fmt, 0865 const UChar* text, 0866 int32_t textLength, 0867 int32_t* parsePos, /* 0 = start */ 0868 UChar* currency, 0869 UErrorCode* status); 0870 0871 /** 0872 * Parse a UChar string into a UFormattable. 0873 * Example code: 0874 * \snippet test/cintltst/cnumtst.c unum_parseToUFormattable 0875 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT 0876 * and UNUM_DECIMAL_COMPACT_LONG. 0877 * @param fmt the formatter to use 0878 * @param result the UFormattable to hold the result. If NULL, a new UFormattable will be allocated (which the caller must close with ufmt_close). 0879 * @param text the text to parse 0880 * @param textLength the length of text, or -1 if null-terminated 0881 * @param parsePos a pointer to an offset index into text at which to 0882 * begin parsing. On output, *parsePos will point after the last 0883 * parsed character. This parameter may be NULL in which case parsing 0884 * begins at offset 0. 0885 * @param status a pointer to an input-output UErrorCode 0886 * @return the UFormattable. Will be ==result unless NULL was passed in for result, in which case it will be the newly opened UFormattable. 0887 * @see ufmt_getType 0888 * @see ufmt_close 0889 * @stable ICU 52 0890 */ 0891 U_CAPI UFormattable* U_EXPORT2 0892 unum_parseToUFormattable(const UNumberFormat* fmt, 0893 UFormattable *result, 0894 const UChar* text, 0895 int32_t textLength, 0896 int32_t* parsePos, /* 0 = start */ 0897 UErrorCode* status); 0898 0899 /** 0900 * Set the pattern used by a UNumberFormat. This can only be used 0901 * on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR 0902 * in the status. 0903 * @param format The formatter to set. 0904 * @param localized true if the pattern is localized, false otherwise. 0905 * @param pattern The new pattern 0906 * @param patternLength The length of pattern, or -1 if null-terminated. 0907 * @param parseError A pointer to UParseError to receive information 0908 * about errors occurred during parsing, or NULL if no parse error 0909 * information is desired. 0910 * @param status A pointer to an input-output UErrorCode. 0911 * @see unum_toPattern 0912 * @see DecimalFormat 0913 * @stable ICU 2.0 0914 */ 0915 U_CAPI void U_EXPORT2 0916 unum_applyPattern( UNumberFormat *format, 0917 UBool localized, 0918 const UChar *pattern, 0919 int32_t patternLength, 0920 UParseError *parseError, 0921 UErrorCode *status 0922 ); 0923 0924 /** 0925 * Get a locale for which decimal formatting patterns are available. 0926 * A UNumberFormat in a locale returned by this function will perform the correct 0927 * formatting and parsing for the locale. The results of this call are not 0928 * valid for rule-based number formats. 0929 * @param localeIndex The index of the desired locale. 0930 * @return A locale for which number formatting patterns are available, or 0 if none. 0931 * @see unum_countAvailable 0932 * @stable ICU 2.0 0933 */ 0934 U_CAPI const char* U_EXPORT2 0935 unum_getAvailable(int32_t localeIndex); 0936 0937 /** 0938 * Determine how many locales have decimal formatting patterns available. The 0939 * results of this call are not valid for rule-based number formats. 0940 * This function is useful for determining the loop ending condition for 0941 * calls to {@link #unum_getAvailable }. 0942 * @return The number of locales for which decimal formatting patterns are available. 0943 * @see unum_getAvailable 0944 * @stable ICU 2.0 0945 */ 0946 U_CAPI int32_t U_EXPORT2 0947 unum_countAvailable(void); 0948 0949 #if UCONFIG_HAVE_PARSEALLINPUT 0950 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */ 0951 /** 0952 * @internal 0953 */ 0954 typedef enum UNumberFormatAttributeValue { 0955 #ifndef U_HIDE_INTERNAL_API 0956 /** @internal */ 0957 UNUM_NO = 0, 0958 /** @internal */ 0959 UNUM_YES = 1, 0960 /** @internal */ 0961 UNUM_MAYBE = 2 0962 #else 0963 /** @internal */ 0964 UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN 0965 #endif /* U_HIDE_INTERNAL_API */ 0966 } UNumberFormatAttributeValue; 0967 #endif 0968 0969 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */ 0970 typedef enum UNumberFormatAttribute { 0971 /** Parse integers only */ 0972 UNUM_PARSE_INT_ONLY, 0973 /** Use grouping separator */ 0974 UNUM_GROUPING_USED, 0975 /** Always show decimal point */ 0976 UNUM_DECIMAL_ALWAYS_SHOWN, 0977 /** Maximum integer digits */ 0978 UNUM_MAX_INTEGER_DIGITS, 0979 /** Minimum integer digits */ 0980 UNUM_MIN_INTEGER_DIGITS, 0981 /** Integer digits */ 0982 UNUM_INTEGER_DIGITS, 0983 /** Maximum fraction digits */ 0984 UNUM_MAX_FRACTION_DIGITS, 0985 /** Minimum fraction digits */ 0986 UNUM_MIN_FRACTION_DIGITS, 0987 /** Fraction digits */ 0988 UNUM_FRACTION_DIGITS, 0989 /** Multiplier */ 0990 UNUM_MULTIPLIER, 0991 /** Grouping size */ 0992 UNUM_GROUPING_SIZE, 0993 /** Rounding Mode */ 0994 UNUM_ROUNDING_MODE, 0995 /** Rounding increment */ 0996 UNUM_ROUNDING_INCREMENT, 0997 /** The width to which the output of <code>format()</code> is padded. */ 0998 UNUM_FORMAT_WIDTH, 0999 /** The position at which padding will take place. */ 1000 UNUM_PADDING_POSITION, 1001 /** Secondary grouping size */ 1002 UNUM_SECONDARY_GROUPING_SIZE, 1003 /** Use significant digits 1004 * @stable ICU 3.0 */ 1005 UNUM_SIGNIFICANT_DIGITS_USED, 1006 /** Minimum significant digits 1007 * @stable ICU 3.0 */ 1008 UNUM_MIN_SIGNIFICANT_DIGITS, 1009 /** Maximum significant digits 1010 * @stable ICU 3.0 */ 1011 UNUM_MAX_SIGNIFICANT_DIGITS, 1012 /** Lenient parse mode used by rule-based formats. 1013 * @stable ICU 3.0 1014 */ 1015 UNUM_LENIENT_PARSE, 1016 #if UCONFIG_HAVE_PARSEALLINPUT 1017 /** Consume all input. (may use fastpath). Set to UNUM_YES (require fastpath), UNUM_NO (skip fastpath), or UNUM_MAYBE (heuristic). 1018 * This is an internal ICU API. Do not use. 1019 * @internal 1020 */ 1021 UNUM_PARSE_ALL_INPUT = 20, 1022 #endif 1023 /** 1024 * Scale, which adjusts the position of the 1025 * decimal point when formatting. Amounts will be multiplied by 10 ^ (scale) 1026 * before they are formatted. The default value for the scale is 0 ( no adjustment ). 1027 * 1028 * <p>Example: setting the scale to 3, 123 formats as "123,000" 1029 * <p>Example: setting the scale to -4, 123 formats as "0.0123" 1030 * 1031 * This setting is analogous to getMultiplierScale() and setMultiplierScale() in decimfmt.h. 1032 * 1033 * @stable ICU 51 */ 1034 UNUM_SCALE = 21, 1035 1036 /** 1037 * Minimum grouping digits; most commonly set to 2 to print "1000" instead of "1,000". 1038 * See DecimalFormat::getMinimumGroupingDigits(). 1039 * 1040 * For better control over grouping strategies, use UNumberFormatter. 1041 * 1042 * @stable ICU 64 1043 */ 1044 UNUM_MINIMUM_GROUPING_DIGITS = 22, 1045 1046 /** 1047 * if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose, 1048 * otherwise it is UNUM_CASH_CURRENCY purpose 1049 * Default: 0 (UNUM_CURRENCY_STANDARD purpose) 1050 * @stable ICU 54 1051 */ 1052 UNUM_CURRENCY_USAGE = 23, 1053 1054 #ifndef U_HIDE_INTERNAL_API 1055 /** One below the first bitfield-boolean item. 1056 * All items after this one are stored in boolean form. 1057 * @internal */ 1058 UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF, 1059 #endif /* U_HIDE_INTERNAL_API */ 1060 1061 /** If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating. 1062 * For example, formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing. 1063 * Default: 0 (not set) 1064 * @stable ICU 50 1065 */ 1066 UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000, 1067 /** 1068 * 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. 1069 * Has no effect on formatting. 1070 * Default: 0 (unset) 1071 * @stable ICU 50 1072 */ 1073 UNUM_PARSE_NO_EXPONENT = 0x1001, 1074 1075 /** 1076 * if this attribute is set to 1, specifies that, if the pattern contains a 1077 * decimal mark the input is required to have one. If this attribute is set to 0, 1078 * specifies that input does not have to contain a decimal mark. 1079 * Has no effect on formatting. 1080 * Default: 0 (unset) 1081 * @stable ICU 54 1082 */ 1083 UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002, 1084 1085 /** 1086 * Parsing: if set to 1, parsing is sensitive to case (lowercase/uppercase). 1087 * 1088 * @stable ICU 64 1089 */ 1090 UNUM_PARSE_CASE_SENSITIVE = 0x1003, 1091 1092 /** 1093 * Formatting: if set to 1, whether to show the plus sign on non-negative numbers. 1094 * 1095 * For better control over sign display, use UNumberFormatter. 1096 * 1097 * @stable ICU 64 1098 */ 1099 UNUM_SIGN_ALWAYS_SHOWN = 0x1004, 1100 1101 #ifndef U_HIDE_INTERNAL_API 1102 /** Limit of boolean attributes. (value should 1103 * not depend on U_HIDE conditionals) 1104 * @internal */ 1105 UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1005, 1106 #endif /* U_HIDE_INTERNAL_API */ 1107 1108 } UNumberFormatAttribute; 1109 1110 /** 1111 * Returns true if the formatter supports the specified attribute and false if not. 1112 * @param fmt The formatter to query. 1113 * @param attr The attribute to query. This can be any value of UNumberFormatterAttribute, 1114 * regardless of type. 1115 * @return True if the requested attribute is supported by the formatter; false if not. 1116 * @see unum_getAttribute 1117 * @see unum_setAttribute 1118 * @see unum_getDoubleAttribute 1119 * @see unum_setDoubleAttribute 1120 * @see unum_getTextAttribute 1121 * @see unum_setTextAttribute 1122 * @stable ICU 72 1123 */ 1124 U_CAPI bool U_EXPORT2 1125 unum_hasAttribute(const UNumberFormat* fmt, 1126 UNumberFormatAttribute attr); 1127 1128 /** 1129 * Get a numeric attribute associated with a UNumberFormat. 1130 * An example of a numeric attribute is the number of integer digits a formatter will produce. 1131 * @param fmt The formatter to query. 1132 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, 1133 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, 1134 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, 1135 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, 1136 * UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS. 1137 * @return The value of attr, or -1 if the formatter doesn't have the requested attribute. The caller should use unum_hasAttribute() to tell if the attribute 1138 * is available, rather than relaying on this function returning -1. 1139 * @see unum_hasAttribute 1140 * @see unum_setAttribute 1141 * @see unum_getDoubleAttribute 1142 * @see unum_setDoubleAttribute 1143 * @stable ICU 2.0 1144 */ 1145 U_CAPI int32_t U_EXPORT2 1146 unum_getAttribute(const UNumberFormat* fmt, 1147 UNumberFormatAttribute attr); 1148 1149 /** 1150 * Set a numeric attribute associated with a UNumberFormat. 1151 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the 1152 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand 1153 * the lenient-parse attribute. The caller can use unum_hasAttribute() to find out if the formatter supports the attribute. 1154 * @param fmt The formatter to set. 1155 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, 1156 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, 1157 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, 1158 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, 1159 * UNUM_LENIENT_PARSE, UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS. 1160 * @param newValue The new value of attr. 1161 * @see unum_hasAttribute 1162 * @see unum_getAttribute 1163 * @see unum_getDoubleAttribute 1164 * @see unum_setDoubleAttribute 1165 * @see unum_getTextAttribute 1166 * @see unum_setTextAttribute 1167 * @stable ICU 2.0 1168 */ 1169 U_CAPI void U_EXPORT2 1170 unum_setAttribute( UNumberFormat* fmt, 1171 UNumberFormatAttribute attr, 1172 int32_t newValue); 1173 1174 1175 /** 1176 * Get a numeric attribute associated with a UNumberFormat. 1177 * An example of a numeric attribute is the number of integer digits a formatter will produce. 1178 * If the formatter does not understand the attribute, -1 is returned. The caller should use unum_hasAttribute() 1179 * to determine if the attribute is supported, rather than relying on this function returning -1. 1180 * @param fmt The formatter to query. 1181 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT. 1182 * @return The value of attr, or -1 if the formatter doesn't understand the attribute. 1183 * @see unum_hasAttribute 1184 * @see unum_getAttribute 1185 * @see unum_setAttribute 1186 * @see unum_setDoubleAttribute 1187 * @see unum_getTextAttribute 1188 * @see unum_setTextAttribute 1189 * @stable ICU 2.0 1190 */ 1191 U_CAPI double U_EXPORT2 1192 unum_getDoubleAttribute(const UNumberFormat* fmt, 1193 UNumberFormatAttribute attr); 1194 1195 /** 1196 * Set a numeric attribute associated with a UNumberFormat. 1197 * An example of a numeric attribute is the number of integer digits a formatter will produce. 1198 * If the formatter does not understand the attribute, this call is ignored. The caller can use 1199 * unum_hasAttribute() to tell in advance whether the formatter understands the attribute. 1200 * @param fmt The formatter to set. 1201 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT. 1202 * @param newValue The new value of attr. 1203 * @see unum_hasAttribute 1204 * @see unum_getAttribute 1205 * @see unum_setAttribute 1206 * @see unum_getDoubleAttribute 1207 * @see unum_getTextAttribute 1208 * @see unum_setTextAttribute 1209 * @stable ICU 2.0 1210 */ 1211 U_CAPI void U_EXPORT2 1212 unum_setDoubleAttribute( UNumberFormat* fmt, 1213 UNumberFormatAttribute attr, 1214 double newValue); 1215 1216 /** The possible UNumberFormat text attributes @stable ICU 2.0*/ 1217 typedef enum UNumberFormatTextAttribute { 1218 /** Positive prefix */ 1219 UNUM_POSITIVE_PREFIX, 1220 /** Positive suffix */ 1221 UNUM_POSITIVE_SUFFIX, 1222 /** Negative prefix */ 1223 UNUM_NEGATIVE_PREFIX, 1224 /** Negative suffix */ 1225 UNUM_NEGATIVE_SUFFIX, 1226 /** The character used to pad to the format width. */ 1227 UNUM_PADDING_CHARACTER, 1228 /** The ISO currency code */ 1229 UNUM_CURRENCY_CODE, 1230 /** 1231 * The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:", 1232 * "%spellout-ordinal-masculine-plural:", "%spellout-ordinal-feminine:", or 1233 * "%spellout-ordinal-neuter:". The available public rulesets can be listed using 1234 * unum_getTextAttribute with UNUM_PUBLIC_RULESETS. This is only available with 1235 * rule-based formatters. 1236 * @stable ICU 3.0 1237 */ 1238 UNUM_DEFAULT_RULESET, 1239 /** 1240 * The public rule sets. This is only available with rule-based formatters. 1241 * This is a read-only attribute. The public rulesets are returned as a 1242 * single string, with each ruleset name delimited by ';' (semicolon). See the 1243 * CLDR LDML spec for more information about RBNF rulesets: 1244 * http://www.unicode.org/reports/tr35/tr35-numbers.html#Rule-Based_Number_Formatting 1245 * @stable ICU 3.0 1246 */ 1247 UNUM_PUBLIC_RULESETS 1248 } UNumberFormatTextAttribute; 1249 1250 /** 1251 * Get a text attribute associated with a UNumberFormat. 1252 * An example of a text attribute is the suffix for positive numbers. If the formatter 1253 * does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status. 1254 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS. 1255 * @param fmt The formatter to query. 1256 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, 1257 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, 1258 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS. 1259 * @param result A pointer to a buffer to receive the attribute. 1260 * @param resultLength The maximum size of result. 1261 * @param status A pointer to an UErrorCode to receive any errors 1262 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1263 * @see unum_setTextAttribute 1264 * @see unum_getAttribute 1265 * @see unum_setAttribute 1266 * @stable ICU 2.0 1267 */ 1268 U_CAPI int32_t U_EXPORT2 1269 unum_getTextAttribute( const UNumberFormat* fmt, 1270 UNumberFormatTextAttribute tag, 1271 UChar* result, 1272 int32_t resultLength, 1273 UErrorCode* status); 1274 1275 /** 1276 * Set a text attribute associated with a UNumberFormat. 1277 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters 1278 * only understand UNUM_DEFAULT_RULESET. 1279 * @param fmt The formatter to set. 1280 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, 1281 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, 1282 * or UNUM_DEFAULT_RULESET. 1283 * @param newValue The new value of attr. 1284 * @param newValueLength The length of newValue, or -1 if null-terminated. 1285 * @param status A pointer to an UErrorCode to receive any errors 1286 * @see unum_getTextAttribute 1287 * @see unum_getAttribute 1288 * @see unum_setAttribute 1289 * @stable ICU 2.0 1290 */ 1291 U_CAPI void U_EXPORT2 1292 unum_setTextAttribute( UNumberFormat* fmt, 1293 UNumberFormatTextAttribute tag, 1294 const UChar* newValue, 1295 int32_t newValueLength, 1296 UErrorCode *status); 1297 1298 /** 1299 * Extract the pattern from a UNumberFormat. The pattern will follow 1300 * the DecimalFormat pattern syntax. 1301 * @param fmt The formatter to query. 1302 * @param isPatternLocalized true if the pattern should be localized, 1303 * false otherwise. This is ignored if the formatter is a rule-based 1304 * formatter. 1305 * @param result A pointer to a buffer to receive the pattern. 1306 * @param resultLength The maximum size of result. 1307 * @param status A pointer to an input-output UErrorCode. 1308 * @return The total buffer size needed; if greater than resultLength, 1309 * the output was truncated. 1310 * @see unum_applyPattern 1311 * @see DecimalFormat 1312 * @stable ICU 2.0 1313 */ 1314 U_CAPI int32_t U_EXPORT2 1315 unum_toPattern( const UNumberFormat* fmt, 1316 UBool isPatternLocalized, 1317 UChar* result, 1318 int32_t resultLength, 1319 UErrorCode* status); 1320 1321 1322 /** 1323 * Constants for specifying a number format symbol. 1324 * @stable ICU 2.0 1325 */ 1326 typedef enum UNumberFormatSymbol { 1327 /** The decimal separator */ 1328 UNUM_DECIMAL_SEPARATOR_SYMBOL = 0, 1329 /** The grouping separator */ 1330 UNUM_GROUPING_SEPARATOR_SYMBOL = 1, 1331 /** The pattern separator */ 1332 UNUM_PATTERN_SEPARATOR_SYMBOL = 2, 1333 /** The percent sign */ 1334 UNUM_PERCENT_SYMBOL = 3, 1335 /** Zero*/ 1336 UNUM_ZERO_DIGIT_SYMBOL = 4, 1337 /** Character representing a digit in the pattern */ 1338 UNUM_DIGIT_SYMBOL = 5, 1339 /** The minus sign */ 1340 UNUM_MINUS_SIGN_SYMBOL = 6, 1341 /** The plus sign */ 1342 UNUM_PLUS_SIGN_SYMBOL = 7, 1343 /** The currency symbol */ 1344 UNUM_CURRENCY_SYMBOL = 8, 1345 /** The international currency symbol */ 1346 UNUM_INTL_CURRENCY_SYMBOL = 9, 1347 /** The monetary separator */ 1348 UNUM_MONETARY_SEPARATOR_SYMBOL = 10, 1349 /** The exponential symbol */ 1350 UNUM_EXPONENTIAL_SYMBOL = 11, 1351 /** Per mill symbol */ 1352 UNUM_PERMILL_SYMBOL = 12, 1353 /** Escape padding character */ 1354 UNUM_PAD_ESCAPE_SYMBOL = 13, 1355 /** Infinity symbol */ 1356 UNUM_INFINITY_SYMBOL = 14, 1357 /** Nan symbol */ 1358 UNUM_NAN_SYMBOL = 15, 1359 /** Significant digit symbol 1360 * @stable ICU 3.0 */ 1361 UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16, 1362 /** The monetary grouping separator 1363 * @stable ICU 3.6 1364 */ 1365 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, 1366 /** One 1367 * @stable ICU 4.6 1368 */ 1369 UNUM_ONE_DIGIT_SYMBOL = 18, 1370 /** Two 1371 * @stable ICU 4.6 1372 */ 1373 UNUM_TWO_DIGIT_SYMBOL = 19, 1374 /** Three 1375 * @stable ICU 4.6 1376 */ 1377 UNUM_THREE_DIGIT_SYMBOL = 20, 1378 /** Four 1379 * @stable ICU 4.6 1380 */ 1381 UNUM_FOUR_DIGIT_SYMBOL = 21, 1382 /** Five 1383 * @stable ICU 4.6 1384 */ 1385 UNUM_FIVE_DIGIT_SYMBOL = 22, 1386 /** Six 1387 * @stable ICU 4.6 1388 */ 1389 UNUM_SIX_DIGIT_SYMBOL = 23, 1390 /** Seven 1391 * @stable ICU 4.6 1392 */ 1393 UNUM_SEVEN_DIGIT_SYMBOL = 24, 1394 /** Eight 1395 * @stable ICU 4.6 1396 */ 1397 UNUM_EIGHT_DIGIT_SYMBOL = 25, 1398 /** Nine 1399 * @stable ICU 4.6 1400 */ 1401 UNUM_NINE_DIGIT_SYMBOL = 26, 1402 1403 /** Multiplication sign 1404 * @stable ICU 54 1405 */ 1406 UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27, 1407 1408 #ifndef U_HIDE_INTERNAL_API 1409 /** Approximately sign. 1410 * @internal 1411 */ 1412 UNUM_APPROXIMATELY_SIGN_SYMBOL = 28, 1413 #endif 1414 1415 #ifndef U_HIDE_DEPRECATED_API 1416 /** 1417 * One more than the highest normal UNumberFormatSymbol value. 1418 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 1419 */ 1420 UNUM_FORMAT_SYMBOL_COUNT = 29 1421 #endif /* U_HIDE_DEPRECATED_API */ 1422 } UNumberFormatSymbol; 1423 1424 /** 1425 * Get a symbol associated with a UNumberFormat. 1426 * A UNumberFormat uses symbols to represent the special locale-dependent 1427 * characters in a number, for example the percent sign. This API is not 1428 * supported for rule-based formatters. 1429 * @param fmt The formatter to query. 1430 * @param symbol The UNumberFormatSymbol constant for the symbol to get 1431 * @param buffer The string buffer that will receive the symbol string; 1432 * if it is NULL, then only the length of the symbol is returned 1433 * @param size The size of the string buffer 1434 * @param status A pointer to an UErrorCode to receive any errors 1435 * @return The length of the symbol; the buffer is not modified if 1436 * <code>length>=size</code> 1437 * @see unum_setSymbol 1438 * @stable ICU 2.0 1439 */ 1440 U_CAPI int32_t U_EXPORT2 1441 unum_getSymbol(const UNumberFormat *fmt, 1442 UNumberFormatSymbol symbol, 1443 UChar *buffer, 1444 int32_t size, 1445 UErrorCode *status); 1446 1447 /** 1448 * Set a symbol associated with a UNumberFormat. 1449 * A UNumberFormat uses symbols to represent the special locale-dependent 1450 * characters in a number, for example the percent sign. This API is not 1451 * supported for rule-based formatters. 1452 * @param fmt The formatter to set. 1453 * @param symbol The UNumberFormatSymbol constant for the symbol to set 1454 * @param value The string to set the symbol to 1455 * @param length The length of the string, or -1 for a zero-terminated string 1456 * @param status A pointer to an UErrorCode to receive any errors. 1457 * @see unum_getSymbol 1458 * @stable ICU 2.0 1459 */ 1460 U_CAPI void U_EXPORT2 1461 unum_setSymbol(UNumberFormat *fmt, 1462 UNumberFormatSymbol symbol, 1463 const UChar *value, 1464 int32_t length, 1465 UErrorCode *status); 1466 1467 1468 /** 1469 * Get the locale for this number format object. 1470 * You can choose between valid and actual locale. 1471 * @param fmt The formatter to get the locale from 1472 * @param type type of the locale we're looking for (valid or actual) 1473 * @param status error code for the operation 1474 * @return the locale name 1475 * @stable ICU 2.8 1476 */ 1477 U_CAPI const char* U_EXPORT2 1478 unum_getLocaleByType(const UNumberFormat *fmt, 1479 ULocDataLocaleType type, 1480 UErrorCode* status); 1481 1482 /** 1483 * Set a particular UDisplayContext value in the formatter, such as 1484 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. 1485 * @param fmt The formatter for which to set a UDisplayContext value. 1486 * @param value The UDisplayContext value to set. 1487 * @param status A pointer to an UErrorCode to receive any errors 1488 * @stable ICU 53 1489 */ 1490 U_CAPI void U_EXPORT2 1491 unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status); 1492 1493 /** 1494 * Get the formatter's UDisplayContext value for the specified UDisplayContextType, 1495 * such as UDISPCTX_TYPE_CAPITALIZATION. 1496 * @param fmt The formatter to query. 1497 * @param type The UDisplayContextType whose value to return 1498 * @param status A pointer to an UErrorCode to receive any errors 1499 * @return The UDisplayContextValue for the specified type. 1500 * @stable ICU 53 1501 */ 1502 U_CAPI UDisplayContext U_EXPORT2 1503 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status); 1504 1505 #endif /* #if !UCONFIG_NO_FORMATTING */ 1506 1507 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |