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
00294 #ifndef U_HIDE_INTERNAL_API
00295
00302 void setCurrency(const UChar* currency, UErrorCode& status);
00303 #endif // U_HIDE_INTERNAL_API
00304
00309 inline Locale getLocale() const;
00310
00316 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00317
00334 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00335 UBool beforeCurrency,
00336 UErrorCode& status) const;
00347 void setPatternForCurrencySpacing(UCurrencySpacing type,
00348 UBool beforeCurrency,
00349 const UnicodeString& pattern);
00350
00356 virtual UClassID getDynamicClassID() const;
00357
00363 static UClassID U_EXPORT2 getStaticClassID();
00364
00365 private:
00366 DecimalFormatSymbols();
00367
00380 void initialize(const Locale& locale, UErrorCode& success,
00381 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
00382
00386 void initialize();
00387
00388 public:
00389
00390 #ifndef U_HIDE_INTERNAL_API
00391
00394 inline UBool isCustomCurrencySymbol() const {
00395 return fIsCustomCurrencySymbol;
00396 }
00397
00401 inline UBool isCustomIntlCurrencySymbol() const {
00402 return fIsCustomIntlCurrencySymbol;
00403 }
00404
00408 inline UChar32 getCodePointZero() const {
00409 return fCodePointZero;
00410 }
00411 #endif
00412
00428 inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
00429
00430 #ifndef U_HIDE_INTERNAL_API
00431
00446 inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
00447
00452 inline const char16_t* getCurrencyPattern(void) const;
00453 #endif
00454
00455 private:
00470 UnicodeString fSymbols[kFormatSymbolCount];
00471
00475 UnicodeString fNoSymbol;
00476
00491 UChar32 fCodePointZero;
00492
00493 Locale locale;
00494
00495 char actualLocale[ULOC_FULLNAME_CAPACITY];
00496 char validLocale[ULOC_FULLNAME_CAPACITY];
00497 const char16_t* currPattern;
00498
00499 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00500 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00501 UBool fIsCustomCurrencySymbol;
00502 UBool fIsCustomIntlCurrencySymbol;
00503 };
00504
00505
00506
00507 inline UnicodeString
00508 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00509 const UnicodeString *strPtr;
00510 if(symbol < kFormatSymbolCount) {
00511 strPtr = &fSymbols[symbol];
00512 } else {
00513 strPtr = &fNoSymbol;
00514 }
00515 return *strPtr;
00516 }
00517
00518
00519 inline const UnicodeString &
00520 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00521 const UnicodeString *strPtr;
00522 if(symbol < kFormatSymbolCount) {
00523 strPtr = &fSymbols[symbol];
00524 } else {
00525 strPtr = &fNoSymbol;
00526 }
00527 return *strPtr;
00528 }
00529
00530 #ifndef U_HIDE_INTERNAL_API
00531 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
00532 if (digit < 0 || digit > 9) {
00533 digit = 0;
00534 }
00535 if (digit == 0) {
00536 return fSymbols[kZeroDigitSymbol];
00537 }
00538 ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
00539 return fSymbols[key];
00540 }
00541 #endif
00542
00543
00544
00545 inline void
00546 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00547 if (symbol == kCurrencySymbol) {
00548 fIsCustomCurrencySymbol = TRUE;
00549 }
00550 else if (symbol == kIntlCurrencySymbol) {
00551 fIsCustomIntlCurrencySymbol = TRUE;
00552 }
00553 if(symbol<kFormatSymbolCount) {
00554 fSymbols[symbol]=value;
00555 }
00556
00557
00558
00559
00560 if (symbol == kZeroDigitSymbol) {
00561 UChar32 sym = value.char32At(0);
00562 if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
00563 fCodePointZero = sym;
00564 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00565 sym++;
00566 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00567 }
00568 } else {
00569 fCodePointZero = -1;
00570 }
00571 } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
00572 fCodePointZero = -1;
00573 }
00574 }
00575
00576
00577
00578 inline Locale
00579 DecimalFormatSymbols::getLocale() const {
00580 return locale;
00581 }
00582
00583 #ifndef U_HIDE_INTERNAL_API
00584 inline const char16_t*
00585 DecimalFormatSymbols::getCurrencyPattern() const {
00586 return currPattern;
00587 }
00588 #endif
00589
00590 U_NAMESPACE_END
00591
00592 #endif
00593
00594 #endif
00595
00596 #endif // _DCFMTSYM
00597