ICU 65.1  65.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/parseerr.h"
11 #include "unicode/ufieldpositer.h"
12 #include "unicode/umisc.h"
14 
15 
98 typedef enum UNumberUnitWidth {
111 
127 
138 
149 
158 
166 
200 
216 
231 
247 
255 
256 #ifndef U_HIDE_INTERNAL_API
257  ,
264 #endif /* U_HIDE_INTERNAL_API */
265 
267 
287 typedef enum UNumberSignDisplay {
295 
303 
310 
326 
336 
344 
354 
362 
382 
389 
397 
398 struct UNumberFormatter;
407 
408 struct UFormattedNumber;
417 
418 
436 U_STABLE UNumberFormatter* U_EXPORT2
437 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
438  UErrorCode* ec);
439 
440 
441 #ifndef U_HIDE_DRAFT_API
442 
454 U_DRAFT UNumberFormatter* U_EXPORT2
456  const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
457 #endif // U_HIDE_DRAFT_API
458 
459 
468 U_STABLE UFormattedNumber* U_EXPORT2
470 
471 
487 U_STABLE void U_EXPORT2
488 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
489  UErrorCode* ec);
490 
491 
507 U_STABLE void U_EXPORT2
508 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
509  UErrorCode* ec);
510 
511 
531 U_STABLE void U_EXPORT2
532 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
533  UFormattedNumber* uresult, UErrorCode* ec);
534 
535 #ifndef U_HIDE_DRAFT_API
536 
550 U_DRAFT const UFormattedValue* U_EXPORT2
551 unumf_resultAsValue(const UFormattedNumber* uresult, UErrorCode* ec);
552 #endif /* U_HIDE_DRAFT_API */
553 
554 
574 U_STABLE int32_t U_EXPORT2
575 unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
576  UErrorCode* ec);
577 
578 
612 U_STABLE UBool U_EXPORT2
614 
615 
637 U_STABLE void U_EXPORT2
639  UErrorCode* ec);
640 
641 
642 // TODO(ICU-20775): Propose this as API.
643 // NOTE: This is not currently implemented.
644 // U_DRAFT int32_t U_EXPORT2
645 // unumf_resultToDecimalNumber(const UFormattedNumber* uresult, char* buffer, int32_t bufferCapacity,
646 // UErrorCode* ec);
647 
648 
655 U_STABLE void U_EXPORT2
656 unumf_close(UNumberFormatter* uformatter);
657 
658 
665 U_STABLE void U_EXPORT2
667 
668 
669 #if U_SHOW_CPLUSPLUS_API
670 U_NAMESPACE_BEGIN
671 
688 
705 
706 U_NAMESPACE_END
707 #endif // U_SHOW_CPLUSPLUS_API
708 
709 #endif //__UNUMBERFORMATTER_H__
710 #endif /* #if !UCONFIG_NO_FORMATTING */
UNUM_DECIMAL_SEPARATOR_COUNT
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:395
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.
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:353
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
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_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:148
UNUM_UNIT_WIDTH_COUNT
@ 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:261
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:287
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:360
LocalUFormattedNumberPointer
Definition: unumberformatter.h:687
UFormattedNumber
struct UFormattedNumber UFormattedNumber
C-compatible version of icu::number::FormattedNumber.
Definition: unumberformatter.h:416
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:325
UFieldPositionIterator
struct UFieldPositionIterator UFieldPositionIterator
C typedef for struct UFieldPositionIterator.
Definition: ufieldpositer.h:44
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:157
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:263
unumf_resultGetAllFieldPositions
void unumf_resultGetAllFieldPositions(const UFormattedNumber *uresult, UFieldPositionIterator *ufpositer, UErrorCode *ec)
Populates the given iterator with all fields in the formatted output string.
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.
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:363
UNUM_SIGN_NEVER
@ UNUM_SIGN_NEVER
Do not show the sign on positive or negative numbers.
Definition: unumberformatter.h:309
unumf_close
void unumf_close(UNumberFormatter *uformatter)
Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
LocalUNumberFormatterPointer
UNUM_UNIT_WIDTH_SHORT
@ UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:126
UNumberFormatter
struct UNumberFormatter UNumberFormatter
C-compatible version of icu::number::LocalizedNumberFormatter.
Definition: unumberformatter.h:406
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:294
ufieldpositer.h
C API: UFieldPositionIterator for use with format APIs.
unumf_openResult
UFormattedNumber * unumf_openResult(UErrorCode *ec)
Creates an object to hold the result of a UNumberFormatter operation.
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:98
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:374
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
Definition: localpointer.h:562
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:302
unumf_closeResult
void unumf_closeResult(UFormattedNumber *uresult)
Releases the UFormattedNumber created by unumf_openResult().
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:381
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...
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:335
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:343
UNUM_GROUPING_THOUSANDS
@ UNUM_GROUPING_THOUSANDS
Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater.
Definition: unumberformatter.h:254
UNUM_UNIT_WIDTH_NARROW
@ UNUM_UNIT_WIDTH_NARROW
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:110
UNUM_UNIT_WIDTH_FULL_NAME
@ UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: unumberformatter.h:137
U_DRAFT
#define U_DRAFT
This is used to declare a function as a draft public ICU C API
Definition: umachine.h:113
U_STABLE
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
UNUM_GROUPING_ON_ALIGNED
@ UNUM_GROUPING_ON_ALIGNED
Always display the grouping separator on values of at least 1000.
Definition: unumberformatter.h:246
UNUM_GROUPING_OFF
@ UNUM_GROUPING_OFF
Do not display grouping separators in any locale.
Definition: unumberformatter.h:199
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...
UChar
uint16_t UChar
Definition: umachine.h:378
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:215
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.
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
Definition: unumberformatter.h:193
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.
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_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:388
UNUM_GROUPING_AUTO
@ UNUM_GROUPING_AUTO
Display grouping using the default strategy for all locales.
Definition: unumberformatter.h:230