X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/i18n/unicode/unum.h diff --git a/icuSources/i18n/unicode/unum.h b/icuSources/i18n/unicode/unum.h index c5df2bbf..3f9f291a 100644 --- a/icuSources/i18n/unicode/unum.h +++ b/icuSources/i18n/unicode/unum.h @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2008, International Business Machines Corporation and others. +* Copyright (C) 1997-2012, International Business Machines Corporation and others. * All Rights Reserved. * Modification History: * @@ -16,6 +16,7 @@ #if !UCONFIG_NO_FORMATTING +#include "unicode/localpointer.h" #include "unicode/uloc.h" #include "unicode/umisc.h" #include "unicode/parseerr.h" @@ -133,19 +134,34 @@ typedef void* UNumberFormat; */ typedef enum UNumberFormatStyle { /** - * Decimal format defined by pattern + * Decimal format defined by a pattern string. * @stable ICU 3.0 */ UNUM_PATTERN_DECIMAL=0, - /** Decimal format */ + /** + * Decimal format ("normal" style). + * @stable ICU 2.0 + */ UNUM_DECIMAL=1, - /** Currency format */ + /** + * Currency format with a currency symbol, e.g., "$1.00". + * @stable ICU 2.0 + */ UNUM_CURRENCY, - /** Percent format */ + /** + * Percent format + * @stable ICU 2.0 + */ UNUM_PERCENT, - /** Scientific format */ + /** + * Scientific format + * @stable ICU 2.1 + */ UNUM_SCIENTIFIC, - /** Spellout rule-based format */ + /** + * Spellout rule-based format + * @stable ICU 2.0 + */ UNUM_SPELLOUT, /** * Ordinal rule-based format @@ -158,13 +174,40 @@ typedef enum UNumberFormatStyle { */ UNUM_DURATION, /** - * Rule-based format defined by pattern + * Numbering system rule-based format + * @stable ICU 4.2 + */ + UNUM_NUMBERING_SYSTEM, + /** + * Rule-based format defined by a pattern string. * @stable ICU 3.0 */ UNUM_PATTERN_RULEBASED, - /** Default format */ + /** + * Currency format with an ISO currency code, e.g., "USD1.00". + * @stable ICU 4.8 + */ + UNUM_CURRENCY_ISO, + /** + * Currency format with a pluralized currency name, + * e.g., "1.00 US dollar" and "3.00 US dollars". + * @stable ICU 4.8 + */ + UNUM_CURRENCY_PLURAL, + /** + * One more than the highest number format style constant. + * @stable ICU 4.8 + */ + UNUM_FORMAT_STYLE_COUNT, + /** + * Default format + * @stable ICU 2.0 + */ UNUM_DEFAULT = UNUM_DECIMAL, - /** (Alias for UNUM_PATTERN_DECIMAL) */ + /** + * Alias for UNUM_PATTERN_DECIMAL + * @stable ICU 3.0 + */ UNUM_IGNORE = UNUM_PATTERN_DECIMAL } UNumberFormatStyle; @@ -176,18 +219,25 @@ typedef enum UNumberFormatRoundingMode { UNUM_ROUND_FLOOR, UNUM_ROUND_DOWN, UNUM_ROUND_UP, + /** + * Half-even rounding + * @stable, ICU 3.8 + */ + UNUM_ROUND_HALFEVEN, +#ifndef U_HIDE_DEPRECATED_API /** * Half-even rounding, misspelled name * @deprecated, ICU 3.8 */ - UNUM_FOUND_HALFEVEN, + UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN, +#endif /* U_HIDE_DEPRECATED_API */ UNUM_ROUND_HALFDOWN, UNUM_ROUND_HALFUP, - /** - * Half-even rounding - * @stable, ICU 3.8 - */ - UNUM_ROUND_HALFEVEN = UNUM_FOUND_HALFEVEN + /** + * ROUND_UNNECESSARY reports an error if formatted result is not exact. + * @stable ICU 4.8 + */ + UNUM_ROUND_UNNECESSARY } UNumberFormatRoundingMode; /** The possible number format pad positions. @@ -200,6 +250,56 @@ typedef enum UNumberFormatPadPosition { UNUM_PAD_AFTER_SUFFIX } UNumberFormatPadPosition; +/** + * Constants for specifying currency spacing + * @stable ICU 4.8 + */ +enum UCurrencySpacing { + /** @stable ICU 4.8 */ + UNUM_CURRENCY_MATCH, + /** @stable ICU 4.8 */ + UNUM_CURRENCY_SURROUNDING_MATCH, + /** @stable ICU 4.8 */ + UNUM_CURRENCY_INSERT, + /** @stable ICU 4.8 */ + UNUM_CURRENCY_SPACING_COUNT +}; +typedef enum UCurrencySpacing UCurrencySpacing; /**< @stable ICU 4.8 */ + + +/** + * FieldPosition and UFieldPosition selectors for format fields + * defined by NumberFormat and UNumberFormat. + * @stable ICU 49 + */ +typedef enum UNumberFormatFields { + /** @stable ICU 49 */ + UNUM_INTEGER_FIELD, + /** @stable ICU 49 */ + UNUM_FRACTION_FIELD, + /** @stable ICU 49 */ + UNUM_DECIMAL_SEPARATOR_FIELD, + /** @stable ICU 49 */ + UNUM_EXPONENT_SYMBOL_FIELD, + /** @stable ICU 49 */ + UNUM_EXPONENT_SIGN_FIELD, + /** @stable ICU 49 */ + UNUM_EXPONENT_FIELD, + /** @stable ICU 49 */ + UNUM_GROUPING_SEPARATOR_FIELD, + /** @stable ICU 49 */ + UNUM_CURRENCY_FIELD, + /** @stable ICU 49 */ + UNUM_PERCENT_FIELD, + /** @stable ICU 49 */ + UNUM_PERMILL_FIELD, + /** @stable ICU 49 */ + UNUM_SIGN_FIELD, + /** @stable ICU 49 */ + UNUM_FIELD_COUNT +} UNumberFormatFields; + + /** * Create and return a new UNumberFormat for formatting and parsing * numbers. A UNumberFormat may be used to format numbers by calling @@ -249,6 +349,25 @@ unum_open( UNumberFormatStyle style, U_STABLE void U_EXPORT2 unum_close(UNumberFormat* fmt); +#if U_SHOW_CPLUSPLUS_API + +U_NAMESPACE_BEGIN + +/** + * \class LocalUNumberFormatPointer + * "Smart pointer" class, closes a UNumberFormat via unum_close(). + * For most methods see the LocalPointerBase base class. + * + * @see LocalPointerBase + * @see LocalPointer + * @stable ICU 4.4 + */ +U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close); + +U_NAMESPACE_END + +#endif + /** * Open a copy of a UNumberFormat. * This function performs a deep copy. @@ -348,6 +467,40 @@ unum_formatDouble( const UNumberFormat* fmt, UFieldPosition *pos, /* 0 if ignore */ UErrorCode* status); +/** +* Format a decimal number using a UNumberFormat. +* The number will be formatted according to the UNumberFormat's locale. +* The syntax of the input number is a "numeric string" +* as defined in the Decimal Arithmetic Specification, available at +* http://speleotrove.com/decimal +* @param fmt The formatter to use. +* @param number The number to format. +* @param length The length of the input number, or -1 if the input is nul-terminated. +* @param result A pointer to a buffer to receive the formatted number. +* @param resultLength The maximum size of result. +* @param pos A pointer to a UFieldPosition. On input, position->field +* is read. On output, position->beginIndex and position->endIndex indicate +* the beginning and ending indices of field number position->field, if such +* a field exists. This parameter may be NULL, in which case it is ignored. +* @param status A pointer to an UErrorCode to receive any errors +* @return The total buffer size needed; if greater than resultLength, the output was truncated. +* @see unum_format +* @see unum_formatInt64 +* @see unum_parse +* @see unum_parseInt64 +* @see unum_parseDouble +* @see UFieldPosition +* @stable ICU 4.4 +*/ +U_STABLE int32_t U_EXPORT2 +unum_formatDecimal( const UNumberFormat* fmt, + const char * number, + int32_t length, + UChar* result, + int32_t resultLength, + UFieldPosition *pos, /* 0 if ignore */ + UErrorCode* status); + /** * Format a double currency amount using a UNumberFormat. * The double will be formatted according to the UNumberFormat's locale. @@ -450,6 +603,41 @@ unum_parseDouble( const UNumberFormat* fmt, int32_t *parsePos /* 0 = start */, UErrorCode *status); + +/** +* Parse a number from a string into an unformatted numeric string using a UNumberFormat. +* The input string will be parsed according to the UNumberFormat's locale. +* The syntax of the output is a "numeric string" +* as defined in the Decimal Arithmetic Specification, available at +* http://speleotrove.com/decimal +* @param fmt The formatter to use. +* @param text The text to parse. +* @param textLength The length of text, or -1 if null-terminated. +* @param parsePos If not 0, on input a pointer to an integer specifying the offset at which +* to begin parsing. If not 0, on output the offset at which parsing ended. +* @param outBuf A (char *) buffer to receive the parsed number as a string. The output string +* will be nul-terminated if there is sufficient space. +* @param outBufLength The size of the output buffer. May be zero, in which case +* the outBuf pointer may be NULL, and the function will return the +* size of the output string. +* @param status A pointer to an UErrorCode to receive any errors +* @return the length of the output string, not including any terminating nul. +* @see unum_parse +* @see unum_parseInt64 +* @see unum_format +* @see unum_formatInt64 +* @see unum_formatDouble +* @stable ICU 4.4 +*/ +U_STABLE int32_t U_EXPORT2 +unum_parseDecimal(const UNumberFormat* fmt, + const UChar* text, + int32_t textLength, + int32_t *parsePos /* 0 = start */, + char *outBuf, + int32_t outBufLength, + UErrorCode *status); + /** * Parse a string into a double and a currency using a UNumberFormat. * The string will be parsed according to the UNumberFormat's locale. @@ -507,13 +695,13 @@ unum_applyPattern( UNumberFormat *format, * A UNumberFormat in a locale returned by this function will perform the correct * formatting and parsing for the locale. The results of this call are not * valid for rule-based number formats. -* @param index The index of the desired locale. +* @param localeIndex The index of the desired locale. * @return A locale for which number formatting patterns are available, or 0 if none. * @see unum_countAvailable * @stable ICU 2.0 */ U_STABLE const char* U_EXPORT2 -unum_getAvailable(int32_t index); +unum_getAvailable(int32_t localeIndex); /** * Determine how many locales have decimal formatting patterns available. The @@ -801,9 +989,45 @@ typedef enum UNumberFormatSymbol { /** The monetary grouping separator * @stable ICU 3.6 */ - UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, + UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, + /** One + * @stable ICU 4.6 + */ + UNUM_ONE_DIGIT_SYMBOL = 18, + /** Two + * @stable ICU 4.6 + */ + UNUM_TWO_DIGIT_SYMBOL = 19, + /** Three + * @stable ICU 4.6 + */ + UNUM_THREE_DIGIT_SYMBOL = 20, + /** Four + * @stable ICU 4.6 + */ + UNUM_FOUR_DIGIT_SYMBOL = 21, + /** Five + * @stable ICU 4.6 + */ + UNUM_FIVE_DIGIT_SYMBOL = 22, + /** Six + * @stable ICU 4.6 + */ + UNUM_SIX_DIGIT_SYMBOL = 23, + /** Seven + * @stable ICU 4.6 + */ + UNUM_SEVEN_DIGIT_SYMBOL = 24, + /** Eight + * @stable ICU 4.6 + */ + UNUM_EIGHT_DIGIT_SYMBOL = 25, + /** Nine + * @stable ICU 4.6 + */ + UNUM_NINE_DIGIT_SYMBOL = 26, /** count symbol constants */ - UNUM_FORMAT_SYMBOL_COUNT = 18 + UNUM_FORMAT_SYMBOL_COUNT = 27 } UNumberFormatSymbol; /**