ICU 4.6 4.6
|
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2010, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File DCFMTSYM.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 02/19/97 aliu Converted from java. 00013 * 03/18/97 clhuang Updated per C++ implementation. 00014 * 03/27/97 helena Updated to pass the simple test after code review. 00015 * 08/26/97 aliu Added currency/intl currency symbol support. 00016 * 07/22/98 stephen Changed to match C++ style 00017 * currencySymbol -> fCurrencySymbol 00018 * Constants changed from CAPS to kCaps 00019 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes 00020 * 09/22/00 grhoten Marked deprecation tags with a pointer to replacement 00021 * functions. 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 00042 U_NAMESPACE_BEGIN 00043 00083 class U_I18N_API DecimalFormatSymbols : public UObject { 00084 public: 00089 enum ENumberFormatSymbol { 00091 kDecimalSeparatorSymbol, 00093 kGroupingSeparatorSymbol, 00095 kPatternSeparatorSymbol, 00097 kPercentSymbol, 00099 kZeroDigitSymbol, 00101 kDigitSymbol, 00103 kMinusSignSymbol, 00105 kPlusSignSymbol, 00107 kCurrencySymbol, 00109 kIntlCurrencySymbol, 00111 kMonetarySeparatorSymbol, 00113 kExponentialSymbol, 00115 kPerMillSymbol, 00117 kPadEscapeSymbol, 00119 kInfinitySymbol, 00121 kNaNSymbol, 00124 kSignificantDigitSymbol, 00128 kMonetaryGroupingSeparatorSymbol, 00132 kOneDigitSymbol, 00136 kTwoDigitSymbol, 00140 kThreeDigitSymbol, 00144 kFourDigitSymbol, 00148 kFiveDigitSymbol, 00152 kSixDigitSymbol, 00156 kSevenDigitSymbol, 00160 kEightDigitSymbol, 00164 kNineDigitSymbol, 00166 kFormatSymbolCount 00167 }; 00168 00173 enum ECurrencySpacing { 00174 kCurrencyMatch, 00175 kSurroundingMatch, 00176 kInsert, 00177 kCurrencySpacingCount 00178 }; 00179 00188 DecimalFormatSymbols(const Locale& locale, UErrorCode& status); 00189 00200 DecimalFormatSymbols( UErrorCode& status); 00201 00206 DecimalFormatSymbols(const DecimalFormatSymbols&); 00207 00212 DecimalFormatSymbols& operator=(const DecimalFormatSymbols&); 00213 00218 virtual ~DecimalFormatSymbols(); 00219 00227 UBool operator==(const DecimalFormatSymbols& other) const; 00228 00236 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); } 00237 00247 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const; 00248 00261 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits); 00262 00267 inline Locale getLocale() const; 00268 00274 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; 00275 00292 const UnicodeString& getPatternForCurrencySpacing(ECurrencySpacing type, 00293 UBool beforeCurrency, 00294 UErrorCode& status) const; 00305 void setPatternForCurrencySpacing(ECurrencySpacing type, 00306 UBool beforeCurrency, 00307 const UnicodeString& pattern); 00308 00314 virtual UClassID getDynamicClassID() const; 00315 00321 static UClassID U_EXPORT2 getStaticClassID(); 00322 00323 private: 00324 DecimalFormatSymbols(); // default constructor not implemented 00325 00336 void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE); 00337 00341 void initialize(); 00342 00343 void setCurrencyForSymbols(); 00344 00345 public: 00357 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const; 00358 00363 inline const UChar* getCurrencyPattern(void) const; 00364 00365 private: 00381 UnicodeString fSymbols[kFormatSymbolCount]; 00382 00387 UnicodeString fNoSymbol; 00388 00389 Locale locale; 00390 00391 char actualLocale[ULOC_FULLNAME_CAPACITY]; 00392 char validLocale[ULOC_FULLNAME_CAPACITY]; 00393 const UChar* currPattern; 00394 00395 UnicodeString currencySpcBeforeSym[kCurrencySpacingCount]; 00396 UnicodeString currencySpcAfterSym[kCurrencySpacingCount]; 00397 }; 00398 00399 // ------------------------------------- 00400 00401 inline UnicodeString 00402 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const { 00403 const UnicodeString *strPtr; 00404 if(symbol < kFormatSymbolCount) { 00405 strPtr = &fSymbols[symbol]; 00406 } else { 00407 strPtr = &fNoSymbol; 00408 } 00409 return *strPtr; 00410 } 00411 00412 inline const UnicodeString & 00413 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const { 00414 const UnicodeString *strPtr; 00415 if(symbol < kFormatSymbolCount) { 00416 strPtr = &fSymbols[symbol]; 00417 } else { 00418 strPtr = &fNoSymbol; 00419 } 00420 return *strPtr; 00421 } 00422 00423 // ------------------------------------- 00424 00425 inline void 00426 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) { 00427 if(symbol<kFormatSymbolCount) { 00428 fSymbols[symbol]=value; 00429 } 00430 00431 // If the zero digit is being set to a known zero digit according to Unicode, 00432 // then we automatically set the corresponding 1-9 digits 00433 if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) { 00434 UChar32 sym = value.char32At(0); 00435 if ( u_charDigitValue(sym) == 0 ) { 00436 for ( int8_t i = 1 ; i<= 9 ; i++ ) { 00437 sym++; 00438 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym); 00439 } 00440 } 00441 } 00442 } 00443 00444 // ------------------------------------- 00445 00446 inline Locale 00447 DecimalFormatSymbols::getLocale() const { 00448 return locale; 00449 } 00450 00451 inline const UChar* 00452 DecimalFormatSymbols::getCurrencyPattern() const { 00453 return currPattern; 00454 } 00455 U_NAMESPACE_END 00456 00457 #endif /* #if !UCONFIG_NO_FORMATTING */ 00458 00459 #endif // _DCFMTSYM 00460 //eof