00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef DCFMTSYM_H
00028 #define DCFMTSYM_H
00029
00030 #include "unicode/utypes.h"
00031
00032 #if U_SHOW_CPLUSPLUS_API
00033
00034 #if !UCONFIG_NO_FORMATTING
00035
00036 #include "unicode/uchar.h"
00037 #include "unicode/uobject.h"
00038 #include "unicode/locid.h"
00039 #include "unicode/numsys.h"
00040 #include "unicode/unum.h"
00041 #include "unicode/unistr.h"
00042
00049 U_NAMESPACE_BEGIN
00050
00086 class U_I18N_API DecimalFormatSymbols : public UObject {
00087 public:
00092 enum ENumberFormatSymbol {
00094 kDecimalSeparatorSymbol,
00096 kGroupingSeparatorSymbol,
00098 kPatternSeparatorSymbol,
00100 kPercentSymbol,
00102 kZeroDigitSymbol,
00104 kDigitSymbol,
00106 kMinusSignSymbol,
00108 kPlusSignSymbol,
00110 kCurrencySymbol,
00112 kIntlCurrencySymbol,
00114 kMonetarySeparatorSymbol,
00116 kExponentialSymbol,
00118 kPerMillSymbol,
00120 kPadEscapeSymbol,
00122 kInfinitySymbol,
00124 kNaNSymbol,
00127 kSignificantDigitSymbol,
00131 kMonetaryGroupingSeparatorSymbol,
00135 kOneDigitSymbol,
00139 kTwoDigitSymbol,
00143 kThreeDigitSymbol,
00147 kFourDigitSymbol,
00151 kFiveDigitSymbol,
00155 kSixDigitSymbol,
00159 kSevenDigitSymbol,
00163 kEightDigitSymbol,
00167 kNineDigitSymbol,
00171 kExponentMultiplicationSymbol,
00172 #ifndef U_HIDE_INTERNAL_API
00173
00176 kApproximatelySignSymbol,
00177 #endif
00178
00179 kFormatSymbolCount = kExponentMultiplicationSymbol + 2
00180 };
00181
00190 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00191
00208 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
00209
00220 DecimalFormatSymbols(UErrorCode& status);
00221
00237 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
00238
00243 DecimalFormatSymbols(const DecimalFormatSymbols&);
00244
00249 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00250
00255 virtual ~DecimalFormatSymbols();
00256
00264 bool operator==(const DecimalFormatSymbols& other) const;
00265
00273 bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00274
00284 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00285
00298 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits);
00299
00300 #ifndef U_HIDE_INTERNAL_API
00301
00308 void setCurrency(const UChar* currency, UErrorCode& status);
00309 #endif // U_HIDE_INTERNAL_API
00310
00315 inline Locale getLocale() const;
00316
00322 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00323
00340 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00341 UBool beforeCurrency,
00342 UErrorCode& status) const;
00353 void setPatternForCurrencySpacing(UCurrencySpacing type,
00354 UBool beforeCurrency,
00355 const UnicodeString& pattern);
00356
00362 virtual UClassID getDynamicClassID() const override;
00363
00369 static UClassID U_EXPORT2 getStaticClassID();
00370
00371 private:
00372 DecimalFormatSymbols();
00373
00386 void initialize(const Locale& locale, UErrorCode& success,
00387 UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
00388
00392 void initialize();
00393
00394 public:
00395
00396 #ifndef U_HIDE_INTERNAL_API
00397
00400 inline UBool isCustomCurrencySymbol() const {
00401 return fIsCustomCurrencySymbol;
00402 }
00403
00407 inline UBool isCustomIntlCurrencySymbol() const {
00408 return fIsCustomIntlCurrencySymbol;
00409 }
00410
00414 inline UChar32 getCodePointZero() const {
00415 return fCodePointZero;
00416 }
00417 #endif
00418
00434 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
00435
00436 #ifndef U_HIDE_INTERNAL_API
00437
00452 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
00453
00458 inline const char16_t* getCurrencyPattern(void) const;
00459 #endif
00460
00461 private:
00476 UnicodeString fSymbols[kFormatSymbolCount];
00477
00481 UnicodeString fNoSymbol;
00482
00497 UChar32 fCodePointZero;
00498
00499 Locale locale;
00500
00501 char actualLocale[ULOC_FULLNAME_CAPACITY];
00502 char validLocale[ULOC_FULLNAME_CAPACITY];
00503 const char16_t* currPattern;
00504
00505 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00506 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00507 UBool fIsCustomCurrencySymbol;
00508 UBool fIsCustomIntlCurrencySymbol;
00509 };
00510
00511
00512
00513 inline UnicodeString
00514 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00515 const UnicodeString *strPtr;
00516 if(symbol < kFormatSymbolCount) {
00517 strPtr = &fSymbols[symbol];
00518 } else {
00519 strPtr = &fNoSymbol;
00520 }
00521 return *strPtr;
00522 }
00523
00524
00525 inline const UnicodeString &
00526 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00527 const UnicodeString *strPtr;
00528 if(symbol < kFormatSymbolCount) {
00529 strPtr = &fSymbols[symbol];
00530 } else {
00531 strPtr = &fNoSymbol;
00532 }
00533 return *strPtr;
00534 }
00535
00536 #ifndef U_HIDE_INTERNAL_API
00537 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
00538 if (digit < 0 || digit > 9) {
00539 digit = 0;
00540 }
00541 if (digit == 0) {
00542 return fSymbols[kZeroDigitSymbol];
00543 }
00544 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
00545 return fSymbols[key];
00546 }
00547 #endif
00548
00549
00550
00551 inline void
00552 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) {
00553 if (symbol == kCurrencySymbol) {
00554 fIsCustomCurrencySymbol = true;
00555 }
00556 else if (symbol == kIntlCurrencySymbol) {
00557 fIsCustomIntlCurrencySymbol = true;
00558 }
00559 if(symbol<kFormatSymbolCount) {
00560 fSymbols[symbol]=value;
00561 }
00562
00563
00564
00565
00566 if (symbol == kZeroDigitSymbol) {
00567 UChar32 sym = value.char32At(0);
00568 if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
00569 fCodePointZero = sym;
00570 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00571 sym++;
00572 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00573 }
00574 } else {
00575 fCodePointZero = -1;
00576 }
00577 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
00578 fCodePointZero = -1;
00579 }
00580 }
00581
00582
00583
00584 inline Locale
00585 DecimalFormatSymbols::getLocale() const {
00586 return locale;
00587 }
00588
00589 #ifndef U_HIDE_INTERNAL_API
00590 inline const char16_t*
00591 DecimalFormatSymbols::getCurrencyPattern() const {
00592 return currPattern;
00593 }
00594 #endif
00595
00596 U_NAMESPACE_END
00597
00598 #endif
00599
00600 #endif
00601
00602 #endif // _DCFMTSYM
00603