ICU 68.2: unumberformatter.h Source File

ICU 68.2 68.2

unumberformatter.h
Go to the documentation of this file.
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #ifndef __UNUMBERFORMATTER_H__
5 #define __UNUMBERFORMATTER_H__
6
7 #include "unicode/utypes.h"
8
9 #if !UCONFIG_NO_FORMATTING
10
11 #include "unicode/parseerr.h"
12 #include "unicode/ufieldpositer.h"
13 #include "unicode/umisc.h"
14 #include "unicode/uformattedvalue.h"
15
16
99 typedef enum UNumberUnitWidth {
111 UNUM_UNIT_WIDTH_NARROW,
112
127 UNUM_UNIT_WIDTH_SHORT,
128
138 UNUM_UNIT_WIDTH_FULL_NAME,
139
149 UNUM_UNIT_WIDTH_ISO_CODE,
150
151 #ifndef U_HIDE_DRAFT_API
152
161 UNUM_UNIT_WIDTH_FORMAL,
162
172 UNUM_UNIT_WIDTH_VARIANT,
173 #endif // U_HIDE_DRAFT_API
174
182 UNUM_UNIT_WIDTH_HIDDEN,
183
189 UNUM_UNIT_WIDTH_COUNT
190 } UNumberUnitWidth;
191
218 typedef enum UNumberGroupingStrategy {
224 UNUM_GROUPING_OFF,
225
240 UNUM_GROUPING_MIN2,
241
255 UNUM_GROUPING_AUTO,
256
271 UNUM_GROUPING_ON_ALIGNED,
272
279 UNUM_GROUPING_THOUSANDS
280
281 #ifndef U_HIDE_INTERNAL_API
282 ,
288 UNUM_GROUPING_COUNT
289 #endif /* U_HIDE_INTERNAL_API */
290
291 } UNumberGroupingStrategy;
292
312 typedef enum UNumberSignDisplay {
319 UNUM_SIGN_AUTO,
320
327 UNUM_SIGN_ALWAYS,
328
334 UNUM_SIGN_NEVER,
335
350 UNUM_SIGN_ACCOUNTING,
351
360 UNUM_SIGN_ACCOUNTING_ALWAYS,
361
368 UNUM_SIGN_EXCEPT_ZERO,
369
377 UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
378
384 UNUM_SIGN_COUNT
385 } UNumberSignDisplay;
386
398 typedef enum UNumberDecimalSeparatorDisplay {
405 UNUM_DECIMAL_SEPARATOR_AUTO,
406
412 UNUM_DECIMAL_SEPARATOR_ALWAYS,
413
419 UNUM_DECIMAL_SEPARATOR_COUNT
420 } UNumberDecimalSeparatorDisplay;
421
422 struct UNumberFormatter;
430 typedef struct UNumberFormatter UNumberFormatter;
431
432 struct UFormattedNumber;
440 typedef struct UFormattedNumber UFormattedNumber;
441
442
460 U_CAPI UNumberFormatter* U_EXPORT2
461 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
462 UErrorCode* ec);
463
464
477 U_CAPI UNumberFormatter* U_EXPORT2
478 unumf_openForSkeletonAndLocaleWithError(
479 const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
480
481
490 U_CAPI UFormattedNumber* U_EXPORT2
491 unumf_openResult(UErrorCode* ec);
492
493
509 U_CAPI void U_EXPORT2
510 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
511 UErrorCode* ec);
512
513
529 U_CAPI void U_EXPORT2
530 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
531 UErrorCode* ec);
532
533
553 U_CAPI void U_EXPORT2
554 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
555 UFormattedNumber* uresult, UErrorCode* ec);
556
571 U_CAPI const UFormattedValue* U_EXPORT2
572 unumf_resultAsValue(const UFormattedNumber* uresult, UErrorCode* ec);
573
574
594 U_CAPI int32_t U_EXPORT2
595 unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
596 UErrorCode* ec);
597
598
632 U_CAPI UBool U_EXPORT2
633 unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec);
634
635
657 U_CAPI void U_EXPORT2
658 unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
659 UErrorCode* ec);
660
661
662 #ifndef U_HIDE_DRAFT_API
663
681 U_CAPI int32_t U_EXPORT2
682 unumf_resultToDecimalNumber(
683 const UFormattedNumber* uresult,
684 char* dest,
685 int32_t destCapacity,
686 UErrorCode* ec);
687 #endif // U_HIDE_DRAFT_API
688
689
696 U_CAPI void U_EXPORT2
697 unumf_close(UNumberFormatter* uformatter);
698
699
706 U_CAPI void U_EXPORT2
707 unumf_closeResult(UFormattedNumber* uresult);
708
709
710 #if U_SHOW_CPLUSPLUS_API
711 U_NAMESPACE_BEGIN
712
728 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
729
745 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unumf_closeResult);
746
747 U_NAMESPACE_END
748 #endif // U_SHOW_CPLUSPLUS_API
749
750 #endif /* #if !UCONFIG_NO_FORMATTING */
751 #endif //__UNUMBERFORMATTER_H__
UNUM_UNIT_WIDTH_VARIANT
@ UNUM_UNIT_WIDTH_VARIANT
Use the alternate variant of the currency symbol; for example, "TL" for the Turkish lira (TRY).
Definition: unumberformatter.h:172
UNUM_DECIMAL_SEPARATOR_COUNT
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:419
parseerr.h
C API: Parse Error Information.
UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO
@ UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: unumberformatter.h:377
unumf_formatInt
U_CAPI void unumf_formatInt(const UNumberFormatter *uformatter, int64_t value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format an integer to a UFormattedNumber.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
unumf_openForSkeletonAndLocaleWithError
U_CAPI UNumberFormatter * unumf_openForSkeletonAndLocaleWithError(const UChar *skeleton, int32_t skeletonLen, const char *locale, UParseError *perror, UErrorCode *ec)
Like unumf_openForSkeletonAndLocale, but accepts a UParseError, which will be populated with the loca...
UNUM_UNIT_WIDTH_ISO_CODE
@ UNUM_UNIT_WIDTH_ISO_CODE
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
Definition: unumberformatter.h:149
UNUM_UNIT_WIDTH_COUNT
@ UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: unumberformatter.h:189
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:312
uformattedvalue.h
C API: Abstract operations for localized strings.
UNUM_SIGN_COUNT
@ UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:384
LocalUFormattedNumberPointer
"Smart pointer" class; closes a UFormattedNumber via unumf_closeResult().
Definition: unumberformatter.h:728
UFormattedNumber
struct UFormattedNumber UFormattedNumber
C-compatible version of icu::number::FormattedNumber.
Definition: unumberformatter.h:440
unumf_resultAsValue
U_CAPI const UFormattedValue * unumf_resultAsValue(const UFormattedNumber *uresult, UErrorCode *ec)
Returns a representation of a UFormattedNumber as a UFormattedValue, which can be subsequently passed...
unumf_openResult
U_CAPI UFormattedNumber * unumf_openResult(UErrorCode *ec)
Creates an object to hold the result of a UNumberFormatter operation.
UNUM_SIGN_ACCOUNTING
@ UNUM_SIGN_ACCOUNTING
Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive ...
Definition: unumberformatter.h:350
UFieldPositionIterator
struct UFieldPositionIterator UFieldPositionIterator
C typedef for struct UFieldPositionIterator.
Definition: ufieldpositer.h:46
UNUM_UNIT_WIDTH_HIDDEN
@ UNUM_UNIT_WIDTH_HIDDEN
Format the number according to the specified unit, but do not display the unit.
Definition: unumberformatter.h:182
unumf_openForSkeletonAndLocale
U_CAPI UNumberFormatter * unumf_openForSkeletonAndLocale(const UChar *skeleton, int32_t skeletonLen, const char *locale, UErrorCode *ec)
Creates a new UNumberFormatter for the given skeleton string and locale.
umisc.h
C API:misc definitions.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
UNUM_GROUPING_COUNT
@ UNUM_GROUPING_COUNT
One more than the highest UNumberGroupingStrategy value.
Definition: unumberformatter.h:288
unumf_resultToString
U_CAPI int32_t unumf_resultToString(const UFormattedNumber *uresult, UChar *buffer, int32_t bufferCapacity, UErrorCode *ec)
Extracts the result number string out of a UFormattedNumber to a UChar buffer if possible.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UFormattedValue
struct UFormattedValue UFormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: uformattedvalue.h:361
UNUM_SIGN_NEVER
@ UNUM_SIGN_NEVER
Do not show the sign on positive or negative numbers.
Definition: unumberformatter.h:334
LocalUNumberFormatterPointer
"Smart pointer" class; closes a UNumberFormatter via unumf_close().
UNUM_UNIT_WIDTH_SHORT
@ UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:127
unumf_formatDouble
U_CAPI void unumf_formatDouble(const UNumberFormatter *uformatter, double value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format a double to a UFormattedNumber.
UNumberFormatter
struct UNumberFormatter UNumberFormatter
C-compatible version of icu::number::LocalizedNumberFormatter.
Definition: unumberformatter.h:430
UNUM_SIGN_AUTO
@ UNUM_SIGN_AUTO
Show the minus sign on negative numbers, and do not show the sign on positive numbers.
Definition: unumberformatter.h:319
ufieldpositer.h
C API: UFieldPositionIterator for use with format APIs.
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:99
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:398
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:550
unumf_resultGetAllFieldPositions
U_CAPI void unumf_resultGetAllFieldPositions(const UFormattedNumber *uresult, UFieldPositionIterator *ufpositer, UErrorCode *ec)
Populates the given iterator with all fields in the formatted output string.
UFieldPosition
A struct representing a range of text containing a specific field.
Definition: umisc.h:34
UNUM_SIGN_ALWAYS
@ UNUM_SIGN_ALWAYS
Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.
Definition: unumberformatter.h:327
UNUM_DECIMAL_SEPARATOR_AUTO
@ UNUM_DECIMAL_SEPARATOR_AUTO
Show the decimal separator when there are one or more digits to display after the separator,...
Definition: unumberformatter.h:405
unumf_closeResult
U_CAPI void unumf_closeResult(UFormattedNumber *uresult)
Releases the UFormattedNumber created by unumf_openResult().
UNUM_SIGN_ACCOUNTING_ALWAYS
@ UNUM_SIGN_ACCOUNTING_ALWAYS
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: unumberformatter.h:360
UNUM_SIGN_EXCEPT_ZERO
@ UNUM_SIGN_EXCEPT_ZERO
Show the minus sign on negative numbers and the plus sign on positive numbers.
Definition: unumberformatter.h:368
UNUM_GROUPING_THOUSANDS
@ UNUM_GROUPING_THOUSANDS
Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater.
Definition: unumberformatter.h:279
UNUM_UNIT_WIDTH_NARROW
@ UNUM_UNIT_WIDTH_NARROW
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:111
UNUM_UNIT_WIDTH_FULL_NAME
@ UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: unumberformatter.h:138
UNUM_GROUPING_ON_ALIGNED
@ UNUM_GROUPING_ON_ALIGNED
Always display the grouping separator on values of at least 1000.
Definition: unumberformatter.h:271
UNUM_GROUPING_OFF
@ UNUM_GROUPING_OFF
Do not display grouping separators in any locale.
Definition: unumberformatter.h:224
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:418
UNUM_UNIT_WIDTH_FORMAL
@ UNUM_UNIT_WIDTH_FORMAL
Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan dollar in zh-TW.
Definition: unumberformatter.h:161
UNUM_GROUPING_MIN2
@ UNUM_GROUPING_MIN2
Display grouping using locale defaults, except do not show grouping on values smaller than 10000 (suc...
Definition: unumberformatter.h:240
unumf_formatDecimal
U_CAPI void unumf_formatDecimal(const UNumberFormatter *uformatter, const char *value, int32_t valueLen, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format a decimal number to a UFormattedNumber.
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
Definition: unumberformatter.h:218
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
unumf_close
U_CAPI void unumf_close(UNumberFormatter *uformatter)
Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
unumf_resultNextFieldPosition
U_CAPI UBool unumf_resultNextFieldPosition(const UFormattedNumber *uresult, UFieldPosition *ufpos, UErrorCode *ec)
Determines the start and end indices of the next occurrence of the given field in the output string.
UNUM_DECIMAL_SEPARATOR_ALWAYS
@ UNUM_DECIMAL_SEPARATOR_ALWAYS
Always show the decimal separator, even if there are no digits to display after the separator.
Definition: unumberformatter.h:412
unumf_resultToDecimalNumber
U_CAPI int32_t unumf_resultToDecimalNumber(const UFormattedNumber *uresult, char *dest, int32_t destCapacity, UErrorCode *ec)
Extracts the formatted number as a "numeric string" conforming to the syntax defined in the Decimal A...
UNUM_GROUPING_AUTO
@ UNUM_GROUPING_AUTO
Display grouping using the default strategy for all locales.
Definition: unumberformatter.h:255