ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unum.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2014, 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"
25 
133 typedef void* UNumberFormat;
134 
138 typedef enum UNumberFormatStyle {
200 #ifndef U_HIDE_DRAFT_API
201 
207 #endif /* U_HIDE_DRAFT_API */
208 
224 
229  UNUM_ROUND_CEILING,
230  UNUM_ROUND_FLOOR,
231  UNUM_ROUND_DOWN,
232  UNUM_ROUND_UP,
238 #ifndef U_HIDE_DEPRECATED_API
239 
244 #endif /* U_HIDE_DEPRECATED_API */
245  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
246  UNUM_ROUND_HALFUP,
253 
258  UNUM_PAD_BEFORE_PREFIX,
259  UNUM_PAD_AFTER_PREFIX,
260  UNUM_PAD_BEFORE_SUFFIX,
261  UNUM_PAD_AFTER_SUFFIX
263 
268 typedef enum UNumberCompactStyle {
275 
289 };
298 typedef enum UNumberFormatFields {
324 
325 
359 U_STABLE UNumberFormat* U_EXPORT2
361  const UChar* pattern,
362  int32_t patternLength,
363  const char* locale,
364  UParseError* parseErr,
365  UErrorCode* status);
366 
367 
374 U_STABLE void U_EXPORT2
376 
377 #if U_SHOW_CPLUSPLUS_API
378 
380 
391 
393 
394 #endif
395 
404 U_STABLE UNumberFormat* U_EXPORT2
405 unum_clone(const UNumberFormat *fmt,
406  UErrorCode *status);
407 
432 U_STABLE int32_t U_EXPORT2
433 unum_format( const UNumberFormat* fmt,
434  int32_t number,
435  UChar* result,
436  int32_t resultLength,
437  UFieldPosition *pos,
438  UErrorCode* status);
439 
464 U_STABLE int32_t U_EXPORT2
466  int64_t number,
467  UChar* result,
468  int32_t resultLength,
469  UFieldPosition *pos,
470  UErrorCode* status);
471 
496 U_STABLE int32_t U_EXPORT2
497 unum_formatDouble( const UNumberFormat* fmt,
498  double number,
499  UChar* result,
500  int32_t resultLength,
501  UFieldPosition *pos, /* 0 if ignore */
502  UErrorCode* status);
503 
532 U_STABLE int32_t U_EXPORT2
534  const char * number,
535  int32_t length,
536  UChar* result,
537  int32_t resultLength,
538  UFieldPosition *pos, /* 0 if ignore */
539  UErrorCode* status);
540 
565 U_STABLE int32_t U_EXPORT2
567  double number,
568  UChar* currency,
569  UChar* result,
570  int32_t resultLength,
571  UFieldPosition* pos,
572  UErrorCode* status);
573 
574 #ifndef U_HIDE_DRAFT_API
575 
595 U_DRAFT int32_t U_EXPORT2
597  const UFormattable *number,
598  UChar *result,
599  int32_t resultLength,
600  UFieldPosition *pos,
601  UErrorCode *status);
602 #endif /* U_HIDE_DRAFT_API */
603 
621 U_STABLE int32_t U_EXPORT2
622 unum_parse( const UNumberFormat* fmt,
623  const UChar* text,
624  int32_t textLength,
625  int32_t *parsePos /* 0 = start */,
626  UErrorCode *status);
627 
645 U_STABLE int64_t U_EXPORT2
646 unum_parseInt64(const UNumberFormat* fmt,
647  const UChar* text,
648  int32_t textLength,
649  int32_t *parsePos /* 0 = start */,
650  UErrorCode *status);
651 
669 U_STABLE double U_EXPORT2
670 unum_parseDouble( const UNumberFormat* fmt,
671  const UChar* text,
672  int32_t textLength,
673  int32_t *parsePos /* 0 = start */,
674  UErrorCode *status);
675 
676 
702 U_STABLE int32_t U_EXPORT2
704  const UChar* text,
705  int32_t textLength,
706  int32_t *parsePos /* 0 = start */,
707  char *outBuf,
708  int32_t outBufLength,
709  UErrorCode *status);
710 
730 U_STABLE double U_EXPORT2
732  const UChar* text,
733  int32_t textLength,
734  int32_t* parsePos, /* 0 = start */
735  UChar* currency,
736  UErrorCode* status);
737 
738 #ifndef U_HIDE_DRAFT_API
739 
757 U_DRAFT UFormattable* U_EXPORT2
759  UFormattable *result,
760  const UChar* text,
761  int32_t textLength,
762  int32_t* parsePos, /* 0 = start */
763  UErrorCode* status);
764 #endif /* U_HIDE_DRAFT_API */
765 
782 U_STABLE void U_EXPORT2
784  UBool localized,
785  const UChar *pattern,
786  int32_t patternLength,
787  UParseError *parseError,
788  UErrorCode *status
789  );
790 
801 U_STABLE const char* U_EXPORT2
802 unum_getAvailable(int32_t localeIndex);
803 
813 U_STABLE int32_t U_EXPORT2
814 unum_countAvailable(void);
815 
816 #if UCONFIG_HAVE_PARSEALLINPUT
817 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
821 typedef enum UNumberFormatAttributeValue {
822 #ifndef U_HIDE_INTERNAL_API
823 
824  UNUM_NO = 0,
826  UNUM_YES = 1,
828  UNUM_MAYBE = 2
829 #endif /* U_HIDE_INTERNAL_API */
830 } UNumberFormatAttributeValue;
831 #endif
832 
880 #if UCONFIG_HAVE_PARSEALLINPUT
881 
885  UNUM_PARSE_ALL_INPUT = UNUM_LENIENT_PARSE + 1,
886 #endif
887 
897 
898 #ifndef U_HIDE_INTERNAL_API
899 
902 #endif /* U_HIDE_INTERNAL_API */
903 
904  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
909 
923 
924  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
929 
947 U_STABLE int32_t U_EXPORT2
950 
970 U_STABLE void U_EXPORT2
973  int32_t newValue);
974 
975 
990 U_STABLE double U_EXPORT2
993 
1008 U_STABLE void U_EXPORT2
1011  double newValue);
1012 
1040 
1059 U_STABLE int32_t U_EXPORT2
1062  UChar* result,
1063  int32_t resultLength,
1064  UErrorCode* status);
1065 
1082 U_STABLE void U_EXPORT2
1085  const UChar* newValue,
1086  int32_t newValueLength,
1087  UErrorCode *status);
1088 
1105 U_STABLE int32_t U_EXPORT2
1106 unum_toPattern( const UNumberFormat* fmt,
1107  UBool isPatternLocalized,
1108  UChar* result,
1109  int32_t resultLength,
1110  UErrorCode* status);
1111 
1112 
1117 typedef enum UNumberFormatSymbol {
1196 
1213 U_STABLE int32_t U_EXPORT2
1214 unum_getSymbol(const UNumberFormat *fmt,
1215  UNumberFormatSymbol symbol,
1216  UChar *buffer,
1217  int32_t size,
1218  UErrorCode *status);
1219 
1233 U_STABLE void U_EXPORT2
1235  UNumberFormatSymbol symbol,
1236  const UChar *value,
1237  int32_t length,
1238  UErrorCode *status);
1239 
1240 
1250 U_STABLE const char* U_EXPORT2
1252  ULocDataLocaleType type,
1253  UErrorCode* status);
1254 
1255 #ifndef U_HIDE_DRAFT_API
1256 
1264 U_DRAFT void U_EXPORT2
1266 
1276 U_DRAFT UDisplayContext U_EXPORT2
1277 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1278 
1279 #endif /* U_HIDE_DRAFT_API */
1280 
1281 #endif /* #if !UCONFIG_NO_FORMATTING */
1282 
1283 #endif
Default format.
Definition: unum.h:217
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:228
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1141
The monetary grouping separator.
Definition: unum.h:1156
One more than the highest number format style constant.
Definition: unum.h:212
Negative prefix.
Definition: unum.h:1020
void unum_setContext(UNumberFormat *fmt, UDisplayContext value, UErrorCode *status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
Numbering system rule-based format.
Definition: unum.h:183
Count of "regular" numeric attributes.
Definition: unum.h:901
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:153
Decimal format ("normal" style).
Definition: unum.h:148
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:922
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1152
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:188
Lenient parse mode used by rule-based formats.
Definition: unum.h:879
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:280
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:251
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:1121
Limit of boolean attributes.
Definition: unum.h:927
Integer digits.
Definition: unum.h:846
Fraction digits.
Definition: unum.h:852
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1117
Half-even rounding, misspelled name.
Definition: unum.h:243
Positive prefix.
Definition: unum.h:1016
The ISO currency code.
Definition: unum.h:1026
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1131
Nan symbol.
Definition: unum.h:1149
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:193
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:143
Use significant digits.
Definition: unum.h:869
Percent format.
Definition: unum.h:158
Half-even rounding.
Definition: unum.h:237
The position at which padding will take place.
Definition: unum.h:864
#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:168
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:138
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1125
Infinity symbol.
Definition: unum.h:1147
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:290
void * UNumberFormat
A number formatter.
Definition: unum.h:133
Minimum fraction digits.
Definition: unum.h:850
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:298
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
Maximum significant digits.
Definition: unum.h:875
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:199
count symbol constants
Definition: unum.h:1194
Parse integers only.
Definition: unum.h:836
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:896
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1014
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Maximum fraction digits.
Definition: unum.h:848
Secondary grouping size.
Definition: unum.h:866
The width to which the output of format() is padded.
Definition: unum.h:862
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:222
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:908
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:257
Per mill symbol.
Definition: unum.h:1143
The pattern separator.
Definition: unum.h:1123
UDisplayContext unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode *status)
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
Scientific format.
Definition: unum.h:163
Use grouping separator.
Definition: unum.h:838
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:915
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:1018
Multiplier.
Definition: unum.h:854
Minimum integer digits.
Definition: unum.h:844
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:268
UDisplayContextType
Display context types, for getting values of a particular setting.
Ordinal rule-based format.
Definition: unum.h:173
Escape padding character.
Definition: unum.h:1145
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:1024
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:858
The decimal separator.
Definition: unum.h:1119
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
Currency format for accounting, e.g., "($3.00)" for negative currency amount instead of "-$3...
Definition: unum.h:206
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:860
Minimum significant digits.
Definition: unum.h:872
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:1137
int32_t unum_getAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The default rule set.
Definition: unum.h:1031
The monetary separator.
Definition: unum.h:1139
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:1135
The plus sign.
Definition: unum.h:1133
Duration rule-based format.
Definition: unum.h:178
#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:834
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1022
Grouping size.
Definition: unum.h:856
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:1038
#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:842
Character representing a digit in the pattern.
Definition: unum.h:1129
C API: Locale.
Always show decimal point.
Definition: unum.h:840
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.