aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/include/unicode/unumberformatter.h
diff options
context:
space:
mode:
authorromankoshelev <romankoshelev@yandex-team.com>2023-08-09 20:07:20 +0300
committerromankoshelev <romankoshelev@yandex-team.com>2023-08-09 20:59:13 +0300
commitfd82fb12fb45e71a02c628e45b12c50c0dd0d308 (patch)
treef582b79f9002ab1d083e9acda600dfb3551c47b6 /contrib/libs/icu/include/unicode/unumberformatter.h
parentbf862ddf5c6178e1bb5e4fb3f7c61015deebe284 (diff)
downloadydb-fd82fb12fb45e71a02c628e45b12c50c0dd0d308.tar.gz
Update ICU to 70.1
Diffstat (limited to 'contrib/libs/icu/include/unicode/unumberformatter.h')
-rw-r--r--contrib/libs/icu/include/unicode/unumberformatter.h225
1 files changed, 190 insertions, 35 deletions
diff --git a/contrib/libs/icu/include/unicode/unumberformatter.h b/contrib/libs/icu/include/unicode/unumberformatter.h
index af98ba0027..cb980cd94d 100644
--- a/contrib/libs/icu/include/unicode/unumberformatter.h
+++ b/contrib/libs/icu/include/unicode/unumberformatter.h
@@ -1,11 +1,12 @@
// © 2018 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
+#ifndef __UNUMBERFORMATTER_H__
+#define __UNUMBERFORMATTER_H__
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
-#ifndef __UNUMBERFORMATTER_H__
-#define __UNUMBERFORMATTER_H__
#include "unicode/parseerr.h"
#include "unicode/ufieldpositer.h"
@@ -77,6 +78,62 @@
* </pre>
*/
+#ifndef U_FORCE_HIDE_DRAFT_API
+/**
+ * An enum declaring how to resolve conflicts between maximum fraction digits and maximum
+ * significant digits.
+ *
+ * There are two modes, RELAXED and STRICT:
+ *
+ * - RELAXED: Relax one of the two constraints (fraction digits or significant digits) in order
+ * to round the number to a higher level of precision.
+ * - STRICT: Enforce both constraints, resulting in the number being rounded to a lower
+ * level of precision.
+ *
+ * The default settings for compact notation rounding are Max-Fraction = 0 (round to the nearest
+ * integer), Max-Significant = 2 (round to 2 significant digits), and priority RELAXED (choose
+ * the constraint that results in more digits being displayed).
+ *
+ * Conflicting *minimum* fraction and significant digits are always resolved in the direction that
+ * results in more trailing zeros.
+ *
+ * Example 1: Consider the number 3.141, with various different settings:
+ *
+ * - Max-Fraction = 1: "3.1"
+ * - Max-Significant = 3: "3.14"
+ *
+ * The rounding priority determines how to resolve the conflict when both Max-Fraction and
+ * Max-Significant are set. With RELAXED, the less-strict setting (the one that causes more digits
+ * to be displayed) will be used; Max-Significant wins. With STRICT, the more-strict setting (the
+ * one that causes fewer digits to be displayed) will be used; Max-Fraction wins.
+ *
+ * Example 2: Consider the number 8317, with various different settings:
+ *
+ * - Max-Fraction = 1: "8317"
+ * - Max-Significant = 3: "8320"
+ *
+ * Here, RELAXED favors Max-Fraction and STRICT favors Max-Significant. Note that this larger
+ * number caused the two modes to favor the opposite result.
+ *
+ * @draft ICU 69
+ */
+typedef enum UNumberRoundingPriority {
+ /**
+ * Favor greater precision by relaxing one of the rounding constraints.
+ *
+ * @draft ICU 69
+ */
+ UNUM_ROUNDING_PRIORITY_RELAXED,
+
+ /**
+ * Favor adherence to all rounding constraints by producing lower precision.
+ *
+ * @draft ICU 69
+ */
+ UNUM_ROUNDING_PRIORITY_STRICT,
+} UNumberRoundingPriority;
+#endif // U_FORCE_HIDE_DRAFT_API
+
/**
* An enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123
* meters in <em>en-CA</em>:
@@ -107,7 +164,7 @@ typedef enum UNumberUnitWidth {
*
* @stable ICU 60
*/
- UNUM_UNIT_WIDTH_NARROW,
+ UNUM_UNIT_WIDTH_NARROW = 0,
/**
* Print an abbreviated version of the unit name. Similar to NARROW, but use a slightly wider abbreviation or
@@ -123,7 +180,7 @@ typedef enum UNumberUnitWidth {
*
* @stable ICU 60
*/
- UNUM_UNIT_WIDTH_SHORT,
+ UNUM_UNIT_WIDTH_SHORT = 1,
/**
* Print the full name of the unit, without any abbreviations.
@@ -134,7 +191,7 @@ typedef enum UNumberUnitWidth {
*
* @stable ICU 60
*/
- UNUM_UNIT_WIDTH_FULL_NAME,
+ UNUM_UNIT_WIDTH_FULL_NAME = 2,
/**
* Use the three-digit ISO XXX code in place of the symbol for displaying currencies. The behavior of this
@@ -145,7 +202,29 @@ typedef enum UNumberUnitWidth {
*
* @stable ICU 60
*/
- UNUM_UNIT_WIDTH_ISO_CODE,
+ UNUM_UNIT_WIDTH_ISO_CODE = 3,
+
+ /**
+ * Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan
+ * dollar in zh-TW.
+ *
+ * <p>
+ * Behavior of this option with non-currency units is not defined at this time.
+ *
+ * @stable ICU 68
+ */
+ UNUM_UNIT_WIDTH_FORMAL = 4,
+
+ /**
+ * Use the alternate variant of the currency symbol; for example, "TL" for the Turkish
+ * lira (TRY).
+ *
+ * <p>
+ * Behavior of this option with non-currency units is not defined at this time.
+ *
+ * @stable ICU 68
+ */
+ UNUM_UNIT_WIDTH_VARIANT = 5,
/**
* Format the number according to the specified unit, but do not display the unit. For currencies, apply
@@ -154,14 +233,16 @@ typedef enum UNumberUnitWidth {
*
* @stable ICU 60
*/
- UNUM_UNIT_WIDTH_HIDDEN,
+ UNUM_UNIT_WIDTH_HIDDEN = 6,
+ // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
+ // needed for unconditionalized struct MacroProps
/**
* One more than the highest UNumberUnitWidth value.
*
* @internal ICU 60: The numeric value may change over time; see ICU ticket #12420.
*/
- UNUM_UNIT_WIDTH_COUNT
+ UNUM_UNIT_WIDTH_COUNT = 7
} UNumberUnitWidth;
/**
@@ -289,9 +370,12 @@ typedef enum UNumberSignDisplay {
* Show the minus sign on negative numbers, and do not show the sign on positive numbers. This is the default
* behavior.
*
+ * If using this option, a sign will be displayed on negative zero, including negative numbers
+ * that round to zero. To hide the sign on negative zero, use the NEGATIVE option.
+ *
* @stable ICU 60
*/
- UNUM_SIGN_AUTO,
+ UNUM_SIGN_AUTO,
/**
* Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.
@@ -299,14 +383,14 @@ typedef enum UNumberSignDisplay {
*
* @stable ICU 60
*/
- UNUM_SIGN_ALWAYS,
+ UNUM_SIGN_ALWAYS,
/**
* Do not show the sign on positive or negative numbers.
*
* @stable ICU 60
*/
- UNUM_SIGN_NEVER,
+ UNUM_SIGN_NEVER,
/**
* Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive numbers.
@@ -322,7 +406,7 @@ typedef enum UNumberSignDisplay {
*
* @stable ICU 60
*/
- UNUM_SIGN_ACCOUNTING,
+ UNUM_SIGN_ACCOUNTING,
/**
* Use the locale-dependent accounting format on negative numbers, and show the plus sign on
@@ -332,7 +416,7 @@ typedef enum UNumberSignDisplay {
*
* @stable ICU 60
*/
- UNUM_SIGN_ACCOUNTING_ALWAYS,
+ UNUM_SIGN_ACCOUNTING_ALWAYS,
/**
* Show the minus sign on negative numbers and the plus sign on positive numbers. Do not show a
@@ -340,7 +424,7 @@ typedef enum UNumberSignDisplay {
*
* @stable ICU 61
*/
- UNUM_SIGN_EXCEPT_ZERO,
+ UNUM_SIGN_EXCEPT_ZERO,
/**
* Use the locale-dependent accounting format on negative numbers, and show the plus sign on
@@ -349,14 +433,32 @@ typedef enum UNumberSignDisplay {
*
* @stable ICU 61
*/
- UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
+ UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Same as AUTO, but do not show the sign on negative zero.
+ *
+ * @draft ICU 69
+ */
+ UNUM_SIGN_NEGATIVE,
+
+ /**
+ * Same as ACCOUNTING, but do not show the sign on negative zero.
+ *
+ * @draft ICU 69
+ */
+ UNUM_SIGN_ACCOUNTING_NEGATIVE,
+#endif // U_HIDE_DRAFT_API
+ // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
+ // needed for unconditionalized struct MacroProps
/**
* One more than the highest UNumberSignDisplay value.
*
* @internal ICU 60: The numeric value may change over time; see ICU ticket #12420.
*/
- UNUM_SIGN_COUNT
+ UNUM_SIGN_COUNT = 9,
} UNumberSignDisplay;
/**
@@ -386,6 +488,8 @@ typedef enum UNumberDecimalSeparatorDisplay {
*/
UNUM_DECIMAL_SEPARATOR_ALWAYS,
+ // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
+ // needed for unconditionalized struct MacroProps
/**
* One more than the highest UNumberDecimalSeparatorDisplay value.
*
@@ -394,6 +498,32 @@ typedef enum UNumberDecimalSeparatorDisplay {
UNUM_DECIMAL_SEPARATOR_COUNT
} UNumberDecimalSeparatorDisplay;
+#ifndef U_FORCE_HIDE_DRAFT_API
+/**
+ * An enum declaring how to render trailing zeros.
+ *
+ * - UNUM_TRAILING_ZERO_AUTO: 0.90, 1.00, 1.10
+ * - UNUM_TRAILING_ZERO_HIDE_IF_WHOLE: 0.90, 1, 1.10
+ *
+ * @draft ICU 69
+ */
+typedef enum UNumberTrailingZeroDisplay {
+ /**
+ * Display trailing zeros according to the settings for minimum fraction and significant digits.
+ *
+ * @draft ICU 69
+ */
+ UNUM_TRAILING_ZERO_AUTO,
+
+ /**
+ * Same as AUTO, but hide trailing zeros after the decimal separator if they are all zero.
+ *
+ * @draft ICU 69
+ */
+ UNUM_TRAILING_ZERO_HIDE_IF_WHOLE,
+} UNumberTrailingZeroDisplay;
+#endif // U_FORCE_HIDE_DRAFT_API
+
struct UNumberFormatter;
/**
* C-compatible version of icu::number::LocalizedNumberFormatter.
@@ -424,6 +554,9 @@ typedef struct UFormattedNumber UFormattedNumber;
* For more details on skeleton strings, see the documentation in numberformatter.h. For more details on
* the usage of this API, see the documentation at the top of unumberformatter.h.
*
+ * For more information on number skeleton strings, see:
+ * https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html
+ *
* NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
*
* @param skeleton The skeleton string, like u"percent precision-integer"
@@ -432,7 +565,7 @@ typedef struct UFormattedNumber UFormattedNumber;
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE UNumberFormatter* U_EXPORT2
+U_CAPI UNumberFormatter* U_EXPORT2
unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
UErrorCode* ec);
@@ -441,6 +574,9 @@ unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const
* Like unumf_openForSkeletonAndLocale, but accepts a UParseError, which will be populated with the
* location of a skeleton syntax error if such a syntax error exists.
*
+ * For more information on number skeleton strings, see:
+ * https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html
+ *
* @param skeleton The skeleton string, like u"percent precision-integer"
* @param skeletonLen The number of UChars in the skeleton string, or -1 if it is NUL-terminated.
* @param locale The NUL-terminated locale ID.
@@ -449,7 +585,7 @@ unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const
* @param ec Set if an error occurs.
* @stable ICU 64
*/
-U_STABLE UNumberFormatter* U_EXPORT2
+U_CAPI UNumberFormatter* U_EXPORT2
unumf_openForSkeletonAndLocaleWithError(
const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
@@ -462,7 +598,7 @@ unumf_openForSkeletonAndLocaleWithError(
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE UFormattedNumber* U_EXPORT2
+U_CAPI UFormattedNumber* U_EXPORT2
unumf_openResult(UErrorCode* ec);
@@ -481,7 +617,7 @@ unumf_openResult(UErrorCode* ec);
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
UErrorCode* ec);
@@ -501,7 +637,7 @@ unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNum
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
UErrorCode* ec);
@@ -525,7 +661,7 @@ unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedN
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
UFormattedNumber* uresult, UErrorCode* ec);
@@ -543,7 +679,7 @@ unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32
* @return A UFormattedValue owned by the input object.
* @stable ICU 64
*/
-U_STABLE const UFormattedValue* U_EXPORT2
+U_CAPI const UFormattedValue* U_EXPORT2
unumf_resultAsValue(const UFormattedNumber* uresult, UErrorCode* ec);
@@ -566,7 +702,7 @@ unumf_resultAsValue(const UFormattedNumber* uresult, UErrorCode* ec);
* @return The required length.
* @stable ICU 62
*/
-U_STABLE int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
UErrorCode* ec);
@@ -600,11 +736,11 @@ unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t buf
* "beginIndex" field is set to the beginning of the first occurrence of the field after the
* input "endIndex", and "endIndex" is set to the end of that occurrence of the field
* (exclusive index). If a field position is not found, the FieldPosition is not changed and
- * the method returns FALSE.
+ * the method returns false.
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec);
@@ -629,16 +765,35 @@ unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* u
* @param ec Set if an error occurs.
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
UErrorCode* ec);
-// TODO(ICU-20775): Propose this as API.
-// NOTE: This is not currently implemented.
-// U_DRAFT int32_t U_EXPORT2
-// unumf_resultToDecimalNumber(const UFormattedNumber* uresult, char* buffer, int32_t bufferCapacity,
-// UErrorCode* ec);
+/**
+ * Extracts the formatted number as a "numeric string" conforming to the
+ * syntax defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * This endpoint is useful for obtaining the exact number being printed
+ * after scaling and rounding have been applied by the number formatter.
+ *
+ * @param uresult The input object containing the formatted number.
+ * @param dest the 8-bit char buffer into which the decimal number is placed
+ * @param destCapacity The size, in chars, of the destination buffer. May be zero
+ * for precomputing the required size.
+ * @param ec receives any error status.
+ * If U_BUFFER_OVERFLOW_ERROR: Returns number of chars for
+ * preflighting.
+ * @return Number of chars in the data. Does not include a trailing NUL.
+ * @stable ICU 68
+ */
+U_CAPI int32_t U_EXPORT2
+unumf_resultToDecimalNumber(
+ const UFormattedNumber* uresult,
+ char* dest,
+ int32_t destCapacity,
+ UErrorCode* ec);
/**
@@ -647,7 +802,7 @@ unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPosition
* @param uformatter An object created by unumf_openForSkeletonAndLocale().
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_close(UNumberFormatter* uformatter);
@@ -657,7 +812,7 @@ unumf_close(UNumberFormatter* uformatter);
* @param uresult An object created by unumf_openResult().
* @stable ICU 62
*/
-U_STABLE void U_EXPORT2
+U_CAPI void U_EXPORT2
unumf_closeResult(UFormattedNumber* uresult);
@@ -701,5 +856,5 @@ U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unum
U_NAMESPACE_END
#endif // U_SHOW_CPLUSPLUS_API
-#endif //__UNUMBERFORMATTER_H__
#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif //__UNUMBERFORMATTER_H__