]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/dcfmtsym.h
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / dcfmtsym.h
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File DCFMTSYM.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 03/18/97 clhuang Updated per C++ implementation.
14 * 03/27/97 helena Updated to pass the simple test after code review.
15 * 08/26/97 aliu Added currency/intl currency symbol support.
16 * 07/22/98 stephen Changed to match C++ style
17 * currencySymbol -> fCurrencySymbol
18 * Constants changed from CAPS to kCaps
19 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
20 * 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
21 * functions.
22 ********************************************************************************
23 */
24
25 #ifndef DCFMTSYM_H
26 #define DCFMTSYM_H
27
28 #include "unicode/utypes.h"
29
30 #if !UCONFIG_NO_FORMATTING
31
32 #include "unicode/uobject.h"
33 #include "unicode/locid.h"
34
35 U_NAMESPACE_BEGIN
36
37 /**
38 * This class represents the set of symbols needed by DecimalFormat
39 * to format numbers. DecimalFormat creates for itself an instance of
40 * DecimalFormatSymbols from its locale data. If you need to change any
41 * of these symbols, you can get the DecimalFormatSymbols object from
42 * your DecimalFormat and modify it.
43 * <P>
44 * Here are the special characters used in the parts of the
45 * subpattern, with notes on their usage.
46 * <pre>
47 * \code
48 * Symbol Meaning
49 * 0 a digit
50 * # a digit, zero shows as absent
51 * . placeholder for decimal separator
52 * , placeholder for grouping separator.
53 * ; separates formats.
54 * - default negative prefix.
55 * % divide by 100 and show as percentage
56 * X any other characters can be used in the prefix or suffix
57 * ' used to quote special characters in a prefix or suffix.
58 * \endcode
59 * </pre>
60 * [Notes]
61 * <P>
62 * If there is no explicit negative subpattern, - is prefixed to the
63 * positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
64 * <P>
65 * The grouping separator is commonly used for thousands, but in some
66 * countries for ten-thousands. The interval is a constant number of
67 * digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
68 * If you supply a pattern with multiple grouping characters, the interval
69 * between the last one and the end of the integer is the one that is
70 * used. So "#,##,###,####" == "######,####" == "##,####,####".
71 * <P>
72 * This class only handles localized digits where the 10 digits are
73 * contiguous in Unicode, from 0 to 9. Other digits sets (such as
74 * superscripts) would need a different subclass.
75 */
76 class U_I18N_API DecimalFormatSymbols : public UObject {
77 public:
78 /**
79 * Constants for specifying a number format symbol.
80 * @stable ICU 2.0
81 */
82 enum ENumberFormatSymbol {
83 /** The decimal separator */
84 kDecimalSeparatorSymbol,
85 /** The grouping separator */
86 kGroupingSeparatorSymbol,
87 /** The pattern separator */
88 kPatternSeparatorSymbol,
89 /** The percent sign */
90 kPercentSymbol,
91 /** Zero*/
92 kZeroDigitSymbol,
93 /** Character representing a digit in the pattern */
94 kDigitSymbol,
95 /** The minus sign */
96 kMinusSignSymbol,
97 /** The plus sign */
98 kPlusSignSymbol,
99 /** The currency symbol */
100 kCurrencySymbol,
101 /** The international currency symbol */
102 kIntlCurrencySymbol,
103 /** The monetary separator */
104 kMonetarySeparatorSymbol,
105 /** The exponential symbol */
106 kExponentialSymbol,
107 /** Per mill symbol - replaces kPermillSymbol */
108 kPerMillSymbol,
109 /** Escape padding character */
110 kPadEscapeSymbol,
111 /** Infinity symbol */
112 kInfinitySymbol,
113 /** Nan symbol */
114 kNaNSymbol,
115 /** Significant digit symbol
116 * @draft ICU 3.0 */
117 kSignificantDigitSymbol,
118 /** count symbol constants */
119 kFormatSymbolCount
120 };
121
122 /**
123 * Create a DecimalFormatSymbols object for the given locale.
124 *
125 * @param locale The locale to get symbols for.
126 * @param status Input/output parameter, set to success or
127 * failure code upon return.
128 * @stable ICU 2.0
129 */
130 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
131
132 /**
133 * Create a DecimalFormatSymbols object for the default locale.
134 * This constructor will not fail. If the resource file data is
135 * not available, it will use hard-coded last-resort data and
136 * set status to U_USING_FALLBACK_ERROR.
137 *
138 * @param status Input/output parameter, set to success or
139 * failure code upon return.
140 * @stable ICU 2.0
141 */
142 DecimalFormatSymbols( UErrorCode& status);
143
144 /**
145 * Copy constructor.
146 * @stable ICU 2.0
147 */
148 DecimalFormatSymbols(const DecimalFormatSymbols&);
149
150 /**
151 * Assignment operator.
152 * @stable ICU 2.0
153 */
154 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
155
156 /**
157 * Destructor.
158 * @stable ICU 2.0
159 */
160 virtual ~DecimalFormatSymbols();
161
162 /**
163 * Return true if another object is semantically equal to this one.
164 *
165 * @param other the object to be compared with.
166 * @return true if another object is semantically equal to this one.
167 * @stable ICU 2.0
168 */
169 UBool operator==(const DecimalFormatSymbols& other) const;
170
171 /**
172 * Return true if another object is semantically unequal to this one.
173 *
174 * @param other the object to be compared with.
175 * @return true if another object is semantically unequal to this one.
176 * @stable ICU 2.0
177 */
178 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
179
180 /**
181 * Get one of the format symbols by its enum constant.
182 * Each symbol is stored as a string so that graphemes
183 * (characters with modifyer letters) can be used.
184 *
185 * @param symbol Constant to indicate a number format symbol.
186 * @return the format symbols by the param 'symbol'
187 * @stable ICU 2.0
188 */
189 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
190
191 /**
192 * Set one of the format symbols by its enum constant.
193 * Each symbol is stored as a string so that graphemes
194 * (characters with modifyer letters) can be used.
195 *
196 * @param symbol Constant to indicate a number format symbol.
197 * @param value value of the format sybmol
198 * @stable ICU 2.0
199 */
200 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value);
201
202 /**
203 * Returns the locale for which this object was constructed.
204 * @stable ICU 2.6
205 */
206 inline Locale getLocale() const;
207
208 /**
209 * Returns the locale for this object. Two flavors are available:
210 * valid and actual locale.
211 * @draft ICU 2.8 likely to change in ICU 3.0, based on feedback
212 */
213 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
214
215 /**
216 * ICU "poor man's RTTI", returns a UClassID for the actual class.
217 *
218 * @stable ICU 2.2
219 */
220 virtual UClassID getDynamicClassID() const;
221
222 /**
223 * ICU "poor man's RTTI", returns a UClassID for this class.
224 *
225 * @stable ICU 2.2
226 */
227 static UClassID U_EXPORT2 getStaticClassID();
228
229 private:
230 DecimalFormatSymbols(); // default constructor not implemented
231
232 /**
233 * Initializes the symbols from the LocaleElements resource bundle.
234 * Note: The organization of LocaleElements badly needs to be
235 * cleaned up.
236 *
237 * @param locale The locale to get symbols for.
238 * @param success Input/output parameter, set to success or
239 * failure code upon return.
240 * @param useLastResortData determine if use last resort data
241 */
242 void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
243
244 /**
245 * Initialize the symbols from the given array of UnicodeStrings.
246 * The array must be of the correct size.
247 *
248 * @param numberElements the number format symbols
249 * @param numberElementsLength length of numberElements
250 */
251 void initialize(const UChar** numberElements, int32_t *numberElementsStrLen, int32_t numberElementsLength);
252
253 /**
254 * Initialize the symbols with default values.
255 */
256 void initialize();
257
258 void setCurrencyForSymbols();
259
260 public:
261 /**
262 * _Internal_ function - more efficient version of getSymbol,
263 * returning a const reference to one of the symbol strings.
264 * The returned reference becomes invalid when the symbol is changed
265 * or when the DecimalFormatSymbols are destroyed.
266 * ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
267 *
268 * @param symbol Constant to indicate a number format symbol.
269 * @return the format symbol by the param 'symbol'
270 * @internal
271 */
272 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
273
274 private:
275 /**
276 * Private symbol strings.
277 * They are either loaded from a resource bundle or otherwise owned.
278 * setSymbol() clones the symbol string.
279 * Readonly aliases can only come from a resource bundle, so that we can always
280 * use fastCopyFrom() with them.
281 *
282 * If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
283 * from private to protected,
284 * or when fSymbols can be set any other way that allows them to be readonly aliases
285 * to non-resource bundle strings,
286 * then regular UnicodeString copies must be used instead of fastCopyFrom().
287 *
288 * @internal
289 */
290 UnicodeString fSymbols[kFormatSymbolCount];
291
292 /**
293 * Non-symbol variable for getConstSymbol(). Always empty.
294 * @internal
295 */
296 UnicodeString fNoSymbol;
297
298 Locale locale;
299
300 char actualLocale[ULOC_FULLNAME_CAPACITY];
301 char validLocale[ULOC_FULLNAME_CAPACITY];
302 };
303
304 // -------------------------------------
305
306 inline UnicodeString
307 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
308 const UnicodeString *strPtr;
309 if(symbol < kFormatSymbolCount) {
310 strPtr = &fSymbols[symbol];
311 } else {
312 strPtr = &fNoSymbol;
313 }
314 return *strPtr;
315 }
316
317 inline const UnicodeString &
318 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
319 const UnicodeString *strPtr;
320 if(symbol < kFormatSymbolCount) {
321 strPtr = &fSymbols[symbol];
322 } else {
323 strPtr = &fNoSymbol;
324 }
325 return *strPtr;
326 }
327
328 // -------------------------------------
329
330 inline void
331 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value) {
332 if(symbol<kFormatSymbolCount) {
333 fSymbols[symbol]=value;
334 }
335 }
336
337 // -------------------------------------
338
339 inline Locale
340 DecimalFormatSymbols::getLocale() const {
341 return locale;
342 }
343
344
345 U_NAMESPACE_END
346
347 #endif /* #if !UCONFIG_NO_FORMATTING */
348
349 #endif // _DCFMTSYM
350 //eof