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) 1997-2016, International Business Machines
|
jpayne@69
|
6 * Corporation and others. All Rights Reserved.
|
jpayne@69
|
7 ********************************************************************************
|
jpayne@69
|
8 *
|
jpayne@69
|
9 * File DCFMTSYM.H
|
jpayne@69
|
10 *
|
jpayne@69
|
11 * Modification History:
|
jpayne@69
|
12 *
|
jpayne@69
|
13 * Date Name Description
|
jpayne@69
|
14 * 02/19/97 aliu Converted from java.
|
jpayne@69
|
15 * 03/18/97 clhuang Updated per C++ implementation.
|
jpayne@69
|
16 * 03/27/97 helena Updated to pass the simple test after code review.
|
jpayne@69
|
17 * 08/26/97 aliu Added currency/intl currency symbol support.
|
jpayne@69
|
18 * 07/22/98 stephen Changed to match C++ style
|
jpayne@69
|
19 * currencySymbol -> fCurrencySymbol
|
jpayne@69
|
20 * Constants changed from CAPS to kCaps
|
jpayne@69
|
21 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
|
jpayne@69
|
22 * 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
|
jpayne@69
|
23 * functions.
|
jpayne@69
|
24 ********************************************************************************
|
jpayne@69
|
25 */
|
jpayne@69
|
26
|
jpayne@69
|
27 #ifndef DCFMTSYM_H
|
jpayne@69
|
28 #define DCFMTSYM_H
|
jpayne@69
|
29
|
jpayne@69
|
30 #include "unicode/utypes.h"
|
jpayne@69
|
31
|
jpayne@69
|
32 #if U_SHOW_CPLUSPLUS_API
|
jpayne@69
|
33
|
jpayne@69
|
34 #if !UCONFIG_NO_FORMATTING
|
jpayne@69
|
35
|
jpayne@69
|
36 #include "unicode/uchar.h"
|
jpayne@69
|
37 #include "unicode/uobject.h"
|
jpayne@69
|
38 #include "unicode/locid.h"
|
jpayne@69
|
39 #include "unicode/numsys.h"
|
jpayne@69
|
40 #include "unicode/unum.h"
|
jpayne@69
|
41 #include "unicode/unistr.h"
|
jpayne@69
|
42
|
jpayne@69
|
43 /**
|
jpayne@69
|
44 * \file
|
jpayne@69
|
45 * \brief C++ API: Symbols for formatting numbers.
|
jpayne@69
|
46 */
|
jpayne@69
|
47
|
jpayne@69
|
48
|
jpayne@69
|
49 U_NAMESPACE_BEGIN
|
jpayne@69
|
50
|
jpayne@69
|
51 /**
|
jpayne@69
|
52 * This class represents the set of symbols needed by DecimalFormat
|
jpayne@69
|
53 * to format numbers. DecimalFormat creates for itself an instance of
|
jpayne@69
|
54 * DecimalFormatSymbols from its locale data. If you need to change any
|
jpayne@69
|
55 * of these symbols, you can get the DecimalFormatSymbols object from
|
jpayne@69
|
56 * your DecimalFormat and modify it.
|
jpayne@69
|
57 * <P>
|
jpayne@69
|
58 * Here are the special characters used in the parts of the
|
jpayne@69
|
59 * subpattern, with notes on their usage.
|
jpayne@69
|
60 * <pre>
|
jpayne@69
|
61 * \code
|
jpayne@69
|
62 * Symbol Meaning
|
jpayne@69
|
63 * 0 a digit
|
jpayne@69
|
64 * # a digit, zero shows as absent
|
jpayne@69
|
65 * . placeholder for decimal separator
|
jpayne@69
|
66 * , placeholder for grouping separator.
|
jpayne@69
|
67 * ; separates formats.
|
jpayne@69
|
68 * - default negative prefix.
|
jpayne@69
|
69 * % divide by 100 and show as percentage
|
jpayne@69
|
70 * X any other characters can be used in the prefix or suffix
|
jpayne@69
|
71 * ' used to quote special characters in a prefix or suffix.
|
jpayne@69
|
72 * \endcode
|
jpayne@69
|
73 * </pre>
|
jpayne@69
|
74 * [Notes]
|
jpayne@69
|
75 * <P>
|
jpayne@69
|
76 * If there is no explicit negative subpattern, - is prefixed to the
|
jpayne@69
|
77 * positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
|
jpayne@69
|
78 * <P>
|
jpayne@69
|
79 * The grouping separator is commonly used for thousands, but in some
|
jpayne@69
|
80 * countries for ten-thousands. The interval is a constant number of
|
jpayne@69
|
81 * digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
|
jpayne@69
|
82 * If you supply a pattern with multiple grouping characters, the interval
|
jpayne@69
|
83 * between the last one and the end of the integer is the one that is
|
jpayne@69
|
84 * used. So "#,##,###,####" == "######,####" == "##,####,####".
|
jpayne@69
|
85 */
|
jpayne@69
|
86 class U_I18N_API DecimalFormatSymbols : public UObject {
|
jpayne@69
|
87 public:
|
jpayne@69
|
88 /**
|
jpayne@69
|
89 * Constants for specifying a number format symbol.
|
jpayne@69
|
90 * @stable ICU 2.0
|
jpayne@69
|
91 */
|
jpayne@69
|
92 enum ENumberFormatSymbol {
|
jpayne@69
|
93 /** The decimal separator */
|
jpayne@69
|
94 kDecimalSeparatorSymbol,
|
jpayne@69
|
95 /** The grouping separator */
|
jpayne@69
|
96 kGroupingSeparatorSymbol,
|
jpayne@69
|
97 /** The pattern separator */
|
jpayne@69
|
98 kPatternSeparatorSymbol,
|
jpayne@69
|
99 /** The percent sign */
|
jpayne@69
|
100 kPercentSymbol,
|
jpayne@69
|
101 /** Zero*/
|
jpayne@69
|
102 kZeroDigitSymbol,
|
jpayne@69
|
103 /** Character representing a digit in the pattern */
|
jpayne@69
|
104 kDigitSymbol,
|
jpayne@69
|
105 /** The minus sign */
|
jpayne@69
|
106 kMinusSignSymbol,
|
jpayne@69
|
107 /** The plus sign */
|
jpayne@69
|
108 kPlusSignSymbol,
|
jpayne@69
|
109 /** The currency symbol */
|
jpayne@69
|
110 kCurrencySymbol,
|
jpayne@69
|
111 /** The international currency symbol */
|
jpayne@69
|
112 kIntlCurrencySymbol,
|
jpayne@69
|
113 /** The monetary separator */
|
jpayne@69
|
114 kMonetarySeparatorSymbol,
|
jpayne@69
|
115 /** The exponential symbol */
|
jpayne@69
|
116 kExponentialSymbol,
|
jpayne@69
|
117 /** Per mill symbol - replaces kPermillSymbol */
|
jpayne@69
|
118 kPerMillSymbol,
|
jpayne@69
|
119 /** Escape padding character */
|
jpayne@69
|
120 kPadEscapeSymbol,
|
jpayne@69
|
121 /** Infinity symbol */
|
jpayne@69
|
122 kInfinitySymbol,
|
jpayne@69
|
123 /** Nan symbol */
|
jpayne@69
|
124 kNaNSymbol,
|
jpayne@69
|
125 /** Significant digit symbol
|
jpayne@69
|
126 * @stable ICU 3.0 */
|
jpayne@69
|
127 kSignificantDigitSymbol,
|
jpayne@69
|
128 /** The monetary grouping separator
|
jpayne@69
|
129 * @stable ICU 3.6
|
jpayne@69
|
130 */
|
jpayne@69
|
131 kMonetaryGroupingSeparatorSymbol,
|
jpayne@69
|
132 /** One
|
jpayne@69
|
133 * @stable ICU 4.6
|
jpayne@69
|
134 */
|
jpayne@69
|
135 kOneDigitSymbol,
|
jpayne@69
|
136 /** Two
|
jpayne@69
|
137 * @stable ICU 4.6
|
jpayne@69
|
138 */
|
jpayne@69
|
139 kTwoDigitSymbol,
|
jpayne@69
|
140 /** Three
|
jpayne@69
|
141 * @stable ICU 4.6
|
jpayne@69
|
142 */
|
jpayne@69
|
143 kThreeDigitSymbol,
|
jpayne@69
|
144 /** Four
|
jpayne@69
|
145 * @stable ICU 4.6
|
jpayne@69
|
146 */
|
jpayne@69
|
147 kFourDigitSymbol,
|
jpayne@69
|
148 /** Five
|
jpayne@69
|
149 * @stable ICU 4.6
|
jpayne@69
|
150 */
|
jpayne@69
|
151 kFiveDigitSymbol,
|
jpayne@69
|
152 /** Six
|
jpayne@69
|
153 * @stable ICU 4.6
|
jpayne@69
|
154 */
|
jpayne@69
|
155 kSixDigitSymbol,
|
jpayne@69
|
156 /** Seven
|
jpayne@69
|
157 * @stable ICU 4.6
|
jpayne@69
|
158 */
|
jpayne@69
|
159 kSevenDigitSymbol,
|
jpayne@69
|
160 /** Eight
|
jpayne@69
|
161 * @stable ICU 4.6
|
jpayne@69
|
162 */
|
jpayne@69
|
163 kEightDigitSymbol,
|
jpayne@69
|
164 /** Nine
|
jpayne@69
|
165 * @stable ICU 4.6
|
jpayne@69
|
166 */
|
jpayne@69
|
167 kNineDigitSymbol,
|
jpayne@69
|
168 /** Multiplication sign.
|
jpayne@69
|
169 * @stable ICU 54
|
jpayne@69
|
170 */
|
jpayne@69
|
171 kExponentMultiplicationSymbol,
|
jpayne@69
|
172 /** count symbol constants */
|
jpayne@69
|
173 kFormatSymbolCount = kNineDigitSymbol + 2
|
jpayne@69
|
174 };
|
jpayne@69
|
175
|
jpayne@69
|
176 /**
|
jpayne@69
|
177 * Create a DecimalFormatSymbols object for the given locale.
|
jpayne@69
|
178 *
|
jpayne@69
|
179 * @param locale The locale to get symbols for.
|
jpayne@69
|
180 * @param status Input/output parameter, set to success or
|
jpayne@69
|
181 * failure code upon return.
|
jpayne@69
|
182 * @stable ICU 2.0
|
jpayne@69
|
183 */
|
jpayne@69
|
184 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
|
jpayne@69
|
185
|
jpayne@69
|
186 /**
|
jpayne@69
|
187 * Creates a DecimalFormatSymbols instance for the given locale with digits and symbols
|
jpayne@69
|
188 * corresponding to the given NumberingSystem.
|
jpayne@69
|
189 *
|
jpayne@69
|
190 * This constructor behaves equivalently to the normal constructor called with a locale having a
|
jpayne@69
|
191 * "numbers=xxxx" keyword specifying the numbering system by name.
|
jpayne@69
|
192 *
|
jpayne@69
|
193 * In this constructor, the NumberingSystem argument will be used even if the locale has its own
|
jpayne@69
|
194 * "numbers=xxxx" keyword.
|
jpayne@69
|
195 *
|
jpayne@69
|
196 * @param locale The locale to get symbols for.
|
jpayne@69
|
197 * @param ns The numbering system.
|
jpayne@69
|
198 * @param status Input/output parameter, set to success or
|
jpayne@69
|
199 * failure code upon return.
|
jpayne@69
|
200 * @stable ICU 60
|
jpayne@69
|
201 */
|
jpayne@69
|
202 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
|
jpayne@69
|
203
|
jpayne@69
|
204 /**
|
jpayne@69
|
205 * Create a DecimalFormatSymbols object for the default locale.
|
jpayne@69
|
206 * This constructor will not fail. If the resource file data is
|
jpayne@69
|
207 * not available, it will use hard-coded last-resort data and
|
jpayne@69
|
208 * set status to U_USING_FALLBACK_ERROR.
|
jpayne@69
|
209 *
|
jpayne@69
|
210 * @param status Input/output parameter, set to success or
|
jpayne@69
|
211 * failure code upon return.
|
jpayne@69
|
212 * @stable ICU 2.0
|
jpayne@69
|
213 */
|
jpayne@69
|
214 DecimalFormatSymbols(UErrorCode& status);
|
jpayne@69
|
215
|
jpayne@69
|
216 /**
|
jpayne@69
|
217 * Creates a DecimalFormatSymbols object with last-resort data.
|
jpayne@69
|
218 * Intended for callers who cache the symbols data and
|
jpayne@69
|
219 * set all symbols on the resulting object.
|
jpayne@69
|
220 *
|
jpayne@69
|
221 * The last-resort symbols are similar to those for the root data,
|
jpayne@69
|
222 * except that the grouping separators are empty,
|
jpayne@69
|
223 * the NaN symbol is U+FFFD rather than "NaN",
|
jpayne@69
|
224 * and the CurrencySpacing patterns are empty.
|
jpayne@69
|
225 *
|
jpayne@69
|
226 * @param status Input/output parameter, set to success or
|
jpayne@69
|
227 * failure code upon return.
|
jpayne@69
|
228 * @return last-resort symbols
|
jpayne@69
|
229 * @stable ICU 52
|
jpayne@69
|
230 */
|
jpayne@69
|
231 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
|
jpayne@69
|
232
|
jpayne@69
|
233 /**
|
jpayne@69
|
234 * Copy constructor.
|
jpayne@69
|
235 * @stable ICU 2.0
|
jpayne@69
|
236 */
|
jpayne@69
|
237 DecimalFormatSymbols(const DecimalFormatSymbols&);
|
jpayne@69
|
238
|
jpayne@69
|
239 /**
|
jpayne@69
|
240 * Assignment operator.
|
jpayne@69
|
241 * @stable ICU 2.0
|
jpayne@69
|
242 */
|
jpayne@69
|
243 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
|
jpayne@69
|
244
|
jpayne@69
|
245 /**
|
jpayne@69
|
246 * Destructor.
|
jpayne@69
|
247 * @stable ICU 2.0
|
jpayne@69
|
248 */
|
jpayne@69
|
249 virtual ~DecimalFormatSymbols();
|
jpayne@69
|
250
|
jpayne@69
|
251 /**
|
jpayne@69
|
252 * Return true if another object is semantically equal to this one.
|
jpayne@69
|
253 *
|
jpayne@69
|
254 * @param other the object to be compared with.
|
jpayne@69
|
255 * @return true if another object is semantically equal to this one.
|
jpayne@69
|
256 * @stable ICU 2.0
|
jpayne@69
|
257 */
|
jpayne@69
|
258 UBool operator==(const DecimalFormatSymbols& other) const;
|
jpayne@69
|
259
|
jpayne@69
|
260 /**
|
jpayne@69
|
261 * Return true if another object is semantically unequal to this one.
|
jpayne@69
|
262 *
|
jpayne@69
|
263 * @param other the object to be compared with.
|
jpayne@69
|
264 * @return true if another object is semantically unequal to this one.
|
jpayne@69
|
265 * @stable ICU 2.0
|
jpayne@69
|
266 */
|
jpayne@69
|
267 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
|
jpayne@69
|
268
|
jpayne@69
|
269 /**
|
jpayne@69
|
270 * Get one of the format symbols by its enum constant.
|
jpayne@69
|
271 * Each symbol is stored as a string so that graphemes
|
jpayne@69
|
272 * (characters with modifier letters) can be used.
|
jpayne@69
|
273 *
|
jpayne@69
|
274 * @param symbol Constant to indicate a number format symbol.
|
jpayne@69
|
275 * @return the format symbols by the param 'symbol'
|
jpayne@69
|
276 * @stable ICU 2.0
|
jpayne@69
|
277 */
|
jpayne@69
|
278 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
|
jpayne@69
|
279
|
jpayne@69
|
280 /**
|
jpayne@69
|
281 * Set one of the format symbols by its enum constant.
|
jpayne@69
|
282 * Each symbol is stored as a string so that graphemes
|
jpayne@69
|
283 * (characters with modifier letters) can be used.
|
jpayne@69
|
284 *
|
jpayne@69
|
285 * @param symbol Constant to indicate a number format symbol.
|
jpayne@69
|
286 * @param value value of the format symbol
|
jpayne@69
|
287 * @param propogateDigits If false, setting the zero digit will not automatically set 1-9.
|
jpayne@69
|
288 * The default behavior is to automatically set 1-9 if zero is being set and the value
|
jpayne@69
|
289 * it is being set to corresponds to a known Unicode zero digit.
|
jpayne@69
|
290 * @stable ICU 2.0
|
jpayne@69
|
291 */
|
jpayne@69
|
292 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
|
jpayne@69
|
293
|
jpayne@69
|
294 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
295 /**
|
jpayne@69
|
296 * Loads symbols for the specified currency into this instance.
|
jpayne@69
|
297 *
|
jpayne@69
|
298 * This method is internal. If you think it should be public, file a ticket.
|
jpayne@69
|
299 *
|
jpayne@69
|
300 * @internal
|
jpayne@69
|
301 */
|
jpayne@69
|
302 void setCurrency(const UChar* currency, UErrorCode& status);
|
jpayne@69
|
303 #endif // U_HIDE_INTERNAL_API
|
jpayne@69
|
304
|
jpayne@69
|
305 /**
|
jpayne@69
|
306 * Returns the locale for which this object was constructed.
|
jpayne@69
|
307 * @stable ICU 2.6
|
jpayne@69
|
308 */
|
jpayne@69
|
309 inline Locale getLocale() const;
|
jpayne@69
|
310
|
jpayne@69
|
311 /**
|
jpayne@69
|
312 * Returns the locale for this object. Two flavors are available:
|
jpayne@69
|
313 * valid and actual locale.
|
jpayne@69
|
314 * @stable ICU 2.8
|
jpayne@69
|
315 */
|
jpayne@69
|
316 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
jpayne@69
|
317
|
jpayne@69
|
318 /**
|
jpayne@69
|
319 * Get pattern string for 'CurrencySpacing' that can be applied to
|
jpayne@69
|
320 * currency format.
|
jpayne@69
|
321 * This API gets the CurrencySpacing data from ResourceBundle. The pattern can
|
jpayne@69
|
322 * be empty if there is no data from current locale and its parent locales.
|
jpayne@69
|
323 *
|
jpayne@69
|
324 * @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
|
jpayne@69
|
325 * @param beforeCurrency : true if the pattern is for before currency symbol.
|
jpayne@69
|
326 * false if the pattern is for after currency symbol.
|
jpayne@69
|
327 * @param status: Input/output parameter, set to success or
|
jpayne@69
|
328 * failure code upon return.
|
jpayne@69
|
329 * @return pattern string for currencyMatch, surroundingMatch or spaceInsert.
|
jpayne@69
|
330 * Return empty string if there is no data for this locale and its parent
|
jpayne@69
|
331 * locales.
|
jpayne@69
|
332 * @stable ICU 4.8
|
jpayne@69
|
333 */
|
jpayne@69
|
334 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
|
jpayne@69
|
335 UBool beforeCurrency,
|
jpayne@69
|
336 UErrorCode& status) const;
|
jpayne@69
|
337 /**
|
jpayne@69
|
338 * Set pattern string for 'CurrencySpacing' that can be applied to
|
jpayne@69
|
339 * currency format.
|
jpayne@69
|
340 *
|
jpayne@69
|
341 * @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
|
jpayne@69
|
342 * @param beforeCurrency : true if the pattern is for before currency symbol.
|
jpayne@69
|
343 * false if the pattern is for after currency symbol.
|
jpayne@69
|
344 * @param pattern : pattern string to override current setting.
|
jpayne@69
|
345 * @stable ICU 4.8
|
jpayne@69
|
346 */
|
jpayne@69
|
347 void setPatternForCurrencySpacing(UCurrencySpacing type,
|
jpayne@69
|
348 UBool beforeCurrency,
|
jpayne@69
|
349 const UnicodeString& pattern);
|
jpayne@69
|
350
|
jpayne@69
|
351 /**
|
jpayne@69
|
352 * ICU "poor man's RTTI", returns a UClassID for the actual class.
|
jpayne@69
|
353 *
|
jpayne@69
|
354 * @stable ICU 2.2
|
jpayne@69
|
355 */
|
jpayne@69
|
356 virtual UClassID getDynamicClassID() const;
|
jpayne@69
|
357
|
jpayne@69
|
358 /**
|
jpayne@69
|
359 * ICU "poor man's RTTI", returns a UClassID for this class.
|
jpayne@69
|
360 *
|
jpayne@69
|
361 * @stable ICU 2.2
|
jpayne@69
|
362 */
|
jpayne@69
|
363 static UClassID U_EXPORT2 getStaticClassID();
|
jpayne@69
|
364
|
jpayne@69
|
365 private:
|
jpayne@69
|
366 DecimalFormatSymbols();
|
jpayne@69
|
367
|
jpayne@69
|
368 /**
|
jpayne@69
|
369 * Initializes the symbols from the LocaleElements resource bundle.
|
jpayne@69
|
370 * Note: The organization of LocaleElements badly needs to be
|
jpayne@69
|
371 * cleaned up.
|
jpayne@69
|
372 *
|
jpayne@69
|
373 * @param locale The locale to get symbols for.
|
jpayne@69
|
374 * @param success Input/output parameter, set to success or
|
jpayne@69
|
375 * failure code upon return.
|
jpayne@69
|
376 * @param useLastResortData determine if use last resort data
|
jpayne@69
|
377 * @param ns The NumberingSystem to use; otherwise, fall
|
jpayne@69
|
378 * back to the locale.
|
jpayne@69
|
379 */
|
jpayne@69
|
380 void initialize(const Locale& locale, UErrorCode& success,
|
jpayne@69
|
381 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
|
jpayne@69
|
382
|
jpayne@69
|
383 /**
|
jpayne@69
|
384 * Initialize the symbols with default values.
|
jpayne@69
|
385 */
|
jpayne@69
|
386 void initialize();
|
jpayne@69
|
387
|
jpayne@69
|
388 public:
|
jpayne@69
|
389
|
jpayne@69
|
390 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
391 /**
|
jpayne@69
|
392 * @internal For ICU use only
|
jpayne@69
|
393 */
|
jpayne@69
|
394 inline UBool isCustomCurrencySymbol() const {
|
jpayne@69
|
395 return fIsCustomCurrencySymbol;
|
jpayne@69
|
396 }
|
jpayne@69
|
397
|
jpayne@69
|
398 /**
|
jpayne@69
|
399 * @internal For ICU use only
|
jpayne@69
|
400 */
|
jpayne@69
|
401 inline UBool isCustomIntlCurrencySymbol() const {
|
jpayne@69
|
402 return fIsCustomIntlCurrencySymbol;
|
jpayne@69
|
403 }
|
jpayne@69
|
404
|
jpayne@69
|
405 /**
|
jpayne@69
|
406 * @internal For ICU use only
|
jpayne@69
|
407 */
|
jpayne@69
|
408 inline UChar32 getCodePointZero() const {
|
jpayne@69
|
409 return fCodePointZero;
|
jpayne@69
|
410 }
|
jpayne@69
|
411 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
412
|
jpayne@69
|
413 /**
|
jpayne@69
|
414 * _Internal_ function - more efficient version of getSymbol,
|
jpayne@69
|
415 * returning a const reference to one of the symbol strings.
|
jpayne@69
|
416 * The returned reference becomes invalid when the symbol is changed
|
jpayne@69
|
417 * or when the DecimalFormatSymbols are destroyed.
|
jpayne@69
|
418 * Note: moved \#ifndef U_HIDE_INTERNAL_API after this, since this is needed for inline in DecimalFormat
|
jpayne@69
|
419 *
|
jpayne@69
|
420 * This is not currently stable API, but if you think it should be stable,
|
jpayne@69
|
421 * post a comment on the following ticket and the ICU team will take a look:
|
jpayne@69
|
422 * http://bugs.icu-project.org/trac/ticket/13580
|
jpayne@69
|
423 *
|
jpayne@69
|
424 * @param symbol Constant to indicate a number format symbol.
|
jpayne@69
|
425 * @return the format symbol by the param 'symbol'
|
jpayne@69
|
426 * @internal
|
jpayne@69
|
427 */
|
jpayne@69
|
428 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
|
jpayne@69
|
429
|
jpayne@69
|
430 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
431 /**
|
jpayne@69
|
432 * Returns the const UnicodeString reference, like getConstSymbol,
|
jpayne@69
|
433 * corresponding to the digit with the given value. This is equivalent
|
jpayne@69
|
434 * to accessing the symbol from getConstSymbol with the corresponding
|
jpayne@69
|
435 * key, such as kZeroDigitSymbol or kOneDigitSymbol.
|
jpayne@69
|
436 *
|
jpayne@69
|
437 * This is not currently stable API, but if you think it should be stable,
|
jpayne@69
|
438 * post a comment on the following ticket and the ICU team will take a look:
|
jpayne@69
|
439 * http://bugs.icu-project.org/trac/ticket/13580
|
jpayne@69
|
440 *
|
jpayne@69
|
441 * @param digit The digit, an integer between 0 and 9 inclusive.
|
jpayne@69
|
442 * If outside the range 0 to 9, the zero digit is returned.
|
jpayne@69
|
443 * @return the format symbol for the given digit.
|
jpayne@69
|
444 * @internal This API is currently for ICU use only.
|
jpayne@69
|
445 */
|
jpayne@69
|
446 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
|
jpayne@69
|
447
|
jpayne@69
|
448 /**
|
jpayne@69
|
449 * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
|
jpayne@69
|
450 * @internal
|
jpayne@69
|
451 */
|
jpayne@69
|
452 inline const char16_t* getCurrencyPattern(void) const;
|
jpayne@69
|
453 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
454
|
jpayne@69
|
455 private:
|
jpayne@69
|
456 /**
|
jpayne@69
|
457 * Private symbol strings.
|
jpayne@69
|
458 * They are either loaded from a resource bundle or otherwise owned.
|
jpayne@69
|
459 * setSymbol() clones the symbol string.
|
jpayne@69
|
460 * Readonly aliases can only come from a resource bundle, so that we can always
|
jpayne@69
|
461 * use fastCopyFrom() with them.
|
jpayne@69
|
462 *
|
jpayne@69
|
463 * If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
|
jpayne@69
|
464 * from private to protected,
|
jpayne@69
|
465 * or when fSymbols can be set any other way that allows them to be readonly aliases
|
jpayne@69
|
466 * to non-resource bundle strings,
|
jpayne@69
|
467 * then regular UnicodeString copies must be used instead of fastCopyFrom().
|
jpayne@69
|
468 *
|
jpayne@69
|
469 */
|
jpayne@69
|
470 UnicodeString fSymbols[kFormatSymbolCount];
|
jpayne@69
|
471
|
jpayne@69
|
472 /**
|
jpayne@69
|
473 * Non-symbol variable for getConstSymbol(). Always empty.
|
jpayne@69
|
474 */
|
jpayne@69
|
475 UnicodeString fNoSymbol;
|
jpayne@69
|
476
|
jpayne@69
|
477 /**
|
jpayne@69
|
478 * Dealing with code points is faster than dealing with strings when formatting. Because of
|
jpayne@69
|
479 * this, we maintain a value containing the zero code point that is used whenever digitStrings
|
jpayne@69
|
480 * represents a sequence of ten code points in order.
|
jpayne@69
|
481 *
|
jpayne@69
|
482 * <p>If the value stored here is positive, it means that the code point stored in this value
|
jpayne@69
|
483 * corresponds to the digitStrings array, and codePointZero can be used instead of the
|
jpayne@69
|
484 * digitStrings array for the purposes of efficient formatting; if -1, then digitStrings does
|
jpayne@69
|
485 * *not* contain a sequence of code points, and it must be used directly.
|
jpayne@69
|
486 *
|
jpayne@69
|
487 * <p>It is assumed that codePointZero always shadows the value in digitStrings. codePointZero
|
jpayne@69
|
488 * should never be set directly; rather, it should be updated only when digitStrings mutates.
|
jpayne@69
|
489 * That is, the flow of information is digitStrings -> codePointZero, not the other way.
|
jpayne@69
|
490 */
|
jpayne@69
|
491 UChar32 fCodePointZero;
|
jpayne@69
|
492
|
jpayne@69
|
493 Locale locale;
|
jpayne@69
|
494
|
jpayne@69
|
495 char actualLocale[ULOC_FULLNAME_CAPACITY];
|
jpayne@69
|
496 char validLocale[ULOC_FULLNAME_CAPACITY];
|
jpayne@69
|
497 const char16_t* currPattern;
|
jpayne@69
|
498
|
jpayne@69
|
499 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
|
jpayne@69
|
500 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
|
jpayne@69
|
501 UBool fIsCustomCurrencySymbol;
|
jpayne@69
|
502 UBool fIsCustomIntlCurrencySymbol;
|
jpayne@69
|
503 };
|
jpayne@69
|
504
|
jpayne@69
|
505 // -------------------------------------
|
jpayne@69
|
506
|
jpayne@69
|
507 inline UnicodeString
|
jpayne@69
|
508 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
|
jpayne@69
|
509 const UnicodeString *strPtr;
|
jpayne@69
|
510 if(symbol < kFormatSymbolCount) {
|
jpayne@69
|
511 strPtr = &fSymbols[symbol];
|
jpayne@69
|
512 } else {
|
jpayne@69
|
513 strPtr = &fNoSymbol;
|
jpayne@69
|
514 }
|
jpayne@69
|
515 return *strPtr;
|
jpayne@69
|
516 }
|
jpayne@69
|
517
|
jpayne@69
|
518 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
|
jpayne@69
|
519 inline const UnicodeString &
|
jpayne@69
|
520 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
|
jpayne@69
|
521 const UnicodeString *strPtr;
|
jpayne@69
|
522 if(symbol < kFormatSymbolCount) {
|
jpayne@69
|
523 strPtr = &fSymbols[symbol];
|
jpayne@69
|
524 } else {
|
jpayne@69
|
525 strPtr = &fNoSymbol;
|
jpayne@69
|
526 }
|
jpayne@69
|
527 return *strPtr;
|
jpayne@69
|
528 }
|
jpayne@69
|
529
|
jpayne@69
|
530 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
531 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
|
jpayne@69
|
532 if (digit < 0 || digit > 9) {
|
jpayne@69
|
533 digit = 0;
|
jpayne@69
|
534 }
|
jpayne@69
|
535 if (digit == 0) {
|
jpayne@69
|
536 return fSymbols[kZeroDigitSymbol];
|
jpayne@69
|
537 }
|
jpayne@69
|
538 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
|
jpayne@69
|
539 return fSymbols[key];
|
jpayne@69
|
540 }
|
jpayne@69
|
541 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
542
|
jpayne@69
|
543 // -------------------------------------
|
jpayne@69
|
544
|
jpayne@69
|
545 inline void
|
jpayne@69
|
546 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
|
jpayne@69
|
547 if (symbol == kCurrencySymbol) {
|
jpayne@69
|
548 fIsCustomCurrencySymbol = TRUE;
|
jpayne@69
|
549 }
|
jpayne@69
|
550 else if (symbol == kIntlCurrencySymbol) {
|
jpayne@69
|
551 fIsCustomIntlCurrencySymbol = TRUE;
|
jpayne@69
|
552 }
|
jpayne@69
|
553 if(symbol<kFormatSymbolCount) {
|
jpayne@69
|
554 fSymbols[symbol]=value;
|
jpayne@69
|
555 }
|
jpayne@69
|
556
|
jpayne@69
|
557 // If the zero digit is being set to a known zero digit according to Unicode,
|
jpayne@69
|
558 // then we automatically set the corresponding 1-9 digits
|
jpayne@69
|
559 // Also record updates to fCodePointZero. Be conservative if in doubt.
|
jpayne@69
|
560 if (symbol == kZeroDigitSymbol) {
|
jpayne@69
|
561 UChar32 sym = value.char32At(0);
|
jpayne@69
|
562 if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
|
jpayne@69
|
563 fCodePointZero = sym;
|
jpayne@69
|
564 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
|
jpayne@69
|
565 sym++;
|
jpayne@69
|
566 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
|
jpayne@69
|
567 }
|
jpayne@69
|
568 } else {
|
jpayne@69
|
569 fCodePointZero = -1;
|
jpayne@69
|
570 }
|
jpayne@69
|
571 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
|
jpayne@69
|
572 fCodePointZero = -1;
|
jpayne@69
|
573 }
|
jpayne@69
|
574 }
|
jpayne@69
|
575
|
jpayne@69
|
576 // -------------------------------------
|
jpayne@69
|
577
|
jpayne@69
|
578 inline Locale
|
jpayne@69
|
579 DecimalFormatSymbols::getLocale() const {
|
jpayne@69
|
580 return locale;
|
jpayne@69
|
581 }
|
jpayne@69
|
582
|
jpayne@69
|
583 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
584 inline const char16_t*
|
jpayne@69
|
585 DecimalFormatSymbols::getCurrencyPattern() const {
|
jpayne@69
|
586 return currPattern;
|
jpayne@69
|
587 }
|
jpayne@69
|
588 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
589
|
jpayne@69
|
590 U_NAMESPACE_END
|
jpayne@69
|
591
|
jpayne@69
|
592 #endif /* #if !UCONFIG_NO_FORMATTING */
|
jpayne@69
|
593
|
jpayne@69
|
594 #endif /* U_SHOW_CPLUSPLUS_API */
|
jpayne@69
|
595
|
jpayne@69
|
596 #endif // _DCFMTSYM
|
jpayne@69
|
597 //eof
|