ICU 63.1 63.1

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/ufieldpositer.h"
11 #include "unicode/umisc.h"
12
13
79 #ifndef U_HIDE_DRAFT_API
80
98 typedef enum UNumberUnitWidth {
110 UNUM_UNIT_WIDTH_NARROW,
111
126 UNUM_UNIT_WIDTH_SHORT,
127
137 UNUM_UNIT_WIDTH_FULL_NAME,
138
148 UNUM_UNIT_WIDTH_ISO_CODE,
149
157 UNUM_UNIT_WIDTH_HIDDEN,
158
164 UNUM_UNIT_WIDTH_COUNT
165 } UNumberUnitWidth;
166 #endif /* U_HIDE_DRAFT_API */
167
168 #ifndef U_HIDE_DRAFT_API
169
195 typedef enum UNumberGroupingStrategy {
201 UNUM_GROUPING_OFF,
202
217 UNUM_GROUPING_MIN2,
218
232 UNUM_GROUPING_AUTO,
233
248 UNUM_GROUPING_ON_ALIGNED,
249
256 UNUM_GROUPING_THOUSANDS
257
258 #ifndef U_HIDE_INTERNAL_API
259 ,
265 UNUM_GROUPING_COUNT
266 #endif /* U_HIDE_INTERNAL_API */
267
268 } UNumberGroupingStrategy;
269
270 #ifndef U_HIDE_DEPRECATED_API
271
275 typedef UNumberGroupingStrategy UGroupingStrategy;
276 #endif /* U_HIDE_DEPRECATED_API */
277
278 #endif /* U_HIDE_DRAFT_API */
279
280 #ifndef U_HIDE_DRAFT_API
281
300 typedef enum UNumberSignDisplay {
307 UNUM_SIGN_AUTO,
308
315 UNUM_SIGN_ALWAYS,
316
322 UNUM_SIGN_NEVER,
323
338 UNUM_SIGN_ACCOUNTING,
339
348 UNUM_SIGN_ACCOUNTING_ALWAYS,
349
356 UNUM_SIGN_EXCEPT_ZERO,
357
365 UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
366
372 UNUM_SIGN_COUNT
373 } UNumberSignDisplay;
374 #endif /* U_HIDE_DRAFT_API */
375
376 #ifndef U_HIDE_DRAFT_API
377
386 typedef enum UNumberDecimalSeparatorDisplay {
393 UNUM_DECIMAL_SEPARATOR_AUTO,
394
400 UNUM_DECIMAL_SEPARATOR_ALWAYS,
401
407 UNUM_DECIMAL_SEPARATOR_COUNT
408 } UNumberDecimalSeparatorDisplay;
409 #endif /* U_HIDE_DRAFT_API */
410
411 #ifndef U_HIDE_DRAFT_API
412
413 struct UNumberFormatter;
421 typedef struct UNumberFormatter UNumberFormatter;
422
423 struct UFormattedNumber;
431 typedef struct UFormattedNumber UFormattedNumber;
432
433
451 U_DRAFT UNumberFormatter* U_EXPORT2
452 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
453 UErrorCode* ec);
454
455
466 U_DRAFT UFormattedNumber* U_EXPORT2
467 unumf_openResult(UErrorCode* ec);
468
469
485 U_DRAFT void U_EXPORT2
486 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
487 UErrorCode* ec);
488
489
505 U_DRAFT void U_EXPORT2
506 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
507 UErrorCode* ec);
508
509
529 U_DRAFT void U_EXPORT2
530 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
531 UFormattedNumber* uresult, UErrorCode* ec);
532
533
548 U_DRAFT int32_t U_EXPORT2
549 unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
550 UErrorCode* ec);
551
552
584 U_DRAFT UBool U_EXPORT2
585 unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec);
586
587
606 U_DRAFT void U_EXPORT2
607 unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
608 UErrorCode* ec);
609
610
619 U_DRAFT void U_EXPORT2
620 unumf_close(UNumberFormatter* uformatter);
621
622
631 U_DRAFT void U_EXPORT2
632 unumf_closeResult(UFormattedNumber* uresult);
633
634
635 #if U_SHOW_CPLUSPLUS_API
636 U_NAMESPACE_BEGIN
637
653 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
654
670 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unumf_closeResult);
671
672 U_NAMESPACE_END
673 #endif // U_SHOW_CPLUSPLUS_API
674
675 #endif /* U_HIDE_DRAFT_API */
676
677 #endif //__UNUMBERFORMATTER_H__
678 #endif /* #if !UCONFIG_NO_FORMATTING */
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:372
UGroupingStrategy
UNumberGroupingStrategy UGroupingStrategy
Old name for compatibility: will be removed in ICU 64.
Definition: unumberformatter.h:275
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:265
unumf_openResult
UFormattedNumber * unumf_openResult(UErrorCode *ec)
Creates a new UFormattedNumber for holding the result of a number formatting 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:365
UNumberFormatter
struct UNumberFormatter UNumberFormatter
C-compatible version of icu::number::LocalizedNumberFormatter.
Definition: unumberformatter.h:421
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:148
UNUM_SIGN_ACCOUNTING
Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive ...
Definition: unumberformatter.h:338
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:386
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:322
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
UNUM_UNIT_WIDTH_HIDDEN
Format the number according to the specified unit, but do not display the unit.
Definition: unumberformatter.h:157
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:487
UFormattedNumber
struct UFormattedNumber UFormattedNumber
C-compatible version of icu::number::FormattedNumber.
Definition: unumberformatter.h:431
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:300
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i.e., the separator, often a comma or period, after every 2-3 powers of ten).
Definition: unumberformatter.h:195
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:393
UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: unumberformatter.h:137
UNUM_GROUPING_OFF
Do not display grouping separators in any locale.
Definition: unumberformatter.h:201
UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:126
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:110
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:307
UNUM_GROUPING_ON_ALIGNED
Always display the grouping separator on values of at least 1000.
Definition: unumberformatter.h:248
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:348
UNUM_SIGN_ALWAYS
Show the minus sign on negative numbers and the plus sign on positive numbers, including zero...
Definition: unumberformatter.h:315
ufieldpositer.h
C API: UFieldPositionIterator for use with format APIs.
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:98
UNUM_GROUPING_AUTO
Display grouping using the default strategy for all locales.
Definition: unumberformatter.h:232
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:256
UNUM_GROUPING_MIN2
Display grouping using locale defaults, except do not show grouping on values smaller than 10000 (suc...
Definition: unumberformatter.h:217
UNUM_DECIMAL_SEPARATOR_ALWAYS
Always show the decimal separator, even if there are no digits to display after the separator...
Definition: unumberformatter.h:400
UNUM_SIGN_EXCEPT_ZERO
Show the minus sign on negative numbers and the plus sign on positive numbers.
Definition: unumberformatter.h:356
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:407
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:164
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.