ICU 73.2  73.2
unum.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 *******************************************************************************
00005 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
00006 * All Rights Reserved.
00007 * Modification History:
00008 *
00009 *   Date        Name        Description
00010 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
00011 *******************************************************************************
00012 */
00013 
00014 #ifndef _UNUM
00015 #define _UNUM
00016 
00017 #include "unicode/utypes.h"
00018 
00019 #if !UCONFIG_NO_FORMATTING
00020 
00021 #include "unicode/uloc.h"
00022 #include "unicode/ucurr.h"
00023 #include "unicode/umisc.h"
00024 #include "unicode/parseerr.h"
00025 #include "unicode/uformattable.h"
00026 #include "unicode/udisplaycontext.h"
00027 #include "unicode/ufieldpositer.h"
00028 #include "unicode/unumberoptions.h"
00029 
00030 #if U_SHOW_CPLUSPLUS_API
00031 #include "unicode/localpointer.h"
00032 #endif   // U_SHOW_CPLUSPLUS_API
00033 
00145 typedef void* UNumberFormat;
00146 
00150 typedef enum UNumberFormatStyle {
00155     UNUM_PATTERN_DECIMAL=0,
00160     UNUM_DECIMAL=1,
00169     UNUM_CURRENCY=2,
00174     UNUM_PERCENT=3,
00179     UNUM_SCIENTIFIC=4,
00186     UNUM_SPELLOUT=5,
00193     UNUM_ORDINAL=6,
00198     UNUM_DURATION=7,
00203     UNUM_NUMBERING_SYSTEM=8,
00208     UNUM_PATTERN_RULEBASED=9,
00213     UNUM_CURRENCY_ISO=10,
00219     UNUM_CURRENCY_PLURAL=11,
00226     UNUM_CURRENCY_ACCOUNTING=12,
00232     UNUM_CASH_CURRENCY=13,
00239     UNUM_DECIMAL_COMPACT_SHORT=14,
00246     UNUM_DECIMAL_COMPACT_LONG=15,
00253     UNUM_CURRENCY_STANDARD=16,
00254 
00255 #ifndef U_HIDE_DEPRECATED_API
00256 
00260     UNUM_FORMAT_STYLE_COUNT=17,
00261 #endif  /* U_HIDE_DEPRECATED_API */
00262 
00267     UNUM_DEFAULT = UNUM_DECIMAL,
00272     UNUM_IGNORE = UNUM_PATTERN_DECIMAL
00273 } UNumberFormatStyle;
00274 
00278 typedef enum UNumberFormatPadPosition {
00279     UNUM_PAD_BEFORE_PREFIX,
00280     UNUM_PAD_AFTER_PREFIX,
00281     UNUM_PAD_BEFORE_SUFFIX,
00282     UNUM_PAD_AFTER_SUFFIX
00283 } UNumberFormatPadPosition;
00284 
00289 typedef enum UNumberCompactStyle {
00291   UNUM_SHORT,
00293   UNUM_LONG
00295 } UNumberCompactStyle;
00296 
00301 enum UCurrencySpacing {
00303     UNUM_CURRENCY_MATCH,
00305     UNUM_CURRENCY_SURROUNDING_MATCH,
00307     UNUM_CURRENCY_INSERT,
00308 
00309     /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
00310      * it is needed for layout of DecimalFormatSymbols object. */
00311 #ifndef U_FORCE_HIDE_DEPRECATED_API
00312 
00316     UNUM_CURRENCY_SPACING_COUNT
00317 #endif  // U_FORCE_HIDE_DEPRECATED_API
00318 };
00319 typedef enum UCurrencySpacing UCurrencySpacing; 
00327 typedef enum UNumberFormatFields {
00329     UNUM_INTEGER_FIELD,
00331     UNUM_FRACTION_FIELD,
00333     UNUM_DECIMAL_SEPARATOR_FIELD,
00335     UNUM_EXPONENT_SYMBOL_FIELD,
00337     UNUM_EXPONENT_SIGN_FIELD,
00339     UNUM_EXPONENT_FIELD,
00341     UNUM_GROUPING_SEPARATOR_FIELD,
00343     UNUM_CURRENCY_FIELD,
00345     UNUM_PERCENT_FIELD,
00347     UNUM_PERMILL_FIELD,
00349     UNUM_SIGN_FIELD,
00351     UNUM_MEASURE_UNIT_FIELD,
00353     UNUM_COMPACT_FIELD,
00358     UNUM_APPROXIMATELY_SIGN_FIELD,
00359 
00360 #ifndef U_HIDE_DEPRECATED_API
00361 
00365     UNUM_FIELD_COUNT
00366 #endif  /* U_HIDE_DEPRECATED_API */
00367 } UNumberFormatFields;
00368 
00369 
00377 typedef enum UNumberFormatMinimumGroupingDigits {
00382     UNUM_MINIMUM_GROUPING_DIGITS_AUTO = -2,
00389     UNUM_MINIMUM_GROUPING_DIGITS_MIN2 = -3,
00390 } UNumberFormatMinimumGroupingDigits;
00391 
00429 U_CAPI UNumberFormat* U_EXPORT2 
00430 unum_open(  UNumberFormatStyle    style,
00431             const    UChar*    pattern,
00432             int32_t            patternLength,
00433             const    char*     locale,
00434             UParseError*       parseErr,
00435             UErrorCode*        status);
00436 
00437 
00444 U_CAPI void U_EXPORT2 
00445 unum_close(UNumberFormat* fmt);
00446 
00447 #if U_SHOW_CPLUSPLUS_API
00448 
00449 U_NAMESPACE_BEGIN
00450 
00460 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
00461 
00462 U_NAMESPACE_END
00463 
00464 #endif
00465 
00474 U_CAPI UNumberFormat* U_EXPORT2 
00475 unum_clone(const UNumberFormat *fmt,
00476        UErrorCode *status);
00477 
00502 U_CAPI int32_t U_EXPORT2 
00503 unum_format(    const    UNumberFormat*    fmt,
00504         int32_t            number,
00505         UChar*            result,
00506         int32_t            resultLength,
00507         UFieldPosition    *pos,
00508         UErrorCode*        status);
00509 
00534 U_CAPI int32_t U_EXPORT2 
00535 unum_formatInt64(const UNumberFormat *fmt,
00536         int64_t         number,
00537         UChar*          result,
00538         int32_t         resultLength,
00539         UFieldPosition *pos,
00540         UErrorCode*     status);
00541 
00566 U_CAPI int32_t U_EXPORT2 
00567 unum_formatDouble(    const    UNumberFormat*  fmt,
00568             double          number,
00569             UChar*          result,
00570             int32_t         resultLength,
00571             UFieldPosition  *pos, /* 0 if ignore */
00572             UErrorCode*     status);
00573 
00616 U_CAPI int32_t U_EXPORT2
00617 unum_formatDoubleForFields(const UNumberFormat* format,
00618                            double number,
00619                            UChar* result,
00620                            int32_t resultLength,
00621                            UFieldPositionIterator* fpositer,
00622                            UErrorCode* status);
00623 
00624 
00653 U_CAPI int32_t U_EXPORT2 
00654 unum_formatDecimal(    const    UNumberFormat*  fmt,
00655             const char *    number,
00656             int32_t         length,
00657             UChar*          result,
00658             int32_t         resultLength,
00659             UFieldPosition  *pos, /* 0 if ignore */
00660             UErrorCode*     status);
00661 
00692 U_CAPI int32_t U_EXPORT2
00693 unum_formatDoubleCurrency(const UNumberFormat* fmt,
00694                           double number,
00695                           UChar* currency,
00696                           UChar* result,
00697                           int32_t resultLength,
00698                           UFieldPosition* pos,
00699                           UErrorCode* status);
00700 
00721 U_CAPI int32_t U_EXPORT2
00722 unum_formatUFormattable(const UNumberFormat* fmt,
00723                         const UFormattable *number,
00724                         UChar *result,
00725                         int32_t resultLength,
00726                         UFieldPosition *pos,
00727                         UErrorCode *status);
00728 
00748 U_CAPI int32_t U_EXPORT2 
00749 unum_parse(    const   UNumberFormat*  fmt,
00750         const   UChar*          text,
00751         int32_t         textLength,
00752         int32_t         *parsePos /* 0 = start */,
00753         UErrorCode      *status);
00754 
00774 U_CAPI int64_t U_EXPORT2 
00775 unum_parseInt64(const UNumberFormat*  fmt,
00776         const UChar*  text,
00777         int32_t       textLength,
00778         int32_t       *parsePos /* 0 = start */,
00779         UErrorCode    *status);
00780 
00800 U_CAPI double U_EXPORT2 
00801 unum_parseDouble(    const   UNumberFormat*  fmt,
00802             const   UChar*          text,
00803             int32_t         textLength,
00804             int32_t         *parsePos /* 0 = start */,
00805             UErrorCode      *status);
00806 
00807 
00835 U_CAPI int32_t U_EXPORT2 
00836 unum_parseDecimal(const   UNumberFormat*  fmt,
00837                  const   UChar*          text,
00838                          int32_t         textLength,
00839                          int32_t         *parsePos /* 0 = start */,
00840                          char            *outBuf,
00841                          int32_t         outBufLength,
00842                          UErrorCode      *status);
00843 
00863 U_CAPI double U_EXPORT2
00864 unum_parseDoubleCurrency(const UNumberFormat* fmt,
00865                          const UChar* text,
00866                          int32_t textLength,
00867                          int32_t* parsePos, /* 0 = start */
00868                          UChar* currency,
00869                          UErrorCode* status);
00870 
00891 U_CAPI UFormattable* U_EXPORT2
00892 unum_parseToUFormattable(const UNumberFormat* fmt,
00893                          UFormattable *result,
00894                          const UChar* text,
00895                          int32_t textLength,
00896                          int32_t* parsePos, /* 0 = start */
00897                          UErrorCode* status);
00898 
00915 U_CAPI void U_EXPORT2 
00916 unum_applyPattern(          UNumberFormat  *format,
00917                             UBool          localized,
00918                     const   UChar          *pattern,
00919                             int32_t         patternLength,
00920                             UParseError    *parseError,
00921                             UErrorCode     *status
00922                                     );
00923 
00934 U_CAPI const char* U_EXPORT2 
00935 unum_getAvailable(int32_t localeIndex);
00936 
00946 U_CAPI int32_t U_EXPORT2 
00947 unum_countAvailable(void);
00948 
00949 #if UCONFIG_HAVE_PARSEALLINPUT
00950 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
00954 typedef enum UNumberFormatAttributeValue {
00955 #ifndef U_HIDE_INTERNAL_API
00956 
00957   UNUM_NO = 0,
00959   UNUM_YES = 1,
00961   UNUM_MAYBE = 2
00962 #else
00963 
00964   UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
00965 #endif /* U_HIDE_INTERNAL_API */
00966 } UNumberFormatAttributeValue;
00967 #endif
00968 
00970 typedef enum UNumberFormatAttribute {
00972   UNUM_PARSE_INT_ONLY,
00974   UNUM_GROUPING_USED,
00976   UNUM_DECIMAL_ALWAYS_SHOWN,
00978   UNUM_MAX_INTEGER_DIGITS,
00980   UNUM_MIN_INTEGER_DIGITS,
00982   UNUM_INTEGER_DIGITS,
00984   UNUM_MAX_FRACTION_DIGITS,
00986   UNUM_MIN_FRACTION_DIGITS,
00988   UNUM_FRACTION_DIGITS,
00990   UNUM_MULTIPLIER,
00992   UNUM_GROUPING_SIZE,
00994   UNUM_ROUNDING_MODE,
00996   UNUM_ROUNDING_INCREMENT,
00998   UNUM_FORMAT_WIDTH,
01000   UNUM_PADDING_POSITION,
01002   UNUM_SECONDARY_GROUPING_SIZE,
01005   UNUM_SIGNIFICANT_DIGITS_USED,
01008   UNUM_MIN_SIGNIFICANT_DIGITS,
01011   UNUM_MAX_SIGNIFICANT_DIGITS,
01015   UNUM_LENIENT_PARSE,
01016 #if UCONFIG_HAVE_PARSEALLINPUT
01017 
01021   UNUM_PARSE_ALL_INPUT = 20,
01022 #endif
01023 
01034   UNUM_SCALE = 21,
01035 
01044   UNUM_MINIMUM_GROUPING_DIGITS = 22,
01045 
01052   UNUM_CURRENCY_USAGE = 23,
01053 
01054 #ifndef U_HIDE_INTERNAL_API
01055 
01058   UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF,
01059 #endif /* U_HIDE_INTERNAL_API */
01060 
01066   UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000,
01073   UNUM_PARSE_NO_EXPONENT = 0x1001,
01074 
01083   UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002,
01084 
01090   UNUM_PARSE_CASE_SENSITIVE = 0x1003,
01091 
01099   UNUM_SIGN_ALWAYS_SHOWN = 0x1004,
01100 
01101 #ifndef U_HIDE_INTERNAL_API
01102 
01105   UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1005,
01106 #endif /* U_HIDE_INTERNAL_API */
01107 
01108 } UNumberFormatAttribute;
01109 
01110 #ifndef U_HIDE_DRAFT_API
01111 
01125 U_CAPI bool U_EXPORT2
01126 unum_hasAttribute(const UNumberFormat*          fmt,
01127           UNumberFormatAttribute  attr);
01128 #endif // U_HIDE_DRAFT_API
01129 
01147 U_CAPI int32_t U_EXPORT2 
01148 unum_getAttribute(const UNumberFormat*          fmt,
01149           UNumberFormatAttribute  attr);
01150 
01171 U_CAPI void U_EXPORT2 
01172 unum_setAttribute(    UNumberFormat*          fmt,
01173             UNumberFormatAttribute  attr,
01174             int32_t                 newValue);
01175 
01176 
01193 U_CAPI double U_EXPORT2 
01194 unum_getDoubleAttribute(const UNumberFormat*          fmt,
01195           UNumberFormatAttribute  attr);
01196 
01213 U_CAPI void U_EXPORT2 
01214 unum_setDoubleAttribute(    UNumberFormat*          fmt,
01215             UNumberFormatAttribute  attr,
01216             double                 newValue);
01217 
01219 typedef enum UNumberFormatTextAttribute {
01221   UNUM_POSITIVE_PREFIX,
01223   UNUM_POSITIVE_SUFFIX,
01225   UNUM_NEGATIVE_PREFIX,
01227   UNUM_NEGATIVE_SUFFIX,
01229   UNUM_PADDING_CHARACTER,
01231   UNUM_CURRENCY_CODE,
01240   UNUM_DEFAULT_RULESET,
01249   UNUM_PUBLIC_RULESETS
01250 } UNumberFormatTextAttribute;
01251 
01270 U_CAPI int32_t U_EXPORT2 
01271 unum_getTextAttribute(    const    UNumberFormat*                    fmt,
01272             UNumberFormatTextAttribute      tag,
01273             UChar*                            result,
01274             int32_t                            resultLength,
01275             UErrorCode*                        status);
01276 
01293 U_CAPI void U_EXPORT2 
01294 unum_setTextAttribute(    UNumberFormat*                    fmt,
01295             UNumberFormatTextAttribute      tag,
01296             const    UChar*                            newValue,
01297             int32_t                            newValueLength,
01298             UErrorCode                        *status);
01299 
01316 U_CAPI int32_t U_EXPORT2 
01317 unum_toPattern(    const    UNumberFormat*          fmt,
01318         UBool                  isPatternLocalized,
01319         UChar*                  result,
01320         int32_t                 resultLength,
01321         UErrorCode*             status);
01322 
01323 
01328 typedef enum UNumberFormatSymbol {
01330   UNUM_DECIMAL_SEPARATOR_SYMBOL = 0,
01332   UNUM_GROUPING_SEPARATOR_SYMBOL = 1,
01334   UNUM_PATTERN_SEPARATOR_SYMBOL = 2,
01336   UNUM_PERCENT_SYMBOL = 3,
01338   UNUM_ZERO_DIGIT_SYMBOL = 4,
01340   UNUM_DIGIT_SYMBOL = 5,
01342   UNUM_MINUS_SIGN_SYMBOL = 6,
01344   UNUM_PLUS_SIGN_SYMBOL = 7,
01346   UNUM_CURRENCY_SYMBOL = 8,
01348   UNUM_INTL_CURRENCY_SYMBOL = 9,
01350   UNUM_MONETARY_SEPARATOR_SYMBOL = 10,
01352   UNUM_EXPONENTIAL_SYMBOL = 11,
01354   UNUM_PERMILL_SYMBOL = 12,
01356   UNUM_PAD_ESCAPE_SYMBOL = 13,
01358   UNUM_INFINITY_SYMBOL = 14,
01360   UNUM_NAN_SYMBOL = 15,
01363   UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16,
01367   UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17,
01371   UNUM_ONE_DIGIT_SYMBOL = 18,
01375   UNUM_TWO_DIGIT_SYMBOL = 19,
01379   UNUM_THREE_DIGIT_SYMBOL = 20,
01383   UNUM_FOUR_DIGIT_SYMBOL = 21,
01387   UNUM_FIVE_DIGIT_SYMBOL = 22,
01391   UNUM_SIX_DIGIT_SYMBOL = 23,
01395   UNUM_SEVEN_DIGIT_SYMBOL = 24,
01399   UNUM_EIGHT_DIGIT_SYMBOL = 25,
01403   UNUM_NINE_DIGIT_SYMBOL = 26,
01404 
01408   UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27,
01409 
01410 #ifndef U_HIDE_INTERNAL_API
01411 
01414   UNUM_APPROXIMATELY_SIGN_SYMBOL = 28,
01415 #endif
01416 
01417 #ifndef U_HIDE_DEPRECATED_API
01418 
01422   UNUM_FORMAT_SYMBOL_COUNT = 29
01423 #endif  /* U_HIDE_DEPRECATED_API */
01424 } UNumberFormatSymbol;
01425 
01442 U_CAPI int32_t U_EXPORT2
01443 unum_getSymbol(const UNumberFormat *fmt,
01444                UNumberFormatSymbol symbol,
01445                UChar *buffer,
01446                int32_t size,
01447                UErrorCode *status);
01448 
01462 U_CAPI void U_EXPORT2
01463 unum_setSymbol(UNumberFormat *fmt,
01464                UNumberFormatSymbol symbol,
01465                const UChar *value,
01466                int32_t length,
01467                UErrorCode *status);
01468 
01469 
01479 U_CAPI const char* U_EXPORT2
01480 unum_getLocaleByType(const UNumberFormat *fmt,
01481                      ULocDataLocaleType type,
01482                      UErrorCode* status); 
01483 
01492 U_CAPI void U_EXPORT2
01493 unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status);
01494 
01504 U_CAPI UDisplayContext U_EXPORT2
01505 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
01506 
01507 #endif /* #if !UCONFIG_NO_FORMATTING */
01508 
01509 #endif