ICU 75.1 75.1

unumberrangeformatter.h
Go to the documentation of this file.
1 // © 2020 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #ifndef __UNUMBERRANGEFORMATTER_H__
5 #define __UNUMBERRANGEFORMATTER_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 #include "unicode/uformattable.h"
16
17
83 typedef enum UNumberRangeCollapse {
92 UNUM_RANGE_COLLAPSE_AUTO,
93
99 UNUM_RANGE_COLLAPSE_NONE,
100
107 UNUM_RANGE_COLLAPSE_UNIT,
108
115 UNUM_RANGE_COLLAPSE_ALL
116 } UNumberRangeCollapse;
117
125 typedef enum UNumberRangeIdentityFallback {
131 UNUM_IDENTITY_FALLBACK_SINGLE_VALUE,
132
139 UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE,
140
147 UNUM_IDENTITY_FALLBACK_APPROXIMATELY,
148
155 UNUM_IDENTITY_FALLBACK_RANGE
156 } UNumberRangeIdentityFallback;
157
165 typedef enum UNumberRangeIdentityResult {
172 UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING,
173
180 UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING,
181
188 UNUM_IDENTITY_RESULT_NOT_EQUAL,
189
190 #ifndef U_HIDE_INTERNAL_API
195 UNUM_IDENTITY_RESULT_COUNT
196 #endif /* U_HIDE_INTERNAL_API */
197
198 } UNumberRangeIdentityResult;
199
200
201 struct UNumberRangeFormatter;
209 typedef struct UNumberRangeFormatter UNumberRangeFormatter;
210
211
212 struct UFormattedNumberRange;
220 typedef struct UFormattedNumberRange UFormattedNumberRange;
221
222
244 U_CAPI UNumberRangeFormatter* U_EXPORT2
245 unumrf_openForSkeletonWithCollapseAndIdentityFallback(
246 const UChar* skeleton,
247 int32_t skeletonLen,
248 UNumberRangeCollapse collapse,
249 UNumberRangeIdentityFallback identityFallback,
250 const char* locale,
251 UParseError* perror,
252 UErrorCode* ec);
253
254
263 U_CAPI UFormattedNumberRange* U_EXPORT2
264 unumrf_openResult(UErrorCode* ec);
265
266
282 U_CAPI void U_EXPORT2
283 unumrf_formatDoubleRange(
284 const UNumberRangeFormatter* uformatter,
285 double first,
286 double second,
287 UFormattedNumberRange* uresult,
288 UErrorCode* ec);
289
290
310 U_CAPI void U_EXPORT2
311 unumrf_formatDecimalRange(
312 const UNumberRangeFormatter* uformatter,
313 const char* first,
314 int32_t firstLen,
315 const char* second,
316 int32_t secondLen,
317 UFormattedNumberRange* uresult,
318 UErrorCode* ec);
319
320
335 U_CAPI const UFormattedValue* U_EXPORT2
336 unumrf_resultAsValue(const UFormattedNumberRange* uresult, UErrorCode* ec);
337
338
349 U_CAPI UNumberRangeIdentityResult U_EXPORT2
350 unumrf_resultGetIdentityResult(
351 const UFormattedNumberRange* uresult,
352 UErrorCode* ec);
353
354
374 U_CAPI int32_t U_EXPORT2
375 unumrf_resultGetFirstDecimalNumber(
376 const UFormattedNumberRange* uresult,
377 char* dest,
378 int32_t destCapacity,
379 UErrorCode* ec);
380
381
401 U_CAPI int32_t U_EXPORT2
402 unumrf_resultGetSecondDecimalNumber(
403 const UFormattedNumberRange* uresult,
404 char* dest,
405 int32_t destCapacity,
406 UErrorCode* ec);
407
408
415 U_CAPI void U_EXPORT2
416 unumrf_close(UNumberRangeFormatter* uformatter);
417
418
425 U_CAPI void U_EXPORT2
426 unumrf_closeResult(UFormattedNumberRange* uresult);
427
428
429 #if U_SHOW_CPLUSPLUS_API
430 U_NAMESPACE_BEGIN
431
448 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberRangeFormatterPointer, UNumberRangeFormatter, unumrf_close);
449
465 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberRangePointer, UFormattedNumberRange, unumrf_closeResult);
466
467 U_NAMESPACE_END
468 #endif // U_SHOW_CPLUSPLUS_API
469
470 #endif /* #if !UCONFIG_NO_FORMATTING */
471 #endif //__UNUMBERRANGEFORMATTER_H__
LocalUNumberRangeFormatterPointer
"Smart pointer" class; closes a UNumberFormatter via unumf_close().
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
parseerr.h
C API: Parse Error Information.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
ufieldpositer.h
C API: UFieldPositionIterator for use with format APIs.
uformattable.h
C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing.
uformattedvalue.h
C API: Abstract operations for localized strings.
UFormattedValue
struct UFormattedValue UFormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: uformattedvalue.h:368
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
umisc.h
C API: Miscellaneous definitions.
UNumberRangeIdentityResult
UNumberRangeIdentityResult
Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted i...
Definition: unumberrangeformatter.h:165
UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING
@ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING
Used to indicate that the two numbers in the range were equal, even before any rounding rules were ap...
Definition: unumberrangeformatter.h:172
UNUM_IDENTITY_RESULT_NOT_EQUAL
@ UNUM_IDENTITY_RESULT_NOT_EQUAL
Used to indicate that the two numbers in the range were not equal, even after rounding rules were app...
Definition: unumberrangeformatter.h:188
UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING
@ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING
Used to indicate that the two numbers in the range were equal, but only after rounding rules were app...
Definition: unumberrangeformatter.h:180
UNUM_IDENTITY_RESULT_COUNT
@ UNUM_IDENTITY_RESULT_COUNT
The number of entries in this enum.
Definition: unumberrangeformatter.h:195
unumrf_openForSkeletonWithCollapseAndIdentityFallback
U_CAPI UNumberRangeFormatter * unumrf_openForSkeletonWithCollapseAndIdentityFallback(const UChar *skeleton, int32_t skeletonLen, UNumberRangeCollapse collapse, UNumberRangeIdentityFallback identityFallback, const char *locale, UParseError *perror, UErrorCode *ec)
Creates a new UNumberFormatter for the given skeleton string, collapse option, identity fallback opti...
unumrf_formatDoubleRange
U_CAPI void unumrf_formatDoubleRange(const UNumberRangeFormatter *uformatter, double first, double second, UFormattedNumberRange *uresult, UErrorCode *ec)
Uses a UNumberRangeFormatter to format a range of doubles.
unumrf_resultGetFirstDecimalNumber
U_CAPI int32_t unumrf_resultGetFirstDecimalNumber(const UFormattedNumberRange *uresult, char *dest, int32_t destCapacity, UErrorCode *ec)
Extracts the first formatted number as a decimal number.
unumrf_openResult
U_CAPI UFormattedNumberRange * unumrf_openResult(UErrorCode *ec)
Creates an object to hold the result of a UNumberRangeFormatter operation.
unumrf_closeResult
U_CAPI void unumrf_closeResult(UFormattedNumberRange *uresult)
Releases the UFormattedNumber created by unumf_openResult().
UNumberRangeIdentityFallback
UNumberRangeIdentityFallback
Defines the behavior when the two numbers in the range are identical after rounding.
Definition: unumberrangeformatter.h:125
UNUM_IDENTITY_FALLBACK_APPROXIMATELY
@ UNUM_IDENTITY_FALLBACK_APPROXIMATELY
Show the number using a locale-sensitive approximation pattern.
Definition: unumberrangeformatter.h:147
UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE
@ UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE
Show the number using a locale-sensitive approximation pattern.
Definition: unumberrangeformatter.h:139
UNUM_IDENTITY_FALLBACK_SINGLE_VALUE
@ UNUM_IDENTITY_FALLBACK_SINGLE_VALUE
Show the number as a single value rather than a range.
Definition: unumberrangeformatter.h:131
UNUM_IDENTITY_FALLBACK_RANGE
@ UNUM_IDENTITY_FALLBACK_RANGE
Show the number as the range of two equal values.
Definition: unumberrangeformatter.h:155
unumrf_close
U_CAPI void unumrf_close(UNumberRangeFormatter *uformatter)
Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
UFormattedNumberRange
struct UFormattedNumberRange UFormattedNumberRange
C-compatible version of icu::number::FormattedNumberRange.
Definition: unumberrangeformatter.h:220
unumrf_resultGetIdentityResult
U_CAPI UNumberRangeIdentityResult unumrf_resultGetIdentityResult(const UFormattedNumberRange *uresult, UErrorCode *ec)
Extracts the identity result from a UFormattedNumberRange.
unumrf_formatDecimalRange
U_CAPI void unumrf_formatDecimalRange(const UNumberRangeFormatter *uformatter, const char *first, int32_t firstLen, const char *second, int32_t secondLen, UFormattedNumberRange *uresult, UErrorCode *ec)
Uses a UNumberRangeFormatter to format a range of decimal numbers.
UNumberRangeCollapse
UNumberRangeCollapse
Defines how to merge fields that are identical across the range sign.
Definition: unumberrangeformatter.h:83
UNUM_RANGE_COLLAPSE_ALL
@ UNUM_RANGE_COLLAPSE_ALL
Collapse any field that is equal across the range sign.
Definition: unumberrangeformatter.h:115
UNUM_RANGE_COLLAPSE_AUTO
@ UNUM_RANGE_COLLAPSE_AUTO
Use locale data and heuristics to determine how much of the string to collapse.
Definition: unumberrangeformatter.h:92
UNUM_RANGE_COLLAPSE_UNIT
@ UNUM_RANGE_COLLAPSE_UNIT
Collapse the unit part of the number, but not the notation, if present.
Definition: unumberrangeformatter.h:107
UNUM_RANGE_COLLAPSE_NONE
@ UNUM_RANGE_COLLAPSE_NONE
Do not collapse any part of the number.
Definition: unumberrangeformatter.h:99
unumrf_resultGetSecondDecimalNumber
U_CAPI int32_t unumrf_resultGetSecondDecimalNumber(const UFormattedNumberRange *uresult, char *dest, int32_t destCapacity, UErrorCode *ec)
Extracts the second formatted number as a decimal number.
UNumberRangeFormatter
struct UNumberRangeFormatter UNumberRangeFormatter
C-compatible version of icu::number::LocalizedNumberRangeFormatter.
Definition: unumberrangeformatter.h:209
unumrf_resultAsValue
U_CAPI const UFormattedValue * unumrf_resultAsValue(const UFormattedNumberRange *uresult, UErrorCode *ec)
Returns a representation of a UFormattedNumberRange as a UFormattedValue, which can be subsequently p...
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415