• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 *   Copyright (C) 2012-2016, International Business Machines
6 *   Corporation and others.  All Rights Reserved.
7 ********************************************************************************
8 *
9 * File COMPACTDECIMALFORMAT.H
10 ********************************************************************************
11 */
12 
13 #ifndef __COMPACT_DECIMAL_FORMAT_H__
14 #define __COMPACT_DECIMAL_FORMAT_H__
15 
16 #include "unicode/utypes.h"
17 /**
18  * \file
19  * \brief C++ API: Compatibility APIs for compact decimal number formatting.
20  */
21 
22 #if !UCONFIG_NO_FORMATTING
23 
24 #include "unicode/decimfmt.h"
25 
26 struct UHashtable;
27 
28 U_NAMESPACE_BEGIN
29 
30 class PluralRules;
31 
32 /**
33  * **IMPORTANT:** New users are strongly encouraged to see if
34  * numberformatter.h fits their use case.  Although not deprecated, this header
35  * is provided for backwards compatibility only.
36  *
37  * -----------------------------------------------------------------------------
38  *
39  * The CompactDecimalFormat produces abbreviated numbers, suitable for display in
40  * environments will limited real estate. For example, 'Hits: 1.2B' instead of
41  * 'Hits: 1,200,000,000'. The format will be appropriate for the given language,
42  * such as "1,2 Mrd." for German.
43  *
44  * For numbers under 1000 trillion (under 10^15, such as 123,456,789,012,345),
45  * the result will be short for supported languages. However, the result may
46  * sometimes exceed 7 characters, such as when there are combining marks or thin
47  * characters. In such cases, the visual width in fonts should still be short.
48  *
49  * By default, there are 3 significant digits. After creation, if more than
50  * three significant digits are set (with setMaximumSignificantDigits), or if a
51  * fixed number of digits are set (with setMaximumIntegerDigits or
52  * setMaximumFractionDigits), then result may be wider.
53  *
54  * At this time, parsing is not supported, and will produce a U_UNSUPPORTED_ERROR.
55  * Resetting the pattern prefixes or suffixes is not supported; the method calls
56  * are ignored.
57  *
58  * @stable ICU 51
59  */
60 class U_I18N_API CompactDecimalFormat : public DecimalFormat {
61 public:
62 
63      /**
64       * Returns a compact decimal instance for specified locale.
65       *
66       * **NOTE:** New users are strongly encouraged to use
67       * `number::NumberFormatter` instead of NumberFormat.
68       * @param inLocale the given locale.
69       * @param style whether to use short or long style.
70       * @param status error code returned  here.
71       * @stable ICU 51
72       */
73      static CompactDecimalFormat* U_EXPORT2 createInstance(
74           const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status);
75 
76     /**
77      * Copy constructor.
78      *
79      * @param source    the DecimalFormat object to be copied from.
80      * @stable ICU 51
81       */
82     CompactDecimalFormat(const CompactDecimalFormat& source);
83 
84     /**
85      * Destructor.
86      * @stable ICU 51
87      */
88     ~CompactDecimalFormat() U_OVERRIDE;
89 
90     /**
91      * Assignment operator.
92      *
93      * @param rhs    the DecimalFormat object to be copied.
94      * @stable ICU 51
95      */
96     CompactDecimalFormat& operator=(const CompactDecimalFormat& rhs);
97 
98     /**
99      * Clone this Format object polymorphically. The caller owns the
100      * result and should delete it when done.
101      *
102      * @return    a polymorphic copy of this CompactDecimalFormat.
103      * @stable ICU 51
104      */
105     Format* clone() const U_OVERRIDE;
106 
107     using DecimalFormat::format;
108 
109     /**
110      * CompactDecimalFormat does not support parsing. This implementation
111      * does nothing.
112      * @param text           Unused.
113      * @param result         Does not change.
114      * @param parsePosition  Does not change.
115      * @see Formattable
116      * @stable ICU 51
117      */
118     void parse(const UnicodeString& text, Formattable& result,
119                ParsePosition& parsePosition) const U_OVERRIDE;
120 
121     /**
122      * CompactDecimalFormat does not support parsing. This implementation
123      * sets status to U_UNSUPPORTED_ERROR
124      *
125      * @param text      Unused.
126      * @param result    Does not change.
127      * @param status    Always set to U_UNSUPPORTED_ERROR.
128      * @stable ICU 51
129      */
130     void parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const U_OVERRIDE;
131 
132 #ifndef U_HIDE_INTERNAL_API
133     /**
134      * Parses text from the given string as a currency amount.  Unlike
135      * the parse() method, this method will attempt to parse a generic
136      * currency name, searching for a match of this object's locale's
137      * currency display names, or for a 3-letter ISO currency code.
138      * This method will fail if this format is not a currency format,
139      * that is, if it does not contain the currency pattern symbol
140      * (U+00A4) in its prefix or suffix. This implementation always returns
141      * NULL.
142      *
143      * @param text the string to parse
144      * @param pos  input-output position; on input, the position within text
145      *             to match; must have 0 <= pos.getIndex() < text.length();
146      *             on output, the position after the last matched character.
147      *             If the parse fails, the position in unchanged upon output.
148      * @return     if parse succeeds, a pointer to a newly-created CurrencyAmount
149      *             object (owned by the caller) containing information about
150      *             the parsed currency; if parse fails, this is NULL.
151      * @internal
152      */
153     CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE;
154 #endif  /* U_HIDE_INTERNAL_API */
155 
156     /**
157      * Return the class ID for this class.  This is useful only for
158      * comparing to a return value from getDynamicClassID().  For example:
159      * <pre>
160      * .      Base* polymorphic_pointer = createPolymorphicObject();
161      * .      if (polymorphic_pointer->getDynamicClassID() ==
162      * .          Derived::getStaticClassID()) ...
163      * </pre>
164      * @return          The class ID for all objects of this class.
165      * @stable ICU 51
166      */
167     static UClassID U_EXPORT2 getStaticClassID();
168 
169     /**
170      * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
171      * This method is to implement a simple version of RTTI, since not all
172      * C++ compilers support genuine RTTI.  Polymorphic operator==() and
173      * clone() methods call this method.
174      *
175      * @return          The class ID for this object. All objects of a
176      *                  given class have the same class ID.  Objects of
177      *                  other classes have different class IDs.
178      * @stable ICU 51
179      */
180     UClassID getDynamicClassID() const U_OVERRIDE;
181 
182   private:
183     CompactDecimalFormat(const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status);
184 };
185 
186 U_NAMESPACE_END
187 
188 #endif /* #if !UCONFIG_NO_FORMATTING */
189 
190 #endif // __COMPACT_DECIMAL_FORMAT_H__
191 //eof
192