ICU 49.1.2  49.1.2
unum.h
Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 * Copyright (C) 1997-2012, International Business Machines Corporation and others.
00004 * All Rights Reserved.
00005 * Modification History:
00006 *
00007 *   Date        Name        Description
00008 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
00009 *******************************************************************************
00010 */
00011 
00012 #ifndef _UNUM
00013 #define _UNUM
00014 
00015 #include "unicode/utypes.h"
00016 
00017 #if !UCONFIG_NO_FORMATTING
00018 
00019 #include "unicode/localpointer.h"
00020 #include "unicode/uloc.h"
00021 #include "unicode/umisc.h"
00022 #include "unicode/parseerr.h"
00130 typedef void* UNumberFormat;
00131 
00135 typedef enum UNumberFormatStyle {
00140     UNUM_PATTERN_DECIMAL=0,
00145     UNUM_DECIMAL=1,
00150     UNUM_CURRENCY,
00155     UNUM_PERCENT,
00160     UNUM_SCIENTIFIC,
00165     UNUM_SPELLOUT,
00170     UNUM_ORDINAL,
00175     UNUM_DURATION,
00180     UNUM_NUMBERING_SYSTEM,
00185     UNUM_PATTERN_RULEBASED,
00190     UNUM_CURRENCY_ISO,
00196     UNUM_CURRENCY_PLURAL,
00201     UNUM_FORMAT_STYLE_COUNT,
00206     UNUM_DEFAULT = UNUM_DECIMAL,
00211     UNUM_IGNORE = UNUM_PATTERN_DECIMAL
00212 } UNumberFormatStyle;
00213 
00217 typedef enum UNumberFormatRoundingMode {
00218     UNUM_ROUND_CEILING,
00219     UNUM_ROUND_FLOOR,
00220     UNUM_ROUND_DOWN,
00221     UNUM_ROUND_UP,
00226     UNUM_ROUND_HALFEVEN,
00227 #ifndef U_HIDE_DEPRECATED_API
00228 
00232     UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN,
00233 #endif  /* U_HIDE_DEPRECATED_API */
00234     UNUM_ROUND_HALFDOWN,
00235     UNUM_ROUND_HALFUP,
00240     UNUM_ROUND_UNNECESSARY
00241 } UNumberFormatRoundingMode;
00242 
00246 typedef enum UNumberFormatPadPosition {
00247     UNUM_PAD_BEFORE_PREFIX,
00248     UNUM_PAD_AFTER_PREFIX,
00249     UNUM_PAD_BEFORE_SUFFIX,
00250     UNUM_PAD_AFTER_SUFFIX
00251 } UNumberFormatPadPosition;
00252 
00257 enum UCurrencySpacing {
00259     UNUM_CURRENCY_MATCH,
00261     UNUM_CURRENCY_SURROUNDING_MATCH,
00263     UNUM_CURRENCY_INSERT,
00265     UNUM_CURRENCY_SPACING_COUNT
00266 };
00267 typedef enum UCurrencySpacing UCurrencySpacing; 
00275 typedef enum UNumberFormatFields {
00277     UNUM_INTEGER_FIELD,
00279     UNUM_FRACTION_FIELD,
00281     UNUM_DECIMAL_SEPARATOR_FIELD,
00283     UNUM_EXPONENT_SYMBOL_FIELD,
00285     UNUM_EXPONENT_SIGN_FIELD,
00287     UNUM_EXPONENT_FIELD,
00289     UNUM_GROUPING_SEPARATOR_FIELD,
00291     UNUM_CURRENCY_FIELD,
00293     UNUM_PERCENT_FIELD,
00295     UNUM_PERMILL_FIELD,
00297     UNUM_SIGN_FIELD,
00299     UNUM_FIELD_COUNT
00300 } UNumberFormatFields;
00301 
00302 
00334 U_STABLE UNumberFormat* U_EXPORT2 
00335 unum_open(  UNumberFormatStyle    style,
00336             const    UChar*    pattern,
00337             int32_t            patternLength,
00338             const    char*     locale,
00339             UParseError*       parseErr,
00340             UErrorCode*        status);
00341 
00342 
00349 U_STABLE void U_EXPORT2 
00350 unum_close(UNumberFormat* fmt);
00351 
00352 #if U_SHOW_CPLUSPLUS_API
00353 
00354 U_NAMESPACE_BEGIN
00355 
00365 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
00366 
00367 U_NAMESPACE_END
00368 
00369 #endif
00370 
00379 U_STABLE UNumberFormat* U_EXPORT2 
00380 unum_clone(const UNumberFormat *fmt,
00381        UErrorCode *status);
00382 
00404 U_STABLE int32_t U_EXPORT2 
00405 unum_format(    const    UNumberFormat*    fmt,
00406         int32_t            number,
00407         UChar*            result,
00408         int32_t            resultLength,
00409         UFieldPosition    *pos,
00410         UErrorCode*        status);
00411 
00433 U_STABLE int32_t U_EXPORT2 
00434 unum_formatInt64(const UNumberFormat *fmt,
00435         int64_t         number,
00436         UChar*          result,
00437         int32_t         resultLength,
00438         UFieldPosition *pos,
00439         UErrorCode*     status);
00440 
00462 U_STABLE int32_t U_EXPORT2 
00463 unum_formatDouble(    const    UNumberFormat*  fmt,
00464             double          number,
00465             UChar*          result,
00466             int32_t         resultLength,
00467             UFieldPosition  *pos, /* 0 if ignore */
00468             UErrorCode*     status);
00469 
00495 U_STABLE int32_t U_EXPORT2 
00496 unum_formatDecimal(    const    UNumberFormat*  fmt,
00497             const char *    number,
00498             int32_t         length,
00499             UChar*          result,
00500             int32_t         resultLength,
00501             UFieldPosition  *pos, /* 0 if ignore */
00502             UErrorCode*     status);
00503 
00525 U_STABLE int32_t U_EXPORT2 
00526 unum_formatDoubleCurrency(const UNumberFormat* fmt,
00527                           double number,
00528                           UChar* currency,
00529                           UChar* result,
00530                           int32_t resultLength,
00531                           UFieldPosition* pos, /* ignored if 0 */
00532                           UErrorCode* status);
00533 
00551 U_STABLE int32_t U_EXPORT2 
00552 unum_parse(    const   UNumberFormat*  fmt,
00553         const   UChar*          text,
00554         int32_t         textLength,
00555         int32_t         *parsePos /* 0 = start */,
00556         UErrorCode      *status);
00557 
00575 U_STABLE int64_t U_EXPORT2 
00576 unum_parseInt64(const UNumberFormat*  fmt,
00577         const UChar*  text,
00578         int32_t       textLength,
00579         int32_t       *parsePos /* 0 = start */,
00580         UErrorCode    *status);
00581 
00599 U_STABLE double U_EXPORT2 
00600 unum_parseDouble(    const   UNumberFormat*  fmt,
00601             const   UChar*          text,
00602             int32_t         textLength,
00603             int32_t         *parsePos /* 0 = start */,
00604             UErrorCode      *status);
00605 
00606 
00632 U_STABLE int32_t U_EXPORT2 
00633 unum_parseDecimal(const   UNumberFormat*  fmt,
00634                  const   UChar*          text,
00635                          int32_t         textLength,
00636                          int32_t         *parsePos /* 0 = start */,
00637                          char            *outBuf,
00638                          int32_t         outBufLength,
00639                          UErrorCode      *status);
00640 
00660 U_STABLE double U_EXPORT2
00661 unum_parseDoubleCurrency(const UNumberFormat* fmt,
00662                          const UChar* text,
00663                          int32_t textLength,
00664                          int32_t* parsePos, /* 0 = start */
00665                          UChar* currency,
00666                          UErrorCode* status);
00667 
00684 U_STABLE void U_EXPORT2 
00685 unum_applyPattern(          UNumberFormat  *format,
00686                             UBool          localized,
00687                     const   UChar          *pattern,
00688                             int32_t         patternLength,
00689                             UParseError    *parseError,
00690                             UErrorCode     *status
00691                                     );
00692 
00703 U_STABLE const char* U_EXPORT2 
00704 unum_getAvailable(int32_t localeIndex);
00705 
00715 U_STABLE int32_t U_EXPORT2 
00716 unum_countAvailable(void);
00717 
00718 #if UCONFIG_HAVE_PARSEALLINPUT
00719 
00722 typedef enum UNumberFormatAttributeValue {
00724   UNUM_NO = 0,
00726   UNUM_YES = 1,
00728   UNUM_MAYBE = 2
00729 } UNumberFormatAttributeValue;
00730 #endif
00731 
00733 typedef enum UNumberFormatAttribute {
00735   UNUM_PARSE_INT_ONLY,
00737   UNUM_GROUPING_USED,
00739   UNUM_DECIMAL_ALWAYS_SHOWN,
00741   UNUM_MAX_INTEGER_DIGITS,
00743   UNUM_MIN_INTEGER_DIGITS,
00745   UNUM_INTEGER_DIGITS,
00747   UNUM_MAX_FRACTION_DIGITS,
00749   UNUM_MIN_FRACTION_DIGITS,
00751   UNUM_FRACTION_DIGITS,
00753   UNUM_MULTIPLIER,
00755   UNUM_GROUPING_SIZE,
00757   UNUM_ROUNDING_MODE,
00759   UNUM_ROUNDING_INCREMENT,
00761   UNUM_FORMAT_WIDTH,
00763   UNUM_PADDING_POSITION,
00765   UNUM_SECONDARY_GROUPING_SIZE,
00768   UNUM_SIGNIFICANT_DIGITS_USED,
00771   UNUM_MIN_SIGNIFICANT_DIGITS,
00774   UNUM_MAX_SIGNIFICANT_DIGITS,
00778   UNUM_LENIENT_PARSE
00779 
00780 #if UCONFIG_HAVE_PARSEALLINPUT
00781 
00784   ,UNUM_PARSE_ALL_INPUT
00785 #endif
00786   
00787 } UNumberFormatAttribute;
00788 
00805 U_STABLE int32_t U_EXPORT2 
00806 unum_getAttribute(const UNumberFormat*          fmt,
00807           UNumberFormatAttribute  attr);
00808 
00828 U_STABLE void U_EXPORT2 
00829 unum_setAttribute(    UNumberFormat*          fmt,
00830             UNumberFormatAttribute  attr,
00831             int32_t                 newValue);
00832 
00833 
00848 U_STABLE double U_EXPORT2 
00849 unum_getDoubleAttribute(const UNumberFormat*          fmt,
00850           UNumberFormatAttribute  attr);
00851 
00866 U_STABLE void U_EXPORT2 
00867 unum_setDoubleAttribute(    UNumberFormat*          fmt,
00868             UNumberFormatAttribute  attr,
00869             double                 newValue);
00870 
00872 typedef enum UNumberFormatTextAttribute {
00874   UNUM_POSITIVE_PREFIX,
00876   UNUM_POSITIVE_SUFFIX,
00878   UNUM_NEGATIVE_PREFIX,
00880   UNUM_NEGATIVE_SUFFIX,
00882   UNUM_PADDING_CHARACTER,
00884   UNUM_CURRENCY_CODE,
00889   UNUM_DEFAULT_RULESET,
00896   UNUM_PUBLIC_RULESETS
00897 } UNumberFormatTextAttribute;
00898 
00917 U_STABLE int32_t U_EXPORT2 
00918 unum_getTextAttribute(    const    UNumberFormat*                    fmt,
00919             UNumberFormatTextAttribute      tag,
00920             UChar*                            result,
00921             int32_t                            resultLength,
00922             UErrorCode*                        status);
00923 
00940 U_STABLE void U_EXPORT2 
00941 unum_setTextAttribute(    UNumberFormat*                    fmt,
00942             UNumberFormatTextAttribute      tag,
00943             const    UChar*                            newValue,
00944             int32_t                            newValueLength,
00945             UErrorCode                        *status);
00946 
00963 U_STABLE int32_t U_EXPORT2 
00964 unum_toPattern(    const    UNumberFormat*          fmt,
00965         UBool                  isPatternLocalized,
00966         UChar*                  result,
00967         int32_t                 resultLength,
00968         UErrorCode*             status);
00969 
00970 
00975 typedef enum UNumberFormatSymbol {
00977   UNUM_DECIMAL_SEPARATOR_SYMBOL = 0,
00979   UNUM_GROUPING_SEPARATOR_SYMBOL = 1,
00981   UNUM_PATTERN_SEPARATOR_SYMBOL = 2,
00983   UNUM_PERCENT_SYMBOL = 3,
00985   UNUM_ZERO_DIGIT_SYMBOL = 4,
00987   UNUM_DIGIT_SYMBOL = 5,
00989   UNUM_MINUS_SIGN_SYMBOL = 6,
00991   UNUM_PLUS_SIGN_SYMBOL = 7,
00993   UNUM_CURRENCY_SYMBOL = 8,
00995   UNUM_INTL_CURRENCY_SYMBOL = 9,
00997   UNUM_MONETARY_SEPARATOR_SYMBOL = 10,
00999   UNUM_EXPONENTIAL_SYMBOL = 11,
01001   UNUM_PERMILL_SYMBOL = 12,
01003   UNUM_PAD_ESCAPE_SYMBOL = 13,
01005   UNUM_INFINITY_SYMBOL = 14,
01007   UNUM_NAN_SYMBOL = 15,
01010   UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16,
01014   UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17,
01018   UNUM_ONE_DIGIT_SYMBOL = 18,
01022   UNUM_TWO_DIGIT_SYMBOL = 19,
01026   UNUM_THREE_DIGIT_SYMBOL = 20,
01030   UNUM_FOUR_DIGIT_SYMBOL = 21,
01034   UNUM_FIVE_DIGIT_SYMBOL = 22,
01038   UNUM_SIX_DIGIT_SYMBOL = 23,
01042   UNUM_SEVEN_DIGIT_SYMBOL = 24,
01046   UNUM_EIGHT_DIGIT_SYMBOL = 25,
01050   UNUM_NINE_DIGIT_SYMBOL = 26,
01052   UNUM_FORMAT_SYMBOL_COUNT = 27
01053 } UNumberFormatSymbol;
01054 
01071 U_STABLE int32_t U_EXPORT2
01072 unum_getSymbol(const UNumberFormat *fmt,
01073                UNumberFormatSymbol symbol,
01074                UChar *buffer,
01075                int32_t size,
01076                UErrorCode *status);
01077 
01091 U_STABLE void U_EXPORT2
01092 unum_setSymbol(UNumberFormat *fmt,
01093                UNumberFormatSymbol symbol,
01094                const UChar *value,
01095                int32_t length,
01096                UErrorCode *status);
01097 
01098 
01108 U_STABLE const char* U_EXPORT2
01109 unum_getLocaleByType(const UNumberFormat *fmt,
01110                      ULocDataLocaleType type,
01111                      UErrorCode* status); 
01112 
01113 #endif /* #if !UCONFIG_NO_FORMATTING */
01114 
01115 #endif