ICU 52.1  52.1
unum.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 * Modification History:
6 *
7 * Date Name Description
8 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
9 *******************************************************************************
10 */
11 
12 #ifndef _UNUM
13 #define _UNUM
14 
15 #include "unicode/utypes.h"
16 
17 #if !UCONFIG_NO_FORMATTING
18 
19 #include "unicode/localpointer.h"
20 #include "unicode/uloc.h"
21 #include "unicode/umisc.h"
22 #include "unicode/parseerr.h"
23 #include "unicode/uformattable.h"
24 
132 typedef void* UNumberFormat;
133 
137 typedef enum UNumberFormatStyle {
215 
220  UNUM_ROUND_CEILING,
221  UNUM_ROUND_FLOOR,
222  UNUM_ROUND_DOWN,
223  UNUM_ROUND_UP,
229 #ifndef U_HIDE_DEPRECATED_API
230 
235 #endif /* U_HIDE_DEPRECATED_API */
236  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
237  UNUM_ROUND_HALFUP,
244 
249  UNUM_PAD_BEFORE_PREFIX,
250  UNUM_PAD_AFTER_PREFIX,
251  UNUM_PAD_BEFORE_SUFFIX,
252  UNUM_PAD_AFTER_SUFFIX
254 
255 #ifndef U_HIDE_DRAFT_API
256 
260 typedef enum UNumberCompactStyle {
267 #endif /* U_HIDE_DRAFT_API */
268 
282 };
291 typedef enum UNumberFormatFields {
317 
318 
350 U_STABLE UNumberFormat* U_EXPORT2
352  const UChar* pattern,
353  int32_t patternLength,
354  const char* locale,
355  UParseError* parseErr,
356  UErrorCode* status);
357 
358 
365 U_STABLE void U_EXPORT2
367 
368 #if U_SHOW_CPLUSPLUS_API
369 
371 
382 
384 
385 #endif
386 
395 U_STABLE UNumberFormat* U_EXPORT2
396 unum_clone(const UNumberFormat *fmt,
397  UErrorCode *status);
398 
423 U_STABLE int32_t U_EXPORT2
424 unum_format( const UNumberFormat* fmt,
425  int32_t number,
426  UChar* result,
427  int32_t resultLength,
428  UFieldPosition *pos,
429  UErrorCode* status);
430 
455 U_STABLE int32_t U_EXPORT2
457  int64_t number,
458  UChar* result,
459  int32_t resultLength,
460  UFieldPosition *pos,
461  UErrorCode* status);
462 
487 U_STABLE int32_t U_EXPORT2
488 unum_formatDouble( const UNumberFormat* fmt,
489  double number,
490  UChar* result,
491  int32_t resultLength,
492  UFieldPosition *pos, /* 0 if ignore */
493  UErrorCode* status);
494 
523 U_STABLE int32_t U_EXPORT2
525  const char * number,
526  int32_t length,
527  UChar* result,
528  int32_t resultLength,
529  UFieldPosition *pos, /* 0 if ignore */
530  UErrorCode* status);
531 
556 U_STABLE int32_t U_EXPORT2
558  double number,
559  UChar* currency,
560  UChar* result,
561  int32_t resultLength,
562  UFieldPosition* pos,
563  UErrorCode* status);
564 
565 #ifndef U_HIDE_DRAFT_API
566 
586 U_DRAFT int32_t U_EXPORT2
588  const UFormattable *number,
589  UChar *result,
590  int32_t resultLength,
591  UFieldPosition *pos,
592  UErrorCode *status);
593 #endif /* U_HIDE_DRAFT_API */
594 
612 U_STABLE int32_t U_EXPORT2
613 unum_parse( const UNumberFormat* fmt,
614  const UChar* text,
615  int32_t textLength,
616  int32_t *parsePos /* 0 = start */,
617  UErrorCode *status);
618 
636 U_STABLE int64_t U_EXPORT2
637 unum_parseInt64(const UNumberFormat* fmt,
638  const UChar* text,
639  int32_t textLength,
640  int32_t *parsePos /* 0 = start */,
641  UErrorCode *status);
642 
660 U_STABLE double U_EXPORT2
661 unum_parseDouble( const UNumberFormat* fmt,
662  const UChar* text,
663  int32_t textLength,
664  int32_t *parsePos /* 0 = start */,
665  UErrorCode *status);
666 
667 
693 U_STABLE int32_t U_EXPORT2
695  const UChar* text,
696  int32_t textLength,
697  int32_t *parsePos /* 0 = start */,
698  char *outBuf,
699  int32_t outBufLength,
700  UErrorCode *status);
701 
721 U_STABLE double U_EXPORT2
723  const UChar* text,
724  int32_t textLength,
725  int32_t* parsePos, /* 0 = start */
726  UChar* currency,
727  UErrorCode* status);
728 
729 #ifndef U_HIDE_DRAFT_API
730 
748 U_DRAFT UFormattable* U_EXPORT2
750  UFormattable *result,
751  const UChar* text,
752  int32_t textLength,
753  int32_t* parsePos, /* 0 = start */
754  UErrorCode* status);
755 #endif /* U_HIDE_DRAFT_API */
756 
773 U_STABLE void U_EXPORT2
775  UBool localized,
776  const UChar *pattern,
777  int32_t patternLength,
778  UParseError *parseError,
779  UErrorCode *status
780  );
781 
792 U_STABLE const char* U_EXPORT2
793 unum_getAvailable(int32_t localeIndex);
794 
804 U_STABLE int32_t U_EXPORT2
805 unum_countAvailable(void);
806 
807 #if UCONFIG_HAVE_PARSEALLINPUT
808 
811 typedef enum UNumberFormatAttributeValue {
813  UNUM_NO = 0,
815  UNUM_YES = 1,
817  UNUM_MAYBE = 2
818 } UNumberFormatAttributeValue;
819 #endif
820 
868 #if UCONFIG_HAVE_PARSEALLINPUT
869 
873  UNUM_PARSE_ALL_INPUT = UNUM_LENIENT_PARSE + 1,
874 #endif
875 #ifndef U_HIDE_DRAFT_API
876 
886 #endif /* U_HIDE_DRAFT_API */
887 
888 #ifndef U_HIDE_INTERNAL_API
889 
892 
897 #endif /* U_HIDE_INTERNAL_API */
898 
912 
913 #ifndef U_HIDE_INTERNAL_API
914 
917 #endif /* U_HIDE_INTERNAL_API */
919 
937 U_STABLE int32_t U_EXPORT2
940 
960 U_STABLE void U_EXPORT2
963  int32_t newValue);
964 
965 
980 U_STABLE double U_EXPORT2
983 
998 U_STABLE void U_EXPORT2
1001  double newValue);
1002 
1030 
1049 U_STABLE int32_t U_EXPORT2
1052  UChar* result,
1053  int32_t resultLength,
1054  UErrorCode* status);
1055 
1072 U_STABLE void U_EXPORT2
1075  const UChar* newValue,
1076  int32_t newValueLength,
1077  UErrorCode *status);
1078 
1095 U_STABLE int32_t U_EXPORT2
1096 unum_toPattern( const UNumberFormat* fmt,
1097  UBool isPatternLocalized,
1098  UChar* result,
1099  int32_t resultLength,
1100  UErrorCode* status);
1101 
1102 
1107 typedef enum UNumberFormatSymbol {
1186 
1203 U_STABLE int32_t U_EXPORT2
1204 unum_getSymbol(const UNumberFormat *fmt,
1205  UNumberFormatSymbol symbol,
1206  UChar *buffer,
1207  int32_t size,
1208  UErrorCode *status);
1209 
1223 U_STABLE void U_EXPORT2
1225  UNumberFormatSymbol symbol,
1226  const UChar *value,
1227  int32_t length,
1228  UErrorCode *status);
1229 
1230 
1240 U_STABLE const char* U_EXPORT2
1242  ULocDataLocaleType type,
1243  UErrorCode* status);
1244 
1245 #endif /* #if !UCONFIG_NO_FORMATTING */
1246 
1247 #endif
Default format.
Definition: unum.h:208
void unum_setDoubleAttribute(UNumberFormat *fmt, UNumberFormatAttribute attr, double newValue)
Set a numeric attribute associated with a UNumberFormat.
C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing...
void unum_setSymbol(UNumberFormat *fmt, UNumberFormatSymbol symbol, const UChar *value, int32_t length, UErrorCode *status)
Set a symbol associated with a UNumberFormat.
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unum.h:219
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1131
The monetary grouping separator.
Definition: unum.h:1146
One more than the highest number format style constant.
Definition: unum.h:203
Negative prefix.
Definition: unum.h:1010
Numbering system rule-based format.
Definition: unum.h:182
Count of "regular" numeric attributes.
Definition: unum.h:891
const char * unum_getAvailable(int32_t localeIndex)
Get a locale for which decimal formatting patterns are available.
Currency format with a currency symbol, e.g., "$1.00".
Definition: unum.h:152
Decimal format ("normal" style).
Definition: unum.h:147
void unum_applyPattern(UNumberFormat *format, UBool localized, const UChar *pattern, int32_t patternLength, UParseError *parseError, UErrorCode *status)
Set the pattern used by a UNumberFormat.
if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed.
Definition: unum.h:911
Significant digit symbol.
Definition: unum.h:1142
int32_t unum_parseDecimal(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, char *outBuf, int32_t outBufLength, UErrorCode *status)
Parse a number from a string into an unformatted numeric string using a UNumberFormat.
Rule-based format defined by a pattern string.
Definition: unum.h:187
Lenient parse mode used by rule-based formats.
Definition: unum.h:867
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:273
double unum_parseDoubleCurrency(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UChar *currency, UErrorCode *status)
Parse a string into a double and a currency using a UNumberFormat.
C API:misc definitions.
ROUND_UNNECESSARY reports an error if formatted result is not exact.
Definition: unum.h:242
int32_t unum_formatInt64(const UNumberFormat *fmt, int64_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format an int64 using a UNumberFormat.
int32_t unum_format(const UNumberFormat *fmt, int32_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format an integer using a UNumberFormat.
The grouping separator.
Definition: unum.h:1111
Limit of boolean attributes.
Definition: unum.h:916
Integer digits.
Definition: unum.h:834
Fraction digits.
Definition: unum.h:840
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1107
Half-even rounding, misspelled name.
Definition: unum.h:234
Positive prefix.
Definition: unum.h:1006
The ISO currency code.
Definition: unum.h:1016
The minus sign.
Definition: unum.h:1121
Nan symbol.
Definition: unum.h:1139
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:192
int32_t unum_formatUFormattable(const UNumberFormat *fmt, const UFormattable *number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a UFormattable into a string.
int64_t unum_parseInt64(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an int64 using a UNumberFormat.
Decimal format defined by a pattern string.
Definition: unum.h:142
Use significant digits.
Definition: unum.h:857
Percent format.
Definition: unum.h:157
Half-even rounding.
Definition: unum.h:228
The position at which padding will take place.
Definition: unum.h:852
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
Spellout rule-based format.
Definition: unum.h:167
int32_t unum_getTextAttribute(const UNumberFormat *fmt, UNumberFormatTextAttribute tag, UChar *result, int32_t resultLength, UErrorCode *status)
Get a text attribute associated with a UNumberFormat.
UNumberFormatStyle
The possible number format styles.
Definition: unum.h:137
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1115
Infinity symbol.
Definition: unum.h:1137
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:308
void * UNumberFormat
A number formatter.
Definition: unum.h:132
Minimum fraction digits.
Definition: unum.h:838
A struct representing a range of text containing a specific field.
Definition: umisc.h:32
UNumberFormatFields
FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberForma...
Definition: unum.h:291
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
Maximum significant digits.
Definition: unum.h:863
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:198
count symbol constants
Definition: unum.h:1184
Parse integers only.
Definition: unum.h:824
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:885
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1004
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Maximum fraction digits.
Definition: unum.h:836
Secondary grouping size.
Definition: unum.h:854
The width to which the output of format() is padded.
Definition: unum.h:850
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:213
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:896
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:248
Per mill symbol.
Definition: unum.h:1133
The pattern separator.
Definition: unum.h:1113
Scientific format.
Definition: unum.h:162
Use grouping separator.
Definition: unum.h:826
int32_t unum_formatDouble(const UNumberFormat *fmt, double number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a double using a UNumberFormat.
If 1, specifies that if setting the "max integer digits" attribute would truncate a value...
Definition: unum.h:904
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
Positive suffix.
Definition: unum.h:1008
Multiplier.
Definition: unum.h:842
Minimum integer digits.
Definition: unum.h:832
const char * unum_getLocaleByType(const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode *status)
Get the locale for this number format object.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:260
Ordinal rule-based format.
Definition: unum.h:172
Escape padding character.
Definition: unum.h:1135
C API: Parse Error Information.
void unum_setAttribute(UNumberFormat *fmt, UNumberFormatAttribute attr, int32_t newValue)
Set a numeric attribute associated with a UNumberFormat.
The character used to pad to the format width.
Definition: unum.h:1014
UNumberFormat * unum_open(UNumberFormatStyle style, const UChar *pattern, int32_t patternLength, const char *locale, UParseError *parseErr, UErrorCode *status)
Create and return a new UNumberFormat for formatting and parsing numbers.
Rounding Mode.
Definition: unum.h:846
The decimal separator.
Definition: unum.h:1109
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:336
double unum_parseDouble(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into a double using a UNumberFormat.
int32_t unum_getSymbol(const UNumberFormat *fmt, UNumberFormatSymbol symbol, UChar *buffer, int32_t size, UErrorCode *status)
Get a symbol associated with a UNumberFormat.
Rounding increment.
Definition: unum.h:848
Minimum significant digits.
Definition: unum.h:860
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
int32_t unum_formatDoubleCurrency(const UNumberFormat *fmt, double number, UChar *currency, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a double currency amount using a UNumberFormat.
Basic definitions for ICU, for both C and C++ APIs.
UFormattable * unum_parseToUFormattable(const UNumberFormat *fmt, UFormattable *result, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a UChar string into a UFormattable.
The international currency symbol.
Definition: unum.h:1127
int32_t unum_getAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The default rule set.
Definition: unum.h:1021
The monetary separator.
Definition: unum.h:1129
int32_t unum_toPattern(const UNumberFormat *fmt, UBool isPatternLocalized, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the pattern from a UNumberFormat.
int32_t unum_formatDecimal(const UNumberFormat *fmt, const char *number, int32_t length, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a decimal number using a UNumberFormat.
The currency symbol.
Definition: unum.h:1125
The plus sign.
Definition: unum.h:1123
Duration rule-based format.
Definition: unum.h:177
#define U_DRAFT
This is used to declare a function as a draft public ICU C API.
Definition: umachine.h:111
void * UFormattable
Opaque type representing various types of data which may be used for formatting and parsing operation...
Definition: uformattable.h:64
UNumberFormatAttribute
The possible UNumberFormat numeric attributes.
Definition: unum.h:822
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1012
Grouping size.
Definition: unum.h:844
int32_t unum_parse(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an integer using a UNumberFormat.
The public rule sets.
Definition: unum.h:1028
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
Maximum integer digits.
Definition: unum.h:830
Character representing a digit in the pattern.
Definition: unum.h:1119
C API: Locale.
Always show decimal point.
Definition: unum.h:828
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.