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,
00173 kFormatSymbolCount = kNineDigitSymbol + 2
00174 };
00175
00184 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00185
00202 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
00203
00214 DecimalFormatSymbols(UErrorCode& status);
00215
00231 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
00232
00237 DecimalFormatSymbols(const DecimalFormatSymbols&);
00238
00243 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00244
00249 virtual ~DecimalFormatSymbols();
00250
00258 UBool operator==(const DecimalFormatSymbols& other) const;
00259
00267 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00268
00278 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00279
00292 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
00293
00298 inline Locale getLocale() const;
00299
00305 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00306
00323 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00324 UBool beforeCurrency,
00325 UErrorCode& status) const;
00336 void setPatternForCurrencySpacing(UCurrencySpacing type,
00337 UBool beforeCurrency,
00338 const UnicodeString& pattern);
00339
00345 virtual UClassID getDynamicClassID() const;
00346
00352 static UClassID U_EXPORT2 getStaticClassID();
00353
00354 private:
00355 DecimalFormatSymbols();
00356
00369 void initialize(const Locale& locale, UErrorCode& success,
00370 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
00371
00375 void initialize();
00376
00377 void setCurrencyForSymbols();
00378
00379 public:
00380
00381 #ifndef U_HIDE_INTERNAL_API
00382
00385 inline UBool isCustomCurrencySymbol() const {
00386 return fIsCustomCurrencySymbol;
00387 }
00388
00392 inline UBool isCustomIntlCurrencySymbol() const {
00393 return fIsCustomIntlCurrencySymbol;
00394 }
00395
00399 inline UChar32 getCodePointZero() const {
00400 return fCodePointZero;
00401 }
00402 #endif
00403
00419 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
00420
00421 #ifndef U_HIDE_INTERNAL_API
00422
00437 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
00438
00443 inline const char16_t* getCurrencyPattern(void) const;
00444 #endif
00445
00446 private:
00461 UnicodeString fSymbols[kFormatSymbolCount];
00462
00466 UnicodeString fNoSymbol;
00467
00482 UChar32 fCodePointZero;
00483
00484 Locale locale;
00485
00486 char actualLocale[ULOC_FULLNAME_CAPACITY];
00487 char validLocale[ULOC_FULLNAME_CAPACITY];
00488 const char16_t* currPattern;
00489
00490 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00491 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00492 UBool fIsCustomCurrencySymbol;
00493 UBool fIsCustomIntlCurrencySymbol;
00494 };
00495
00496
00497
00498 inline UnicodeString
00499 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00500 const UnicodeString *strPtr;
00501 if(symbol < kFormatSymbolCount) {
00502 strPtr = &fSymbols[symbol];
00503 } else {
00504 strPtr = &fNoSymbol;
00505 }
00506 return *strPtr;
00507 }
00508
00509
00510 inline const UnicodeString &
00511 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00512 const UnicodeString *strPtr;
00513 if(symbol < kFormatSymbolCount) {
00514 strPtr = &fSymbols[symbol];
00515 } else {
00516 strPtr = &fNoSymbol;
00517 }
00518 return *strPtr;
00519 }
00520
00521 #ifndef U_HIDE_INTERNAL_API
00522 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
00523 if (digit < 0 || digit > 9) {
00524 digit = 0;
00525 }
00526 if (digit == 0) {
00527 return fSymbols[kZeroDigitSymbol];
00528 }
00529 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
00530 return fSymbols[key];
00531 }
00532 #endif
00533
00534
00535
00536 inline void
00537 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00538 if (symbol == kCurrencySymbol) {
00539 fIsCustomCurrencySymbol = TRUE;
00540 }
00541 else if (symbol == kIntlCurrencySymbol) {
00542 fIsCustomIntlCurrencySymbol = TRUE;
00543 }
00544 if(symbol<kFormatSymbolCount) {
00545 fSymbols[symbol]=value;
00546 }
00547
00548
00549
00550
00551 if (symbol == kZeroDigitSymbol) {
00552 UChar32 sym = value.char32At(0);
00553 if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
00554 fCodePointZero = sym;
00555 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00556 sym++;
00557 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00558 }
00559 } else {
00560 fCodePointZero = -1;
00561 }
00562 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
00563 fCodePointZero = -1;
00564 }
00565 }
00566
00567
00568
00569 inline Locale
00570 DecimalFormatSymbols::getLocale() const {
00571 return locale;
00572 }
00573
00574 #ifndef U_HIDE_INTERNAL_API
00575 inline const char16_t*
00576 DecimalFormatSymbols::getCurrencyPattern() const {
00577 return currPattern;
00578 }
00579 #endif
00580
00581 U_NAMESPACE_END
00582
00583 #endif
00584
00585 #endif
00586
00587 #endif // _DCFMTSYM
00588