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