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 #ifndef DCFMTSYM_H
00026 #define DCFMTSYM_H
00027
00028 #include "unicode/utypes.h"
00029 #include "unicode/uchar.h"
00030
00031 #if !UCONFIG_NO_FORMATTING
00032
00033 #include "unicode/uobject.h"
00034 #include "unicode/locid.h"
00035 #include "unicode/unum.h"
00036
00043 U_NAMESPACE_BEGIN
00044
00084 class U_I18N_API DecimalFormatSymbols : public UObject {
00085 public:
00090 enum ENumberFormatSymbol {
00092 kDecimalSeparatorSymbol,
00094 kGroupingSeparatorSymbol,
00096 kPatternSeparatorSymbol,
00098 kPercentSymbol,
00100 kZeroDigitSymbol,
00102 kDigitSymbol,
00104 kMinusSignSymbol,
00106 kPlusSignSymbol,
00108 kCurrencySymbol,
00110 kIntlCurrencySymbol,
00112 kMonetarySeparatorSymbol,
00114 kExponentialSymbol,
00116 kPerMillSymbol,
00118 kPadEscapeSymbol,
00120 kInfinitySymbol,
00122 kNaNSymbol,
00125 kSignificantDigitSymbol,
00129 kMonetaryGroupingSeparatorSymbol,
00133 kOneDigitSymbol,
00137 kTwoDigitSymbol,
00141 kThreeDigitSymbol,
00145 kFourDigitSymbol,
00149 kFiveDigitSymbol,
00153 kSixDigitSymbol,
00157 kSevenDigitSymbol,
00161 kEightDigitSymbol,
00165 kNineDigitSymbol,
00169 kExponentMultiplicationSymbol,
00171 kFormatSymbolCount = kNineDigitSymbol + 2
00172 };
00173
00182 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00183
00194 DecimalFormatSymbols(UErrorCode& status);
00195
00211 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
00212
00217 DecimalFormatSymbols(const DecimalFormatSymbols&);
00218
00223 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00224
00229 virtual ~DecimalFormatSymbols();
00230
00238 UBool operator==(const DecimalFormatSymbols& other) const;
00239
00247 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00248
00258 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00259
00272 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
00273
00278 inline Locale getLocale() const;
00279
00285 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00286
00303 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00304 UBool beforeCurrency,
00305 UErrorCode& status) const;
00316 void setPatternForCurrencySpacing(UCurrencySpacing type,
00317 UBool beforeCurrency,
00318 const UnicodeString& pattern);
00319
00325 virtual UClassID getDynamicClassID() const;
00326
00332 static UClassID U_EXPORT2 getStaticClassID();
00333
00334 private:
00335 DecimalFormatSymbols();
00336
00347 void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
00348
00352 void initialize();
00353
00354 void setCurrencyForSymbols();
00355
00356 public:
00357
00358 #ifndef U_HIDE_INTERNAL_API
00359
00362 inline UBool isCustomCurrencySymbol() const {
00363 return fIsCustomCurrencySymbol;
00364 }
00365
00369 inline UBool isCustomIntlCurrencySymbol() const {
00370 return fIsCustomIntlCurrencySymbol;
00371 }
00372 #endif
00373
00386 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
00387
00388 #ifndef U_HIDE_INTERNAL_API
00389
00393 inline const UChar* getCurrencyPattern(void) const;
00394 #endif
00395
00396 private:
00412 UnicodeString fSymbols[kFormatSymbolCount];
00413
00418 UnicodeString fNoSymbol;
00419
00420 Locale locale;
00421
00422 char actualLocale[ULOC_FULLNAME_CAPACITY];
00423 char validLocale[ULOC_FULLNAME_CAPACITY];
00424 const UChar* currPattern;
00425
00426 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00427 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00428 UBool fIsCustomCurrencySymbol;
00429 UBool fIsCustomIntlCurrencySymbol;
00430 };
00431
00432
00433
00434 inline UnicodeString
00435 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00436 const UnicodeString *strPtr;
00437 if(symbol < kFormatSymbolCount) {
00438 strPtr = &fSymbols[symbol];
00439 } else {
00440 strPtr = &fNoSymbol;
00441 }
00442 return *strPtr;
00443 }
00444
00445
00446 inline const UnicodeString &
00447 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00448 const UnicodeString *strPtr;
00449 if(symbol < kFormatSymbolCount) {
00450 strPtr = &fSymbols[symbol];
00451 } else {
00452 strPtr = &fNoSymbol;
00453 }
00454 return *strPtr;
00455 }
00456
00457
00458
00459 inline void
00460 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00461 if (symbol == kCurrencySymbol) {
00462 fIsCustomCurrencySymbol = TRUE;
00463 }
00464 else if (symbol == kIntlCurrencySymbol) {
00465 fIsCustomIntlCurrencySymbol = TRUE;
00466 }
00467 if(symbol<kFormatSymbolCount) {
00468 fSymbols[symbol]=value;
00469 }
00470
00471
00472
00473 if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
00474 UChar32 sym = value.char32At(0);
00475 if ( u_charDigitValue(sym) == 0 ) {
00476 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00477 sym++;
00478 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00479 }
00480 }
00481 }
00482 }
00483
00484
00485
00486 inline Locale
00487 DecimalFormatSymbols::getLocale() const {
00488 return locale;
00489 }
00490
00491 #ifndef U_HIDE_INTERNAL_API
00492 inline const UChar*
00493 DecimalFormatSymbols::getCurrencyPattern() const {
00494 return currPattern;
00495 }
00496 #endif
00497
00498 U_NAMESPACE_END
00499
00500 #endif
00501
00502 #endif // _DCFMTSYM
00503