ICU 71.1 71.1

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
32 #if U_SHOW_CPLUSPLUS_API
33
34 #if !UCONFIG_NO_FORMATTING
35
36 #include "unicode/uchar.h"
37 #include "unicode/uobject.h"
38 #include "unicode/locid.h"
39 #include "unicode/numsys.h"
40 #include "unicode/unum.h"
41 #include "unicode/unistr.h"
42
49 U_NAMESPACE_BEGIN
50
86 class U_I18N_API DecimalFormatSymbols : public UObject {
87 public:
92 enum ENumberFormatSymbol {
94 kDecimalSeparatorSymbol,
96 kGroupingSeparatorSymbol,
98 kPatternSeparatorSymbol,
100 kPercentSymbol,
102 kZeroDigitSymbol,
104 kDigitSymbol,
106 kMinusSignSymbol,
108 kPlusSignSymbol,
110 kCurrencySymbol,
112 kIntlCurrencySymbol,
114 kMonetarySeparatorSymbol,
116 kExponentialSymbol,
118 kPerMillSymbol,
120 kPadEscapeSymbol,
122 kInfinitySymbol,
124 kNaNSymbol,
127 kSignificantDigitSymbol,
131 kMonetaryGroupingSeparatorSymbol,
135 kOneDigitSymbol,
139 kTwoDigitSymbol,
143 kThreeDigitSymbol,
147 kFourDigitSymbol,
151 kFiveDigitSymbol,
155 kSixDigitSymbol,
159 kSevenDigitSymbol,
163 kEightDigitSymbol,
167 kNineDigitSymbol,
171 kExponentMultiplicationSymbol,
172 #ifndef U_HIDE_INTERNAL_API
173
176 kApproximatelySignSymbol,
177 #endif /* U_HIDE_INTERNAL_API */
178
179 kFormatSymbolCount = kExponentMultiplicationSymbol + 2
180 };
181
190 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
191
208 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
209
220 DecimalFormatSymbols(UErrorCode& status);
221
237 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
238
243 DecimalFormatSymbols(const DecimalFormatSymbols&);
244
249 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
250
255 virtual ~DecimalFormatSymbols();
256
264 bool operator==(const DecimalFormatSymbols& other) const;
265
273 bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
274
284 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
285
298 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits);
299
300 #ifndef U_HIDE_INTERNAL_API
301
308 void setCurrency(const UChar* currency, UErrorCode& status);
309 #endif // U_HIDE_INTERNAL_API
310
315 inline Locale getLocale() const;
316
322 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
323
340 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
341 UBool beforeCurrency,
342 UErrorCode& status) const;
353 void setPatternForCurrencySpacing(UCurrencySpacing type,
354 UBool beforeCurrency,
355 const UnicodeString& pattern);
356
362 virtual UClassID getDynamicClassID() const override;
363
369 static UClassID U_EXPORT2 getStaticClassID();
370
371 private:
372 DecimalFormatSymbols();
373
386 void initialize(const Locale& locale, UErrorCode& success,
387 UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
388
392 void initialize();
393
394 public:
395
396 #ifndef U_HIDE_INTERNAL_API
397
400 inline UBool isCustomCurrencySymbol() const {
401 return fIsCustomCurrencySymbol;
402 }
403
407 inline UBool isCustomIntlCurrencySymbol() const {
408 return fIsCustomIntlCurrencySymbol;
409 }
410
414 inline UChar32 getCodePointZero() const {
415 return fCodePointZero;
416 }
417 #endif /* U_HIDE_INTERNAL_API */
418
434 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
435
436 #ifndef U_HIDE_INTERNAL_API
437
452 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
453
458 inline const char16_t* getCurrencyPattern(void) const;
459 #endif /* U_HIDE_INTERNAL_API */
460
461 private:
476 UnicodeString fSymbols[kFormatSymbolCount];
477
481 UnicodeString fNoSymbol;
482
497 UChar32 fCodePointZero;
498
499 Locale locale;
500
501 char actualLocale[ULOC_FULLNAME_CAPACITY];
502 char validLocale[ULOC_FULLNAME_CAPACITY];
503 const char16_t* currPattern;
504
505 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
506 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
507 UBool fIsCustomCurrencySymbol;
508 UBool fIsCustomIntlCurrencySymbol;
509 };
510
511 // -------------------------------------
512
513 inline UnicodeString
514 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
515 const UnicodeString *strPtr;
516 if(symbol < kFormatSymbolCount) {
517 strPtr = &fSymbols[symbol];
518 } else {
519 strPtr = &fNoSymbol;
520 }
521 return *strPtr;
522 }
523
524 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
525 inline const UnicodeString &
526 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
527 const UnicodeString *strPtr;
528 if(symbol < kFormatSymbolCount) {
529 strPtr = &fSymbols[symbol];
530 } else {
531 strPtr = &fNoSymbol;
532 }
533 return *strPtr;
534 }
535
536 #ifndef U_HIDE_INTERNAL_API
537 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
538 if (digit < 0 || digit > 9) {
539 digit = 0;
540 }
541 if (digit == 0) {
542 return fSymbols[kZeroDigitSymbol];
543 }
544 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
545 return fSymbols[key];
546 }
547 #endif /* U_HIDE_INTERNAL_API */
548
549 // -------------------------------------
550
551 inline void
552 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) {
553 if (symbol == kCurrencySymbol) {
554 fIsCustomCurrencySymbol = true;
555 }
556 else if (symbol == kIntlCurrencySymbol) {
557 fIsCustomIntlCurrencySymbol = true;
558 }
559 if(symbol<kFormatSymbolCount) {
560 fSymbols[symbol]=value;
561 }
562
563 // If the zero digit is being set to a known zero digit according to Unicode,
564 // then we automatically set the corresponding 1-9 digits
565 // Also record updates to fCodePointZero. Be conservative if in doubt.
566 if (symbol == kZeroDigitSymbol) {
567 UChar32 sym = value.char32At(0);
568 if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
569 fCodePointZero = sym;
570 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
571 sym++;
572 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
573 }
574 } else {
575 fCodePointZero = -1;
576 }
577 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
578 fCodePointZero = -1;
579 }
580 }
581
582 // -------------------------------------
583
584 inline Locale
585 DecimalFormatSymbols::getLocale() const {
586 return locale;
587 }
588
589 #ifndef U_HIDE_INTERNAL_API
590 inline const char16_t*
591 DecimalFormatSymbols::getCurrencyPattern() const {
592 return currPattern;
593 }
594 #endif /* U_HIDE_INTERNAL_API */
595
596 U_NAMESPACE_END
597
598 #endif /* #if !UCONFIG_NO_FORMATTING */
599
600 #endif /* U_SHOW_CPLUSPLUS_API */
601
602 #endif // _DCFMTSYM
603 //eof
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
icu::DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition: dcfmtsym.h:131
icu::DecimalFormatSymbols::kNaNSymbol
@ kNaNSymbol
Nan symbol.
Definition: dcfmtsym.h:124
icu::DecimalFormatSymbols::kExponentialSymbol
@ kExponentialSymbol
The exponential symbol.
Definition: dcfmtsym.h:116
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UNUM_CURRENCY_SPACING_COUNT
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:364
icu::DecimalFormatSymbols::kDigitSymbol
@ kDigitSymbol
Character representing a digit in the pattern.
Definition: dcfmtsym.h:104
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition: dcfmtsym.h:171
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::DecimalFormatSymbols::kFiveDigitSymbol
@ kFiveDigitSymbol
Five.
Definition: dcfmtsym.h:151
icu::DecimalFormatSymbols::kPlusSignSymbol
@ kPlusSignSymbol
The plus sign.
Definition: dcfmtsym.h:108
icu::DecimalFormatSymbols::kSevenDigitSymbol
@ kSevenDigitSymbol
Seven.
Definition: dcfmtsym.h:159
icu::DecimalFormatSymbols::isCustomCurrencySymbol
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:400
icu::DecimalFormatSymbols::kMinusSignSymbol
@ kMinusSignSymbol
The minus sign.
Definition: dcfmtsym.h:106
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
icu::DecimalFormatSymbols::kSixDigitSymbol
@ kSixDigitSymbol
Six.
Definition: dcfmtsym.h:155
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
@ kPatternSeparatorSymbol
The pattern separator.
Definition: dcfmtsym.h:98
unum.h
C API: Compatibility APIs for number formatting.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::DecimalFormatSymbols::kEightDigitSymbol
@ kEightDigitSymbol
Eight.
Definition: dcfmtsym.h:163
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:467
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
@ kGroupingSeparatorSymbol
The grouping separator.
Definition: dcfmtsym.h:96
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::DecimalFormatSymbols::kZeroDigitSymbol
@ kZeroDigitSymbol
Zero.
Definition: dcfmtsym.h:102
icu::DecimalFormatSymbols::kNineDigitSymbol
@ kNineDigitSymbol
Nine.
Definition: dcfmtsym.h:167
UCurrencySpacing
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:349
icu::DecimalFormatSymbols::operator!=
bool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:273
icu::DecimalFormatSymbols::kTwoDigitSymbol
@ kTwoDigitSymbol
Two.
Definition: dcfmtsym.h:139
numsys.h
C++ API: NumberingSystem object.
icu::DecimalFormatSymbols::kThreeDigitSymbol
@ kThreeDigitSymbol
Three.
Definition: dcfmtsym.h:143
icu::DecimalFormatSymbols::kApproximatelySignSymbol
@ kApproximatelySignSymbol
Approximately sign.
Definition: dcfmtsym.h:176
icu::DecimalFormatSymbols::kMonetarySeparatorSymbol
@ kMonetarySeparatorSymbol
The monetary separator.
Definition: dcfmtsym.h:114
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::isCustomIntlCurrencySymbol
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:407
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::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
icu::DecimalFormatSymbols::getCodePointZero
UChar32 getCodePointZero() const
Definition: dcfmtsym.h:414
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:92
u_charDigitValue
U_CAPI int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
icu::DecimalFormatSymbols::kFourDigitSymbol
@ kFourDigitSymbol
Four.
Definition: dcfmtsym.h:147
icu::DecimalFormatSymbols::kDecimalSeparatorSymbol
@ kDecimalSeparatorSymbol
The decimal separator.
Definition: dcfmtsym.h:94
uchar.h
C API: Unicode Properties.
UChar
char16_t UChar
Definition: umachine.h:418
locid.h
C++ API: Locale ID object.
icu::DecimalFormatSymbols::kPercentSymbol
@ kPercentSymbol
The percent sign.
Definition: dcfmtsym.h:100
icu::DecimalFormatSymbols::kInfinitySymbol
@ kInfinitySymbol
Infinity symbol.
Definition: dcfmtsym.h:122
uobject.h
C++ API: Common ICU base class UObject.
icu::DecimalFormatSymbols::kSignificantDigitSymbol
@ kSignificantDigitSymbol
Significant digit symbol.
Definition: dcfmtsym.h:127
icu::DecimalFormatSymbols::kIntlCurrencySymbol
@ kIntlCurrencySymbol
The international currency symbol.
Definition: dcfmtsym.h:112
icu::DecimalFormatSymbols::kPerMillSymbol
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition: dcfmtsym.h:118
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::DecimalFormatSymbols::kCurrencySymbol
@ kCurrencySymbol
The currency symbol.
Definition: dcfmtsym.h:110
unistr.h
C++ API: Unicode String.
icu::DecimalFormatSymbols::kPadEscapeSymbol
@ kPadEscapeSymbol
Escape padding character.
Definition: dcfmtsym.h:120
icu::DecimalFormatSymbols::kOneDigitSymbol
@ kOneDigitSymbol
One.
Definition: dcfmtsym.h:135