2 ********************************************************************************
3 * Copyright (C) 1997-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
9 * Modification History:
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
22 ********************************************************************************
28 #include "unicode/utypes.h"
30 #if !UCONFIG_NO_FORMATTING
32 #include "unicode/uobject.h"
33 #include "unicode/locid.h"
37 * \brief C++ API: Symbols for formatting numbers.
44 * This class represents the set of symbols needed by DecimalFormat
45 * to format numbers. DecimalFormat creates for itself an instance of
46 * DecimalFormatSymbols from its locale data. If you need to change any
47 * of these symbols, you can get the DecimalFormatSymbols object from
48 * your DecimalFormat and modify it.
50 * Here are the special characters used in the parts of the
51 * subpattern, with notes on their usage.
56 * # a digit, zero shows as absent
57 * . placeholder for decimal separator
58 * , placeholder for grouping separator.
59 * ; separates formats.
60 * - default negative prefix.
61 * % divide by 100 and show as percentage
62 * X any other characters can be used in the prefix or suffix
63 * ' used to quote special characters in a prefix or suffix.
68 * If there is no explicit negative subpattern, - is prefixed to the
69 * positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
71 * The grouping separator is commonly used for thousands, but in some
72 * countries for ten-thousands. The interval is a constant number of
73 * digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
74 * If you supply a pattern with multiple grouping characters, the interval
75 * between the last one and the end of the integer is the one that is
76 * used. So "#,##,###,####" == "######,####" == "##,####,####".
78 * This class only handles localized digits where the 10 digits are
79 * contiguous in Unicode, from 0 to 9. Other digits sets (such as
80 * superscripts) would need a different subclass.
82 class U_I18N_API DecimalFormatSymbols
: public UObject
{
85 * Constants for specifying a number format symbol.
88 enum ENumberFormatSymbol
{
89 /** The decimal separator */
90 kDecimalSeparatorSymbol
,
91 /** The grouping separator */
92 kGroupingSeparatorSymbol
,
93 /** The pattern separator */
94 kPatternSeparatorSymbol
,
95 /** The percent sign */
99 /** Character representing a digit in the pattern */
101 /** The minus sign */
105 /** The currency symbol */
107 /** The international currency symbol */
109 /** The monetary separator */
110 kMonetarySeparatorSymbol
,
111 /** The exponential symbol */
113 /** Per mill symbol - replaces kPermillSymbol */
115 /** Escape padding character */
117 /** Infinity symbol */
121 /** Significant digit symbol
123 kSignificantDigitSymbol
,
124 /** The monetary grouping separator
127 kMonetaryGroupingSeparatorSymbol
,
128 /** count symbol constants */
133 * Create a DecimalFormatSymbols object for the given locale.
135 * @param locale The locale to get symbols for.
136 * @param status Input/output parameter, set to success or
137 * failure code upon return.
140 DecimalFormatSymbols(const Locale
& locale
, UErrorCode
& status
);
143 * Create a DecimalFormatSymbols object for the default locale.
144 * This constructor will not fail. If the resource file data is
145 * not available, it will use hard-coded last-resort data and
146 * set status to U_USING_FALLBACK_ERROR.
148 * @param status Input/output parameter, set to success or
149 * failure code upon return.
152 DecimalFormatSymbols( UErrorCode
& status
);
158 DecimalFormatSymbols(const DecimalFormatSymbols
&);
161 * Assignment operator.
164 DecimalFormatSymbols
& operator=(const DecimalFormatSymbols
&);
170 virtual ~DecimalFormatSymbols();
173 * Return true if another object is semantically equal to this one.
175 * @param other the object to be compared with.
176 * @return true if another object is semantically equal to this one.
179 UBool
operator==(const DecimalFormatSymbols
& other
) const;
182 * Return true if another object is semantically unequal to this one.
184 * @param other the object to be compared with.
185 * @return true if another object is semantically unequal to this one.
188 UBool
operator!=(const DecimalFormatSymbols
& other
) const { return !operator==(other
); }
191 * Get one of the format symbols by its enum constant.
192 * Each symbol is stored as a string so that graphemes
193 * (characters with modifyer letters) can be used.
195 * @param symbol Constant to indicate a number format symbol.
196 * @return the format symbols by the param 'symbol'
199 inline UnicodeString
getSymbol(ENumberFormatSymbol symbol
) const;
202 * Set one of the format symbols by its enum constant.
203 * Each symbol is stored as a string so that graphemes
204 * (characters with modifyer letters) can be used.
206 * @param symbol Constant to indicate a number format symbol.
207 * @param value value of the format sybmol
210 void setSymbol(ENumberFormatSymbol symbol
, const UnicodeString
&value
);
213 * Returns the locale for which this object was constructed.
216 inline Locale
getLocale() const;
219 * Returns the locale for this object. Two flavors are available:
220 * valid and actual locale.
223 Locale
getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const;
226 * ICU "poor man's RTTI", returns a UClassID for the actual class.
230 virtual UClassID
getDynamicClassID() const;
233 * ICU "poor man's RTTI", returns a UClassID for this class.
237 static UClassID U_EXPORT2
getStaticClassID();
240 DecimalFormatSymbols(); // default constructor not implemented
243 * Initializes the symbols from the LocaleElements resource bundle.
244 * Note: The organization of LocaleElements badly needs to be
247 * @param locale The locale to get symbols for.
248 * @param success Input/output parameter, set to success or
249 * failure code upon return.
250 * @param useLastResortData determine if use last resort data
252 void initialize(const Locale
& locale
, UErrorCode
& success
, UBool useLastResortData
= FALSE
);
255 * Initialize the symbols from the given array of UnicodeStrings.
256 * The array must be of the correct size.
258 * @param numberElements the number format symbols
259 * @param numberElementsLength length of numberElements
261 void initialize(const UChar
** numberElements
, int32_t *numberElementsStrLen
, int32_t numberElementsLength
);
264 * Initialize the symbols with default values.
268 void setCurrencyForSymbols();
272 * _Internal_ function - more efficient version of getSymbol,
273 * returning a const reference to one of the symbol strings.
274 * The returned reference becomes invalid when the symbol is changed
275 * or when the DecimalFormatSymbols are destroyed.
276 * ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
278 * @param symbol Constant to indicate a number format symbol.
279 * @return the format symbol by the param 'symbol'
282 inline const UnicodeString
&getConstSymbol(ENumberFormatSymbol symbol
) const;
285 * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
288 inline const UChar
* getCurrencyPattern(void) const;
292 * Private symbol strings.
293 * They are either loaded from a resource bundle or otherwise owned.
294 * setSymbol() clones the symbol string.
295 * Readonly aliases can only come from a resource bundle, so that we can always
296 * use fastCopyFrom() with them.
298 * If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
299 * from private to protected,
300 * or when fSymbols can be set any other way that allows them to be readonly aliases
301 * to non-resource bundle strings,
302 * then regular UnicodeString copies must be used instead of fastCopyFrom().
306 UnicodeString fSymbols
[kFormatSymbolCount
];
309 * Non-symbol variable for getConstSymbol(). Always empty.
312 UnicodeString fNoSymbol
;
316 char actualLocale
[ULOC_FULLNAME_CAPACITY
];
317 char validLocale
[ULOC_FULLNAME_CAPACITY
];
318 const UChar
* currPattern
;
321 // -------------------------------------
324 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol
) const {
325 const UnicodeString
*strPtr
;
326 if(symbol
< kFormatSymbolCount
) {
327 strPtr
= &fSymbols
[symbol
];
334 inline const UnicodeString
&
335 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol
) const {
336 const UnicodeString
*strPtr
;
337 if(symbol
< kFormatSymbolCount
) {
338 strPtr
= &fSymbols
[symbol
];
345 // -------------------------------------
348 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol
, const UnicodeString
&value
) {
349 if(symbol
<kFormatSymbolCount
) {
350 fSymbols
[symbol
]=value
;
354 // -------------------------------------
357 DecimalFormatSymbols::getLocale() const {
362 DecimalFormatSymbols::getCurrencyPattern() const {
367 #endif /* #if !UCONFIG_NO_FORMATTING */