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