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 #include "unicode/uchar.h"
00032
00033 #if !UCONFIG_NO_FORMATTING
00034
00035 #include "unicode/uobject.h"
00036 #include "unicode/locid.h"
00037 #include "unicode/numsys.h"
00038 #include "unicode/unum.h"
00039 #include "unicode/unistr.h"
00040
00047 U_NAMESPACE_BEGIN
00048
00088 class U_I18N_API DecimalFormatSymbols : public UObject {
00089 public:
00094 enum ENumberFormatSymbol {
00096 kDecimalSeparatorSymbol,
00098 kGroupingSeparatorSymbol,
00100 kPatternSeparatorSymbol,
00102 kPercentSymbol,
00104 kZeroDigitSymbol,
00106 kDigitSymbol,
00108 kMinusSignSymbol,
00110 kPlusSignSymbol,
00112 kCurrencySymbol,
00114 kIntlCurrencySymbol,
00116 kMonetarySeparatorSymbol,
00118 kExponentialSymbol,
00120 kPerMillSymbol,
00122 kPadEscapeSymbol,
00124 kInfinitySymbol,
00126 kNaNSymbol,
00129 kSignificantDigitSymbol,
00133 kMonetaryGroupingSeparatorSymbol,
00137 kOneDigitSymbol,
00141 kTwoDigitSymbol,
00145 kThreeDigitSymbol,
00149 kFourDigitSymbol,
00153 kFiveDigitSymbol,
00157 kSixDigitSymbol,
00161 kSevenDigitSymbol,
00165 kEightDigitSymbol,
00169 kNineDigitSymbol,
00173 kExponentMultiplicationSymbol,
00175 kFormatSymbolCount = kNineDigitSymbol + 2
00176 };
00177
00186 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00187
00188 #ifndef U_HIDE_DRAFT_API
00189
00205 DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
00206 #endif
00207
00218 DecimalFormatSymbols(UErrorCode& status);
00219
00235 static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
00236
00241 DecimalFormatSymbols(const DecimalFormatSymbols&);
00242
00247 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00248
00253 virtual ~DecimalFormatSymbols();
00254
00262 UBool operator==(const DecimalFormatSymbols& other) const;
00263
00271 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00272
00282 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00283
00296 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
00297
00302 inline Locale getLocale() const;
00303
00309 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00310
00327 const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00328 UBool beforeCurrency,
00329 UErrorCode& status) const;
00340 void setPatternForCurrencySpacing(UCurrencySpacing type,
00341 UBool beforeCurrency,
00342 const UnicodeString& pattern);
00343
00349 virtual UClassID getDynamicClassID() const;
00350
00356 static UClassID U_EXPORT2 getStaticClassID();
00357
00358 private:
00359 DecimalFormatSymbols();
00360
00373 void initialize(const Locale& locale, UErrorCode& success,
00374 UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
00375
00379 void initialize();
00380
00381 void setCurrencyForSymbols();
00382
00383 public:
00384
00385 #ifndef U_HIDE_INTERNAL_API
00386
00389 inline UBool isCustomCurrencySymbol() const {
00390 return fIsCustomCurrencySymbol;
00391 }
00392
00396 inline UBool isCustomIntlCurrencySymbol() const {
00397 return fIsCustomIntlCurrencySymbol;
00398 }
00399 #endif
00400
00413 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
00414
00415 #ifndef U_HIDE_INTERNAL_API
00416
00420 inline const char16_t* getCurrencyPattern(void) const;
00421 #endif
00422
00423 private:
00439 UnicodeString fSymbols[kFormatSymbolCount];
00440
00445 UnicodeString fNoSymbol;
00446
00447 Locale locale;
00448
00449 char actualLocale[ULOC_FULLNAME_CAPACITY];
00450 char validLocale[ULOC_FULLNAME_CAPACITY];
00451 const char16_t* currPattern;
00452
00453 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00454 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00455 UBool fIsCustomCurrencySymbol;
00456 UBool fIsCustomIntlCurrencySymbol;
00457 };
00458
00459
00460
00461 inline UnicodeString
00462 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00463 const UnicodeString *strPtr;
00464 if(symbol < kFormatSymbolCount) {
00465 strPtr = &fSymbols[symbol];
00466 } else {
00467 strPtr = &fNoSymbol;
00468 }
00469 return *strPtr;
00470 }
00471
00472
00473 inline const UnicodeString &
00474 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00475 const UnicodeString *strPtr;
00476 if(symbol < kFormatSymbolCount) {
00477 strPtr = &fSymbols[symbol];
00478 } else {
00479 strPtr = &fNoSymbol;
00480 }
00481 return *strPtr;
00482 }
00483
00484
00485
00486 inline void
00487 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00488 if (symbol == kCurrencySymbol) {
00489 fIsCustomCurrencySymbol = TRUE;
00490 }
00491 else if (symbol == kIntlCurrencySymbol) {
00492 fIsCustomIntlCurrencySymbol = TRUE;
00493 }
00494 if(symbol<kFormatSymbolCount) {
00495 fSymbols[symbol]=value;
00496 }
00497
00498
00499
00500 if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
00501 UChar32 sym = value.char32At(0);
00502 if ( u_charDigitValue(sym) == 0 ) {
00503 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00504 sym++;
00505 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00506 }
00507 }
00508 }
00509 }
00510
00511
00512
00513 inline Locale
00514 DecimalFormatSymbols::getLocale() const {
00515 return locale;
00516 }
00517
00518 #ifndef U_HIDE_INTERNAL_API
00519 inline const char16_t*
00520 DecimalFormatSymbols::getCurrencyPattern() const {
00521 return currPattern;
00522 }
00523 #endif
00524
00525 U_NAMESPACE_END
00526
00527 #endif
00528
00529 #endif // _DCFMTSYM
00530