/** * \file * \brief C++ API: Simple number formatting focused on low memory and code size. * * These functions render locale-aware number strings but without the bells and whistles found in * other number formatting APIs such as those in numberformatter.h, like units and currencies. * * <pre> * SimpleNumberFormatter snf = SimpleNumberFormatter::forLocale("de-CH", status); * FormattedNumber result = snf.formatInt64(-1000007, status); * assertEquals("", u"-1’000’007", result.toString(status)); * </pre>
*/
U_NAMESPACE_BEGIN
/* forward declaration */ class SimpleDateFormat;
namespace number { // icu::number
namespace impl { class UFormattedNumberData; struct SimpleMicroProps; class AdoptingSignumModifierStore;
} // icu::number::impl
/** * An input type for SimpleNumberFormatter. * * This class is mutable and not intended for public subclassing. This class is movable but not copyable. * * @stable ICU 73
*/ class U_I18N_API SimpleNumber : public UMemory { public: /** * Creates a SimpleNumber for an integer. * * @stable ICU 73
*/ static SimpleNumber forInt64(int64_t value, UErrorCode& status);
/** * Changes the value of the SimpleNumber by a power of 10. * * This function immediately mutates the inner value. * * @stable ICU 73
*/ void multiplyByPowerOfTen(int32_t power, UErrorCode& status);
/** * Rounds the value currently stored in the SimpleNumber to the given power of 10, * which can be before or after the decimal separator. * * This function does not change minimum integer digits. * * @stable ICU 73
*/ void roundTo(int32_t power, UNumberFormatRoundingMode roundingMode, UErrorCode& status);
#ifndef U_HIDE_DRAFT_API /** * Sets the number of integer digits to the given amount, truncating if necessary. * * @draft ICU 75
*/ void setMaximumIntegerDigits(uint32_t maximumIntegerDigits, UErrorCode& status); #endif// U_HIDE_DRAFT_API
/** * Pads the beginning of the number with zeros up to the given minimum number of integer digits. * * @stable ICU 73
*/ void setMinimumIntegerDigits(uint32_t minimumIntegerDigits, UErrorCode& status);
/** * Pads the end of the number with zeros up to the given minimum number of fraction digits. * * @stable ICU 73
*/ void setMinimumFractionDigits(uint32_t minimumFractionDigits, UErrorCode& status);
/** * Sets the sign of the number: an explicit plus sign, explicit minus sign, or no sign. * * This setting is applied upon formatting the number. * * NOTE: This does not support accounting sign notation. * * @stable ICU 73
*/ void setSign(USimpleNumberSign sign, UErrorCode& status);
/** * Creates a new, empty SimpleNumber that does not contain a value. * * NOTE: This number will fail to format; use forInt64() to create a SimpleNumber with a value. * * @stable ICU 73
*/
SimpleNumber() = default;
/** * Destruct this SimpleNumber, cleaning up any memory it might own. * * @stable ICU 73
*/
~SimpleNumber() {
cleanup();
}
// Uses the private constructor to avoid a heap allocation friendclass icu::SimpleDateFormat;
};
/** * A special NumberFormatter focused on smaller binary size and memory use. * * SimpleNumberFormatter is capable of basic number formatting, including grouping separators, * sign display, and rounding. It is not capable of currencies, compact notation, or units. * * This class is immutable and not intended for public subclassing. This class is movable but not copyable. * * @stable ICU 73
*/ class U_I18N_API SimpleNumberFormatter : public UMemory { public: /** * Creates a new SimpleNumberFormatter with all locale defaults. * * @stable ICU 73
*/ static SimpleNumberFormatter forLocale( const icu::Locale &locale,
UErrorCode &status);
/** * Creates a new SimpleNumberFormatter, overriding the grouping strategy. * * @stable ICU 73
*/ static SimpleNumberFormatter forLocaleAndGroupingStrategy( const icu::Locale &locale,
UNumberGroupingStrategy groupingStrategy,
UErrorCode &status);
/** * Creates a new SimpleNumberFormatter, overriding the grouping strategy and symbols. * * IMPORTANT: For efficiency, this function borrows the symbols. The symbols MUST remain valid * for the lifetime of the SimpleNumberFormatter. * * @stable ICU 73
*/ static SimpleNumberFormatter forLocaleAndSymbolsAndGroupingStrategy( const icu::Locale &locale, const DecimalFormatSymbols &symbols,
UNumberGroupingStrategy groupingStrategy,
UErrorCode &status);
/** * Formats a value using this SimpleNumberFormatter. * * The SimpleNumber argument is "consumed". A new SimpleNumber object should be created for * every formatting operation. * * @stable ICU 73
*/
FormattedNumber format(SimpleNumber value, UErrorCode &status) const;
/** * Formats an integer using this SimpleNumberFormatter. * * For more control over the formatting, use SimpleNumber. * * @stable ICU 73
*/
FormattedNumber formatInt64(int64_t value, UErrorCode &status) const { return format(SimpleNumber::forInt64(value, status), status);
}
#ifndef U_HIDE_INTERNAL_API /** * Run the formatter with the internal types. * @internal
*/ void formatImpl(impl::UFormattedNumberData* data, USimpleNumberSign sign, UErrorCode& status) const; #endif// U_HIDE_INTERNAL_API
/** * Destruct this SimpleNumberFormatter, cleaning up any memory it might own. * * @stable ICU 73
*/
~SimpleNumberFormatter() {
cleanup();
}
/** * Creates a shell, initialized but non-functional SimpleNumberFormatter. * * @stable ICU 73
*/
SimpleNumberFormatter() = default;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.