ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

dcfmtsym.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File DCFMTSYM.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 03/18/97 clhuang Updated per C++ implementation.
16 * 03/27/97 helena Updated to pass the simple test after code review.
17 * 08/26/97 aliu Added currency/intl currency symbol support.
18 * 07/22/98 stephen Changed to match C++ style
19 * currencySymbol -> fCurrencySymbol
20 * Constants changed from CAPS to kCaps
21 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
22 * 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
23 * functions.
24 ********************************************************************************
25 */
26
27 #ifndef DCFMTSYM_H
28 #define DCFMTSYM_H
29
30 #include "unicode/utypes.h"
31 #include "unicode/uchar.h"
32
33 #if !UCONFIG_NO_FORMATTING
34
35 #include "unicode/uobject.h"
36 #include "unicode/locid.h"
37 #include "unicode/numsys.h"
38 #include "unicode/unum.h"
39 #include "unicode/unistr.h"
40
47 U_NAMESPACE_BEGIN
48
88 class U_I18N_API DecimalFormatSymbols : public UObject {
89 public:
94 enum ENumberFormatSymbol {
96 kDecimalSeparatorSymbol,
98 kGroupingSeparatorSymbol,
100 kPatternSeparatorSymbol,
102 kPercentSymbol,
104 kZeroDigitSymbol,
106 kDigitSymbol,
108 kMinusSignSymbol,
110 kPlusSignSymbol,
112 kCurrencySymbol,
114 kIntlCurrencySymbol,
116 kMonetarySeparatorSymbol,
118 kExponentialSymbol,
120 kPerMillSymbol,
122 kPadEscapeSymbol,
124 kInfinitySymbol,
126 kNaNSymbol,
129 kSignificantDigitSymbol,
133 kMonetaryGroupingSeparatorSymbol,
137 kOneDigitSymbol,
141 kTwoDigitSymbol,
145 kThreeDigitSymbol,
149 kFourDigitSymbol,
153 kFiveDigitSymbol,
157 kSixDigitSymbol,
161 kSevenDigitSymbol,
165 kEightDigitSymbol,
169 kNineDigitSymbol,
173 kExponentMultiplicationSymbol,
175 kFormatSymbolCount = kNineDigitSymbol + 2
176 };
177
186 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
187
188 #ifndef U_HIDE_DRAFT_API
189
205 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
206 #endif /* U_HIDE_DRAFT_API */
207
218 DecimalFormatSymbols(UErrorCode& status);
219
235 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
236
241 DecimalFormatSymbols(const DecimalFormatSymbols&);
242
247 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
248
253 virtual ~DecimalFormatSymbols();
254
262 UBool operator==(const DecimalFormatSymbols& other) const;
263
271 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
272
282 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
283
296 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
297
302 inline Locale getLocale() const;
303
309 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
310
327 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
328 UBool beforeCurrency,
329 UErrorCode& status) const;
340 void setPatternForCurrencySpacing(UCurrencySpacing type,
341 UBool beforeCurrency,
342 const UnicodeString& pattern);
343
349 virtual UClassID getDynamicClassID() const;
350
356 static UClassID U_EXPORT2 getStaticClassID();
357
358 private:
359 DecimalFormatSymbols();
360
373 void initialize(const Locale& locale, UErrorCode& success,
374 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
375
379 void initialize();
380
381 void setCurrencyForSymbols();
382
383 public:
384
385 #ifndef U_HIDE_INTERNAL_API
386
389 inline UBool isCustomCurrencySymbol() const {
390 return fIsCustomCurrencySymbol;
391 }
392
396 inline UBool isCustomIntlCurrencySymbol() const {
397 return fIsCustomIntlCurrencySymbol;
398 }
399 #endif /* U_HIDE_INTERNAL_API */
400
413 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
414
415 #ifndef U_HIDE_INTERNAL_API
416
420 inline const char16_t* getCurrencyPattern(void) const;
421 #endif /* U_HIDE_INTERNAL_API */
422
423 private:
439 UnicodeString fSymbols[kFormatSymbolCount];
440
445 UnicodeString fNoSymbol;
446
447 Locale locale;
448
449 char actualLocale[ULOC_FULLNAME_CAPACITY];
450 char validLocale[ULOC_FULLNAME_CAPACITY];
451 const char16_t* currPattern;
452
453 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
454 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
455 UBool fIsCustomCurrencySymbol;
456 UBool fIsCustomIntlCurrencySymbol;
457 };
458
459 // -------------------------------------
460
461 inline UnicodeString
462 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
463 const UnicodeString *strPtr;
464 if(symbol < kFormatSymbolCount) {
465 strPtr = &fSymbols[symbol];
466 } else {
467 strPtr = &fNoSymbol;
468 }
469 return *strPtr;
470 }
471
472 // See comments above for this function. Not hidden with #ifndef U_HIDE_INTERNAL_API
473 inline const UnicodeString &
474 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
475 const UnicodeString *strPtr;
476 if(symbol < kFormatSymbolCount) {
477 strPtr = &fSymbols[symbol];
478 } else {
479 strPtr = &fNoSymbol;
480 }
481 return *strPtr;
482 }
483
484 // -------------------------------------
485
486 inline void
487 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
488 if (symbol == kCurrencySymbol) {
489 fIsCustomCurrencySymbol = TRUE;
490 }
491 else if (symbol == kIntlCurrencySymbol) {
492 fIsCustomIntlCurrencySymbol = TRUE;
493 }
494 if(symbol<kFormatSymbolCount) {
495 fSymbols[symbol]=value;
496 }
497
498 // If the zero digit is being set to a known zero digit according to Unicode,
499 // then we automatically set the corresponding 1-9 digits
500 if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
501 UChar32 sym = value.char32At(0);
502 if ( u_charDigitValue(sym) == 0 ) {
503 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
504 sym++;
505 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
506 }
507 }
508 }
509 }
510
511 // -------------------------------------
512
513 inline Locale
514 DecimalFormatSymbols::getLocale() const {
515 return locale;
516 }
517
518 #ifndef U_HIDE_INTERNAL_API
519 inline const char16_t*
520 DecimalFormatSymbols::getCurrencyPattern() const {
521 return currPattern;
522 }
523 #endif /* U_HIDE_INTERNAL_API */
524
525 U_NAMESPACE_END
526
527 #endif /* #if !UCONFIG_NO_FORMATTING */
528
529 #endif // _DCFMTSYM
530 //eof
icu::DecimalFormatSymbols::kInfinitySymbol
Infinity symbol.
Definition: dcfmtsym.h:124
icu::DecimalFormatSymbols::isCustomIntlCurrencySymbol
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:396
icu::DecimalFormatSymbols::kExponentialSymbol
The exponential symbol.
Definition: dcfmtsym.h:118
icu::DecimalFormatSymbols::kFourDigitSymbol
Four.
Definition: dcfmtsym.h:149
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:88
icu::DecimalFormatSymbols::kPadEscapeSymbol
Escape padding character.
Definition: dcfmtsym.h:122
icu::DecimalFormatSymbols::kSixDigitSymbol
Six.
Definition: dcfmtsym.h:157
icu::DecimalFormatSymbols::kNaNSymbol
Nan symbol.
Definition: dcfmtsym.h:126
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
Multiplication sign.
Definition: dcfmtsym.h:173
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::DecimalFormatSymbols::kPercentSymbol
The percent sign.
Definition: dcfmtsym.h:102
icu::DecimalFormatSymbols::getLocale
Locale getLocale() const
Returns the locale for which this object was constructed.
Definition: dcfmtsym.h:514
icu::DecimalFormatSymbols::kIntlCurrencySymbol
The international currency symbol.
Definition: dcfmtsym.h:114
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::DecimalFormatSymbols::kSevenDigitSymbol
Seven.
Definition: dcfmtsym.h:161
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
UCurrencySpacing
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:327
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
The pattern separator.
Definition: dcfmtsym.h:100
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::DecimalFormatSymbols::kTwoDigitSymbol
Two.
Definition: dcfmtsym.h:141
u_charDigitValue
int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
ULOC_FULLNAME_CAPACITY
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition: uloc.h:264
icu::DecimalFormatSymbols::setSymbol
void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits)
Set one of the format symbols by its enum constant.
Definition: dcfmtsym.h:487
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:94
icu::DecimalFormatSymbols::kThreeDigitSymbol
Three.
Definition: dcfmtsym.h:145
icu::DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition: dcfmtsym.h:133
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
icu::DecimalFormatSymbols::getCurrencyPattern
const char16_t * getCurrencyPattern(void) const
Returns that pattern stored in currecy info.
Definition: dcfmtsym.h:520
icu::DecimalFormatSymbols::kZeroDigitSymbol
Zero.
Definition: dcfmtsym.h:104
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
The grouping separator.
Definition: dcfmtsym.h:98
icu::DecimalFormatSymbols::operator!=
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:271
icu::DecimalFormatSymbols::isCustomCurrencySymbol
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:389
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:396
TRUE
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:240
icu::DecimalFormatSymbols::kCurrencySymbol
The currency symbol.
Definition: dcfmtsym.h:112
numsys.h
C++ API: NumberingSystem object.
icu::DecimalFormatSymbols::kMonetarySeparatorSymbol
The monetary separator.
Definition: dcfmtsym.h:116
uchar.h
C API: Unicode Properties.
uobject.h
C++ API: Common ICU base class UObject.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
icu::DecimalFormatSymbols::kDecimalSeparatorSymbol
The decimal separator.
Definition: dcfmtsym.h:96
icu::DecimalFormatSymbols::kEightDigitSymbol
Eight.
Definition: dcfmtsym.h:165
icu::DecimalFormatSymbols::kNineDigitSymbol
Nine.
Definition: dcfmtsym.h:169
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::DecimalFormatSymbols::getSymbol
UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition: dcfmtsym.h:462
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:338
locid.h
C++ API: Locale ID object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::DecimalFormatSymbols::kDigitSymbol
Character representing a digit in the pattern.
Definition: dcfmtsym.h:106
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:244
icu::UnicodeString::countChar32
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
icu::DecimalFormatSymbols::kFiveDigitSymbol
Five.
Definition: dcfmtsym.h:153
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::DecimalFormatSymbols::kMinusSignSymbol
The minus sign.
Definition: dcfmtsym.h:108
icu::DecimalFormatSymbols::kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition: dcfmtsym.h:120
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:341
icu::DecimalFormatSymbols::getConstSymbol
const UnicodeString & getConstSymbol(ENumberFormatSymbol symbol) const
Internal function - more efficient version of getSymbol, returning a const reference to one of the sy...
Definition: dcfmtsym.h:474
icu::DecimalFormatSymbols::kSignificantDigitSymbol
Significant digit symbol.
Definition: dcfmtsym.h:129
icu::DecimalFormatSymbols::kOneDigitSymbol
One.
Definition: dcfmtsym.h:137
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
unum.h
C API: NumberFormat.
icu::DecimalFormatSymbols::kPlusSignSymbol
The plus sign.
Definition: dcfmtsym.h:110
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188