ICU 77.1 77.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
51 class CharString;
87 class U_I18N_API DecimalFormatSymbols : public UObject {
88 public:
93 enum ENumberFormatSymbol {
95 kDecimalSeparatorSymbol,
97 kGroupingSeparatorSymbol,
99 kPatternSeparatorSymbol,
101 kPercentSymbol,
103 kZeroDigitSymbol,
105 kDigitSymbol,
107 kMinusSignSymbol,
109 kPlusSignSymbol,
111 kCurrencySymbol,
113 kIntlCurrencySymbol,
115 kMonetarySeparatorSymbol,
117 kExponentialSymbol,
119 kPerMillSymbol,
121 kPadEscapeSymbol,
123 kInfinitySymbol,
125 kNaNSymbol,
128 kSignificantDigitSymbol,
132 kMonetaryGroupingSeparatorSymbol,
136 kOneDigitSymbol,
140 kTwoDigitSymbol,
144 kThreeDigitSymbol,
148 kFourDigitSymbol,
152 kFiveDigitSymbol,
156 kSixDigitSymbol,
160 kSevenDigitSymbol,
164 kEightDigitSymbol,
168 kNineDigitSymbol,
172 kExponentMultiplicationSymbol,
173 #ifndef U_HIDE_INTERNAL_API
177 kApproximatelySignSymbol,
178 #endif /* U_HIDE_INTERNAL_API */
180 kFormatSymbolCount = kExponentMultiplicationSymbol + 2
181 };
182
191 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
192
209 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
210
221 DecimalFormatSymbols(UErrorCode& status);
222
238 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
239
244 DecimalFormatSymbols(const DecimalFormatSymbols&);
245
250 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
251
256 virtual ~DecimalFormatSymbols();
257
265 bool operator==(const DecimalFormatSymbols& other) const;
266
274 bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
275
285 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
286
299 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits);
300
301 #ifndef U_HIDE_INTERNAL_API
309 void setCurrency(const char16_t* currency, UErrorCode& status);
310 #endif // U_HIDE_INTERNAL_API
311
316 inline Locale getLocale() const;
317
323 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
324
341 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
342 UBool beforeCurrency,
343 UErrorCode& status) const;
354 void setPatternForCurrencySpacing(UCurrencySpacing type,
355 UBool beforeCurrency,
356 const UnicodeString& pattern);
357
363 virtual UClassID getDynamicClassID() const override;
364
370 static UClassID U_EXPORT2 getStaticClassID();
371
372 private:
373 DecimalFormatSymbols();
374
387 void initialize(const Locale& locale, UErrorCode& success,
388 UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
389
393 void initialize();
394
395 public:
396
397 #ifndef U_HIDE_INTERNAL_API
401 inline UBool isCustomCurrencySymbol() const {
402 return fIsCustomCurrencySymbol;
403 }
404
408 inline UBool isCustomIntlCurrencySymbol() const {
409 return fIsCustomIntlCurrencySymbol;
410 }
411
415 inline UChar32 getCodePointZero() const {
416 return fCodePointZero;
417 }
418 #endif /* U_HIDE_INTERNAL_API */
419
435 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
436
437 #ifndef U_HIDE_INTERNAL_API
453 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
454
459 inline const char16_t* getCurrencyPattern() const;
460
465 inline const char* getNumberingSystemName() const;
466 #endif /* U_HIDE_INTERNAL_API */
467
468 private:
483 UnicodeString fSymbols[kFormatSymbolCount];
484
488 UnicodeString fNoSymbol;
489
504 UChar32 fCodePointZero;
505
506 Locale locale;
507
508 CharString* actualLocale = nullptr;
509 CharString* validLocale = nullptr;
510 const char16_t* currPattern = nullptr;
511
512 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
513 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
514 UBool fIsCustomCurrencySymbol;
515 UBool fIsCustomIntlCurrencySymbol;
516 char nsName[kInternalNumSysNameCapacity+1] = {};
517 };
518
519 // -------------------------------------
520
521 inline UnicodeString
522 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
523 const UnicodeString *strPtr;
524 if(symbol < kFormatSymbolCount) {
525 strPtr = &fSymbols[symbol];
526 } else {
527 strPtr = &fNoSymbol;
528 }
529 return *strPtr;
530 }
531
532 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
533 inline const UnicodeString &
534 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
535 const UnicodeString *strPtr;
536 if(symbol < kFormatSymbolCount) {
537 strPtr = &fSymbols[symbol];
538 } else {
539 strPtr = &fNoSymbol;
540 }
541 return *strPtr;
542 }
543
544 #ifndef U_HIDE_INTERNAL_API
545 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
546 if (digit < 0 || digit > 9) {
547 digit = 0;
548 }
549 if (digit == 0) {
550 return fSymbols[kZeroDigitSymbol];
551 }
552 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
553 return fSymbols[key];
554 }
555 #endif /* U_HIDE_INTERNAL_API */
556
557 // -------------------------------------
558
559 inline void
560 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) {
561 if (symbol == kCurrencySymbol) {
562 fIsCustomCurrencySymbol = true;
563 }
564 else if (symbol == kIntlCurrencySymbol) {
565 fIsCustomIntlCurrencySymbol = true;
566 }
567 if(symbol<kFormatSymbolCount) {
568 fSymbols[symbol]=value;
569 }
570
571 // If the zero digit is being set to a known zero digit according to Unicode,
572 // then we automatically set the corresponding 1-9 digits
573 // Also record updates to fCodePointZero. Be conservative if in doubt.
574 if (symbol == kZeroDigitSymbol) {
575 UChar32 sym = value.char32At(0);
576 if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
577 fCodePointZero = sym;
578 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
579 sym++;
580 fSymbols[static_cast<int>(kOneDigitSymbol) + i - 1] = UnicodeString(sym);
581 }
582 } else {
583 fCodePointZero = -1;
584 }
585 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
586 fCodePointZero = -1;
587 }
588 }
589
590 // -------------------------------------
591
592 inline Locale
593 DecimalFormatSymbols::getLocale() const {
594 return locale;
595 }
596
597 #ifndef U_HIDE_INTERNAL_API
598 inline const char16_t*
599 DecimalFormatSymbols::getCurrencyPattern() const {
600 return currPattern;
601 }
602 inline const char*
603 DecimalFormatSymbols::getNumberingSystemName() const {
604 return nsName;
605 }
606 #endif /* U_HIDE_INTERNAL_API */
607
608 U_NAMESPACE_END
609
610 #endif /* #if !UCONFIG_NO_FORMATTING */
611
612 #endif /* U_SHOW_CPLUSPLUS_API */
613
614 #endif // _DCFMTSYM
615 //eof
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:87
icu::DecimalFormatSymbols::setPatternForCurrencySpacing
void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::isCustomCurrencySymbol
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:401
icu::DecimalFormatSymbols::operator==
bool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
icu::DecimalFormatSymbols::~DecimalFormatSymbols
virtual ~DecimalFormatSymbols()
Destructor.
icu::DecimalFormatSymbols::getPatternForCurrencySpacing
const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:93
icu::DecimalFormatSymbols::kEightDigitSymbol
@ kEightDigitSymbol
Eight.
Definition: dcfmtsym.h:164
icu::DecimalFormatSymbols::kThreeDigitSymbol
@ kThreeDigitSymbol
Three.
Definition: dcfmtsym.h:144
icu::DecimalFormatSymbols::kDecimalSeparatorSymbol
@ kDecimalSeparatorSymbol
The decimal separator.
Definition: dcfmtsym.h:95
icu::DecimalFormatSymbols::kNineDigitSymbol
@ kNineDigitSymbol
Nine.
Definition: dcfmtsym.h:168
icu::DecimalFormatSymbols::kPlusSignSymbol
@ kPlusSignSymbol
The plus sign.
Definition: dcfmtsym.h:109
icu::DecimalFormatSymbols::kMinusSignSymbol
@ kMinusSignSymbol
The minus sign.
Definition: dcfmtsym.h:107
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition: dcfmtsym.h:172
icu::DecimalFormatSymbols::kInfinitySymbol
@ kInfinitySymbol
Infinity symbol.
Definition: dcfmtsym.h:123
icu::DecimalFormatSymbols::kExponentialSymbol
@ kExponentialSymbol
The exponential symbol.
Definition: dcfmtsym.h:117
icu::DecimalFormatSymbols::kPerMillSymbol
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition: dcfmtsym.h:119
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
@ kPatternSeparatorSymbol
The pattern separator.
Definition: dcfmtsym.h:99
icu::DecimalFormatSymbols::kCurrencySymbol
@ kCurrencySymbol
The currency symbol.
Definition: dcfmtsym.h:111
icu::DecimalFormatSymbols::kSixDigitSymbol
@ kSixDigitSymbol
Six.
Definition: dcfmtsym.h:156
icu::DecimalFormatSymbols::kTwoDigitSymbol
@ kTwoDigitSymbol
Two.
Definition: dcfmtsym.h:140
icu::DecimalFormatSymbols::kFiveDigitSymbol
@ kFiveDigitSymbol
Five.
Definition: dcfmtsym.h:152
icu::DecimalFormatSymbols::kSignificantDigitSymbol
@ kSignificantDigitSymbol
Significant digit symbol.
Definition: dcfmtsym.h:128
icu::DecimalFormatSymbols::kIntlCurrencySymbol
@ kIntlCurrencySymbol
The international currency symbol.
Definition: dcfmtsym.h:113
icu::DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition: dcfmtsym.h:132
icu::DecimalFormatSymbols::kSevenDigitSymbol
@ kSevenDigitSymbol
Seven.
Definition: dcfmtsym.h:160
icu::DecimalFormatSymbols::kPadEscapeSymbol
@ kPadEscapeSymbol
Escape padding character.
Definition: dcfmtsym.h:121
icu::DecimalFormatSymbols::kPercentSymbol
@ kPercentSymbol
The percent sign.
Definition: dcfmtsym.h:101
icu::DecimalFormatSymbols::kNaNSymbol
@ kNaNSymbol
Nan symbol.
Definition: dcfmtsym.h:125
icu::DecimalFormatSymbols::kApproximatelySignSymbol
@ kApproximatelySignSymbol
Approximately sign.
Definition: dcfmtsym.h:177
icu::DecimalFormatSymbols::kDigitSymbol
@ kDigitSymbol
Character representing a digit in the pattern.
Definition: dcfmtsym.h:105
icu::DecimalFormatSymbols::kMonetarySeparatorSymbol
@ kMonetarySeparatorSymbol
The monetary separator.
Definition: dcfmtsym.h:115
icu::DecimalFormatSymbols::kZeroDigitSymbol
@ kZeroDigitSymbol
Zero.
Definition: dcfmtsym.h:103
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
@ kGroupingSeparatorSymbol
The grouping separator.
Definition: dcfmtsym.h:97
icu::DecimalFormatSymbols::kOneDigitSymbol
@ kOneDigitSymbol
One.
Definition: dcfmtsym.h:136
icu::DecimalFormatSymbols::kFourDigitSymbol
@ kFourDigitSymbol
Four.
Definition: dcfmtsym.h:148
icu::DecimalFormatSymbols::getLocale
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
icu::DecimalFormatSymbols::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::DecimalFormatSymbols::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
icu::DecimalFormatSymbols::setCurrency
void setCurrency(const char16_t *currency, UErrorCode &status)
Loads symbols for the specified currency into this instance.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
icu::DecimalFormatSymbols::operator!=
bool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:274
icu::DecimalFormatSymbols::createWithLastResortData
static DecimalFormatSymbols * createWithLastResortData(UErrorCode &status)
Creates a DecimalFormatSymbols object with last-resort data.
icu::DecimalFormatSymbols::getCodePointZero
UChar32 getCodePointZero() const
Definition: dcfmtsym.h:415
icu::DecimalFormatSymbols::operator=
DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(const Locale &locale, const NumberingSystem &ns, UErrorCode &status)
Creates a DecimalFormatSymbols instance for the given locale with digits and symbols corresponding to...
icu::DecimalFormatSymbols::isCustomIntlCurrencySymbol
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:408
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
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.
locid.h
C++ API: Locale ID object.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::kInternalNumSysNameCapacity
constexpr const size_t kInternalNumSysNameCapacity
Size of a numbering system name.
Definition: numsys.h:42
numsys.h
C++ API: NumberingSystem object.
uchar.h
C API: Unicode Properties.
u_charDigitValue
U_CAPI int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:427
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
unum.h
C API: Compatibility APIs for number formatting.
UCurrencySpacing
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:301
UNUM_CURRENCY_SPACING_COUNT
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:316
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:316