ICU 64.2 64.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 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __UNUMBERFORMATTER_H__
8 #define __UNUMBERFORMATTER_H__
9
10 #include "unicode/parseerr.h"
11 #include "unicode/ufieldpositer.h"
12 #include "unicode/umisc.h"
13 #include "unicode/uformattedvalue.h"
14
15
81 #ifndef U_HIDE_DRAFT_API
82
100 typedef enum UNumberUnitWidth {
112 UNUM_UNIT_WIDTH_NARROW,
113
128 UNUM_UNIT_WIDTH_SHORT,
129
139 UNUM_UNIT_WIDTH_FULL_NAME,
140
150 UNUM_UNIT_WIDTH_ISO_CODE,
151
159 UNUM_UNIT_WIDTH_HIDDEN,
160
166 UNUM_UNIT_WIDTH_COUNT
167 } UNumberUnitWidth;
168 #endif /* U_HIDE_DRAFT_API */
169
170 #ifndef U_HIDE_DRAFT_API
171
197 typedef enum UNumberGroupingStrategy {
203 UNUM_GROUPING_OFF,
204
219 UNUM_GROUPING_MIN2,
220
234 UNUM_GROUPING_AUTO,
235
250 UNUM_GROUPING_ON_ALIGNED,
251
258 UNUM_GROUPING_THOUSANDS
259
260 #ifndef U_HIDE_INTERNAL_API
261 ,
267 UNUM_GROUPING_COUNT
268 #endif /* U_HIDE_INTERNAL_API */
269
270 } UNumberGroupingStrategy;
271
272
273 #endif /* U_HIDE_DRAFT_API */
274
275 #ifndef U_HIDE_DRAFT_API
276
295 typedef enum UNumberSignDisplay {
302 UNUM_SIGN_AUTO,
303
310 UNUM_SIGN_ALWAYS,
311
317 UNUM_SIGN_NEVER,
318
333 UNUM_SIGN_ACCOUNTING,
334
343 UNUM_SIGN_ACCOUNTING_ALWAYS,
344
351 UNUM_SIGN_EXCEPT_ZERO,
352
360 UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
361
367 UNUM_SIGN_COUNT
368 } UNumberSignDisplay;
369 #endif /* U_HIDE_DRAFT_API */
370
371 #ifndef U_HIDE_DRAFT_API
372
383 typedef enum UNumberDecimalSeparatorDisplay {
390 UNUM_DECIMAL_SEPARATOR_AUTO,
391
397 UNUM_DECIMAL_SEPARATOR_ALWAYS,
398
404 UNUM_DECIMAL_SEPARATOR_COUNT
405 } UNumberDecimalSeparatorDisplay;
406 #endif /* U_HIDE_DRAFT_API */
407
408 struct UNumberFormatter;
416 typedef struct UNumberFormatter UNumberFormatter;
417
418 struct UFormattedNumber;
426 typedef struct UFormattedNumber UFormattedNumber;
427
428
446 U_STABLE UNumberFormatter* U_EXPORT2
447 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
448 UErrorCode* ec);
449
450
451 #ifndef U_HIDE_DRAFT_API
452
464 U_DRAFT UNumberFormatter* U_EXPORT2
465 unumf_openForSkeletonAndLocaleWithError(
466 const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
467 #endif // U_HIDE_DRAFT_API
468
469
478 U_STABLE UFormattedNumber* U_EXPORT2
479 unumf_openResult(UErrorCode* ec);
480
481
497 U_STABLE void U_EXPORT2
498 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
499 UErrorCode* ec);
500
501
517 U_STABLE void U_EXPORT2
518 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
519 UErrorCode* ec);
520
521
541 U_STABLE void U_EXPORT2
542 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
543 UFormattedNumber* uresult, UErrorCode* ec);
544
545 #ifndef U_HIDE_DRAFT_API
546
560 U_DRAFT const UFormattedValue* U_EXPORT2
561 unumf_resultAsValue(const UFormattedNumber* uresult, UErrorCode* ec);
562 #endif /* U_HIDE_DRAFT_API */
563
564
584 U_STABLE int32_t U_EXPORT2
585 unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
586 UErrorCode* ec);
587
588
622 U_STABLE UBool U_EXPORT2
623 unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec);
624
625
647 U_STABLE void U_EXPORT2
648 unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
649 UErrorCode* ec);
650
651
658 U_STABLE void U_EXPORT2
659 unumf_close(UNumberFormatter* uformatter);
660
661
668 U_STABLE void U_EXPORT2
669 unumf_closeResult(UFormattedNumber* uresult);
670
671
672 #if U_SHOW_CPLUSPLUS_API
673 U_NAMESPACE_BEGIN
674
690 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
691
707 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unumf_closeResult);
708
709 U_NAMESPACE_END
710 #endif // U_SHOW_CPLUSPLUS_API
711
712 #endif //__UNUMBERFORMATTER_H__
713 #endif /* #if !UCONFIG_NO_FORMATTING */
UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:367
uformattedvalue.h
C API: Abstract operations for localized strings.
unumf_resultAsValue
const UFormattedValue * unumf_resultAsValue(const UFormattedNumber *uresult, UErrorCode *ec)
Returns a representation of a UFormattedNumber as a UFormattedValue, which can be subsequently passed...
unumf_resultNextFieldPosition
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_GROUPING_COUNT
One more than the highest UNumberGroupingStrategy value.
Definition: unumberformatter.h:267
unumf_openResult
UFormattedNumber * unumf_openResult(UErrorCode *ec)
Creates an object to hold the result of a UNumberFormatter operation.
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:360
UNumberFormatter
struct UNumberFormatter UNumberFormatter
C-compatible version of icu::number::LocalizedNumberFormatter.
Definition: unumberformatter.h:416
umisc.h
C API:misc definitions.
UFieldPositionIterator
struct UFieldPositionIterator UFieldPositionIterator
C typedef for struct UFieldPositionIterator.
Definition: ufieldpositer.h:44
UNUM_UNIT_WIDTH_ISO_CODE
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
Definition: unumberformatter.h:150
UNUM_SIGN_ACCOUNTING
Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive ...
Definition: unumberformatter.h:333
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:383
unumf_close
void unumf_close(UNumberFormatter *uformatter)
Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
unumf_formatDouble
void unumf_formatDouble(const UNumberFormatter *uformatter, double value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format a double to a UFormattedNumber.
UNUM_SIGN_NEVER
Do not show the sign on positive or negative numbers.
Definition: unumberformatter.h:317
unumf_openForSkeletonAndLocale
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.
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
unumf_openForSkeletonAndLocaleWithError
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_HIDDEN
Format the number according to the specified unit, but do not display the unit.
Definition: unumberformatter.h:159
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:562
UFormattedNumber
struct UFormattedNumber UFormattedNumber
C-compatible version of icu::number::FormattedNumber.
Definition: unumberformatter.h:426
UFieldPosition
A struct representing a range of text containing a specific field.
Definition: umisc.h:34
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:295
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
Definition: unumberformatter.h:197
unumf_formatDecimal
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.
UNUM_DECIMAL_SEPARATOR_AUTO
Show the decimal separator when there are one or more digits to display after the separator,...
Definition: unumberformatter.h:390
UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: unumberformatter.h:139
UNUM_GROUPING_OFF
Do not display grouping separators in any locale.
Definition: unumberformatter.h:203
UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:128
LocalUFormattedNumberPointer
"Smart pointer" class; closes a UFormattedNumber via unumf_closeResult().
Definition: unumberformatter.h:690
UChar
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:342
UNUM_UNIT_WIDTH_NARROW
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:112
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
LocalUNumberFormatterPointer
"Smart pointer" class; closes a UNumberFormatter via unumf_close().
unumf_resultToString
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.
UNUM_SIGN_AUTO
Show the minus sign on negative numbers, and do not show the sign on positive numbers.
Definition: unumberformatter.h:302
parseerr.h
C API: Parse Error Information.
UNUM_GROUPING_ON_ALIGNED
Always display the grouping separator on values of at least 1000.
Definition: unumberformatter.h:250
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
UNUM_SIGN_ACCOUNTING_ALWAYS
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: unumberformatter.h:343
UNUM_SIGN_ALWAYS
Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.
Definition: unumberformatter.h:310
ufieldpositer.h
C API: UFieldPositionIterator for use with format APIs.
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:100
UNUM_GROUPING_AUTO
Display grouping using the default strategy for all locales.
Definition: unumberformatter.h:234
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
unumf_formatInt
void unumf_formatInt(const UNumberFormatter *uformatter, int64_t value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format an integer to a UFormattedNumber.
UNUM_GROUPING_THOUSANDS
Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater.
Definition: unumberformatter.h:258
UNUM_GROUPING_MIN2
Display grouping using locale defaults, except do not show grouping on values smaller than 10000 (suc...
Definition: unumberformatter.h:219
UNUM_DECIMAL_SEPARATOR_ALWAYS
Always show the decimal separator, even if there are no digits to display after the separator.
Definition: unumberformatter.h:397
UNUM_SIGN_EXCEPT_ZERO
Show the minus sign on negative numbers and the plus sign on positive numbers.
Definition: unumberformatter.h:351
UFormattedValue
struct UFormattedValue UFormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: uformattedvalue.h:362
U_DRAFT
#define U_DRAFT
This is used to declare a function as a draft public ICU C API.
Definition: umachine.h:113
UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:404
unumf_closeResult
void unumf_closeResult(UFormattedNumber *uresult)
Releases the UFormattedNumber created by unumf_openResult().
UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: unumberformatter.h:166
U_STABLE
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
unumf_resultGetAllFieldPositions
void unumf_resultGetAllFieldPositions(const UFormattedNumber *uresult, UFieldPositionIterator *ufpositer, UErrorCode *ec)
Populates the given iterator with all fields in the formatted output string.