diff options
Diffstat (limited to 'Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h')
-rw-r--r-- | Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h | 95 |
1 files changed, 73 insertions, 22 deletions
diff --git a/Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h b/Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h index ece433b55f0..711064ece8d 100644 --- a/Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h +++ b/Build/source/libs/icu/icu-src/source/i18n/unicode/numberformatter.h @@ -22,6 +22,7 @@ #include "unicode/parseerr.h" #include "unicode/plurrule.h" #include "unicode/ucurr.h" +#include "unicode/unounclass.h" #include "unicode/unum.h" #include "unicode/unumberformatter.h" #include "unicode/uobject.h" @@ -640,6 +641,33 @@ class U_I18N_API Precision : public UMemory { */ static IncrementPrecision increment(double roundingIncrement); +#ifndef U_HIDE_DRAFT_API + /** + * Version of `Precision::increment()` that takes an integer at a particular power of 10. + * + * To round to the nearest 0.5 and display 2 fraction digits, with this function, you should write one of the following: + * + * <pre> + * Precision::incrementExact(5, -1).withMinFraction(2) + * Precision::incrementExact(50, -2).withMinFraction(2) + * Precision::incrementExact(50, -2) + * </pre> + * + * This is analagous to ICU4J `Precision.increment(new BigDecimal("0.50"))`. + * + * This behavior is modeled after ECMA-402. For more information, see: + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingincrement + * + * @param mantissa + * The increment to which to round numbers. + * @param magnitude + * The power of 10 of the ones digit of the mantissa. + * @return A precision for chaining or passing to the NumberFormatter precision() setter. + * @draft ICU 71 + */ + static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude); +#endif // U_HIDE_DRAFT_API + /** * Show numbers rounded and padded according to the rules for the currency unit. The most common * rounding precision settings for currencies include <code>Precision::fixedFraction(2)</code>, @@ -659,16 +687,14 @@ class U_I18N_API Precision : public UMemory { */ static CurrencyPrecision currency(UCurrencyUsage currencyUsage); -#ifndef U_HIDE_DRAFT_API /** * Configure how trailing zeros are displayed on numbers. For example, to hide trailing zeros * when the number is an integer, use UNUM_TRAILING_ZERO_HIDE_IF_WHOLE. * * @param trailingZeroDisplay Option to configure the display of trailing zeros. - * @draft ICU 69 + * @stable ICU 69 */ Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const; -#endif // U_HIDE_DRAFT_API private: enum PrecisionType { @@ -707,16 +733,23 @@ class U_I18N_API Precision : public UMemory { impl::digits_t fMaxSig; /** @internal (private) */ UNumberRoundingPriority fPriority; + /** + * Whether to retain trailing zeros based on the looser strategy. + * @internal (private) + */ + bool fRetain; } fracSig; /** @internal (private) */ struct IncrementSettings { // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE + // Note: This is a union, so we shouldn't own memory, since + // the default destructor would leak it. /** @internal (private) */ - double fIncrement; + uint64_t fIncrement; /** @internal (private) */ - impl::digits_t fMinFrac; + impl::digits_t fIncrementMagnitude; /** @internal (private) */ - impl::digits_t fMaxFrac; + impl::digits_t fMinFrac; } increment; UCurrencyUsage currencyUsage; // For RND_CURRENCY UErrorCode errorCode; // For RND_ERROR @@ -759,9 +792,10 @@ class U_I18N_API Precision : public UMemory { const FractionPrecision &base, int32_t minSig, int32_t maxSig, - UNumberRoundingPriority priority); + UNumberRoundingPriority priority, + bool retain); - static IncrementPrecision constructIncrement(double increment, int32_t minFrac); + static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude); static CurrencyPrecision constructCurrency(UCurrencyUsage usage); @@ -801,7 +835,6 @@ class U_I18N_API Precision : public UMemory { */ class U_I18N_API FractionPrecision : public Precision { public: -#ifndef U_HIDE_DRAFT_API /** * Override maximum fraction digits with maximum significant digits depending on the magnitude * of the number. See UNumberRoundingPriority. @@ -814,13 +847,12 @@ class U_I18N_API FractionPrecision : public Precision { * How to disambiguate between fraction digits and significant digits. * @return A precision for chaining or passing to the NumberFormatter precision() setter. * - * @draft ICU 69 + * @stable ICU 69 */ Precision withSignificantDigits( int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const; -#endif // U_HIDE_DRAFT_API /** * Ensure that no less than this number of significant digits are retained when rounding @@ -1170,22 +1202,26 @@ class U_I18N_API Scale : public UMemory { namespace impl { -// Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field +// Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field. +// And do not enclose its class boilerplate within #ifndef U_HIDE_INTERNAL_API. /** * Manages NumberFormatterSettings::usage()'s char* instance on the heap. * @internal */ class U_I18N_API StringProp : public UMemory { -#ifndef U_HIDE_INTERNAL_API - public: /** @internal */ + ~StringProp(); + + /** @internal */ StringProp(const StringProp &other); /** @internal */ StringProp &operator=(const StringProp &other); +#ifndef U_HIDE_INTERNAL_API + /** @internal */ StringProp(StringProp &&src) U_NOEXCEPT; @@ -1193,9 +1229,6 @@ class U_I18N_API StringProp : public UMemory { StringProp &operator=(StringProp &&src) U_NOEXCEPT; /** @internal */ - ~StringProp(); - - /** @internal */ int16_t length() const { return fLength; } @@ -2735,14 +2768,20 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { */ MeasureUnit getOutputUnit(UErrorCode& status) const; -#ifndef U_HIDE_INTERNAL_API +#ifndef U_HIDE_DRAFT_API + /** - * Gets the gender of the formatted output. Returns "" when the gender is - * unknown, or for ungendered languages. + * Gets the noun class of the formatted output. Returns `OTHER` when the noun class + * is not supported yet. * - * @internal ICU 69 technology preview. + * @return `NounClass` + * @draft ICU 71. */ - const char *getGender(UErrorCode& status) const; + NounClass getNounClass(UErrorCode &status) const; + +#endif // U_HIDE_DRAFT_API + +#ifndef U_HIDE_INTERNAL_API /** * Gets the raw DecimalQuantity for plural rule selection. @@ -2758,6 +2797,18 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { #endif /* U_HIDE_INTERNAL_API */ +#ifndef U_HIDE_DEPRECATED_API + + /** + * Gets the gender of the formatted output. Returns "" when the gender is + * unknown, or for ungendered languages. + * + * @deprecated This API is for ICU internal use only. + */ + const char *getGender(UErrorCode &status) const; + +#endif /* U_HIDE_DEPRECATED_API */ + private: // Can't use LocalPointer because UFormattedNumberData is forward-declared const impl::UFormattedNumberData *fData; |