jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************** jpayne@69: * Copyright (C) 2012-2016, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ******************************************************************************** jpayne@69: * jpayne@69: * File COMPACTDECIMALFORMAT.H jpayne@69: ******************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef __COMPACT_DECIMAL_FORMAT_H__ jpayne@69: #define __COMPACT_DECIMAL_FORMAT_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Compatibility APIs for compact decimal number formatting. jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/decimfmt.h" jpayne@69: jpayne@69: struct UHashtable; jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class PluralRules; jpayne@69: jpayne@69: /** jpayne@69: * **IMPORTANT:** New users are strongly encouraged to see if jpayne@69: * numberformatter.h fits their use case. Although not deprecated, this header jpayne@69: * is provided for backwards compatibility only. jpayne@69: * jpayne@69: * ----------------------------------------------------------------------------- jpayne@69: * jpayne@69: * The CompactDecimalFormat produces abbreviated numbers, suitable for display in jpayne@69: * environments will limited real estate. For example, 'Hits: 1.2B' instead of jpayne@69: * 'Hits: 1,200,000,000'. The format will be appropriate for the given language, jpayne@69: * such as "1,2 Mrd." for German. jpayne@69: * jpayne@69: * For numbers under 1000 trillion (under 10^15, such as 123,456,789,012,345), jpayne@69: * the result will be short for supported languages. However, the result may jpayne@69: * sometimes exceed 7 characters, such as when there are combining marks or thin jpayne@69: * characters. In such cases, the visual width in fonts should still be short. jpayne@69: * jpayne@69: * By default, there are 3 significant digits. After creation, if more than jpayne@69: * three significant digits are set (with setMaximumSignificantDigits), or if a jpayne@69: * fixed number of digits are set (with setMaximumIntegerDigits or jpayne@69: * setMaximumFractionDigits), then result may be wider. jpayne@69: * jpayne@69: * At this time, parsing is not supported, and will produce a U_UNSUPPORTED_ERROR. jpayne@69: * Resetting the pattern prefixes or suffixes is not supported; the method calls jpayne@69: * are ignored. jpayne@69: * jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: class U_I18N_API CompactDecimalFormat : public DecimalFormat { jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * Returns a compact decimal instance for specified locale. jpayne@69: * jpayne@69: * **NOTE:** New users are strongly encouraged to use jpayne@69: * `number::NumberFormatter` instead of NumberFormat. jpayne@69: * @param inLocale the given locale. jpayne@69: * @param style whether to use short or long style. jpayne@69: * @param status error code returned here. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: static CompactDecimalFormat* U_EXPORT2 createInstance( jpayne@69: const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * jpayne@69: * @param source the DecimalFormat object to be copied from. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: CompactDecimalFormat(const CompactDecimalFormat& source); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: ~CompactDecimalFormat() U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * jpayne@69: * @param rhs the DecimalFormat object to be copied. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: CompactDecimalFormat& operator=(const CompactDecimalFormat& rhs); jpayne@69: jpayne@69: /** jpayne@69: * Clone this Format object polymorphically. The caller owns the jpayne@69: * result and should delete it when done. jpayne@69: * jpayne@69: * @return a polymorphic copy of this CompactDecimalFormat. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: CompactDecimalFormat* clone() const U_OVERRIDE; jpayne@69: jpayne@69: using DecimalFormat::format; jpayne@69: jpayne@69: /** jpayne@69: * CompactDecimalFormat does not support parsing. This implementation jpayne@69: * does nothing. jpayne@69: * @param text Unused. jpayne@69: * @param result Does not change. jpayne@69: * @param parsePosition Does not change. jpayne@69: * @see Formattable jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: void parse(const UnicodeString& text, Formattable& result, jpayne@69: ParsePosition& parsePosition) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * CompactDecimalFormat does not support parsing. This implementation jpayne@69: * sets status to U_UNSUPPORTED_ERROR jpayne@69: * jpayne@69: * @param text Unused. jpayne@69: * @param result Does not change. jpayne@69: * @param status Always set to U_UNSUPPORTED_ERROR. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: void parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Parses text from the given string as a currency amount. Unlike jpayne@69: * the parse() method, this method will attempt to parse a generic jpayne@69: * currency name, searching for a match of this object's locale's jpayne@69: * currency display names, or for a 3-letter ISO currency code. jpayne@69: * This method will fail if this format is not a currency format, jpayne@69: * that is, if it does not contain the currency pattern symbol jpayne@69: * (U+00A4) in its prefix or suffix. This implementation always returns jpayne@69: * NULL. jpayne@69: * jpayne@69: * @param text the string to parse jpayne@69: * @param pos input-output position; on input, the position within text jpayne@69: * to match; must have 0 <= pos.getIndex() < text.length(); jpayne@69: * on output, the position after the last matched character. jpayne@69: * If the parse fails, the position in unchanged upon output. jpayne@69: * @return if parse succeeds, a pointer to a newly-created CurrencyAmount jpayne@69: * object (owned by the caller) containing information about jpayne@69: * the parsed currency; if parse fails, this is NULL. jpayne@69: * @internal jpayne@69: */ jpayne@69: CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for jpayne@69: * comparing to a return value from getDynamicClassID(). For example: jpayne@69: *
jpayne@69: * . Base* polymorphic_pointer = createPolymorphicObject(); jpayne@69: * . if (polymorphic_pointer->getDynamicClassID() == jpayne@69: * . Derived::getStaticClassID()) ... jpayne@69: *jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. jpayne@69: * This method is to implement a simple version of RTTI, since not all jpayne@69: * C++ compilers support genuine RTTI. Polymorphic operator==() and jpayne@69: * clone() methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: UClassID getDynamicClassID() const U_OVERRIDE; jpayne@69: jpayne@69: private: jpayne@69: CompactDecimalFormat(const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status); jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // __COMPACT_DECIMAL_FORMAT_H__ jpayne@69: //eof