ICU 4.8.1.1  4.8.1.1
dcfmtsym.h
Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2011, 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 #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,
00167         kFormatSymbolCount
00168     };
00169 
00178     DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00179 
00190     DecimalFormatSymbols( UErrorCode& status);
00191 
00196     DecimalFormatSymbols(const DecimalFormatSymbols&);
00197 
00202     DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00203 
00208     virtual ~DecimalFormatSymbols();
00209 
00217     UBool operator==(const DecimalFormatSymbols& other) const;
00218 
00226     UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00227 
00237     inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00238 
00251     void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
00252 
00257     inline Locale getLocale() const;
00258 
00264     Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00265 
00282      const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00283                                                  UBool beforeCurrency,
00284                                                  UErrorCode& status) const;
00295      void setPatternForCurrencySpacing(UCurrencySpacing type,
00296                                        UBool beforeCurrency,
00297                                        const UnicodeString& pattern);
00298 
00304     virtual UClassID getDynamicClassID() const;
00305 
00311     static UClassID U_EXPORT2 getStaticClassID();
00312 
00313 private:
00314     DecimalFormatSymbols(); // default constructor not implemented
00315 
00326     void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
00327 
00331     void initialize();
00332 
00333     void setCurrencyForSymbols();
00334 
00335 public:
00347     inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
00348 
00353     inline const UChar* getCurrencyPattern(void) const;
00354 
00355 private:
00371     UnicodeString fSymbols[kFormatSymbolCount];
00372 
00377     UnicodeString fNoSymbol;
00378 
00379     Locale locale;
00380 
00381     char actualLocale[ULOC_FULLNAME_CAPACITY];
00382     char validLocale[ULOC_FULLNAME_CAPACITY];
00383     const UChar* currPattern;
00384 
00385     UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00386     UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00387 };
00388 
00389 // -------------------------------------
00390 
00391 inline UnicodeString
00392 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00393     const UnicodeString *strPtr;
00394     if(symbol < kFormatSymbolCount) {
00395         strPtr = &fSymbols[symbol];
00396     } else {
00397         strPtr = &fNoSymbol;
00398     }
00399     return *strPtr;
00400 }
00401 
00402 inline const UnicodeString &
00403 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00404     const UnicodeString *strPtr;
00405     if(symbol < kFormatSymbolCount) {
00406         strPtr = &fSymbols[symbol];
00407     } else {
00408         strPtr = &fNoSymbol;
00409     }
00410     return *strPtr;
00411 }
00412 
00413 // -------------------------------------
00414 
00415 inline void
00416 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00417     if(symbol<kFormatSymbolCount) {
00418         fSymbols[symbol]=value;
00419     }
00420 
00421     // If the zero digit is being set to a known zero digit according to Unicode,
00422     // then we automatically set the corresponding 1-9 digits
00423     if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
00424         UChar32 sym = value.char32At(0);
00425         if ( u_charDigitValue(sym) == 0 ) {
00426             for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00427                 sym++;
00428                 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00429             }
00430         }
00431     }
00432 }
00433 
00434 // -------------------------------------
00435 
00436 inline Locale
00437 DecimalFormatSymbols::getLocale() const {
00438     return locale;
00439 }
00440 
00441 inline const UChar*
00442 DecimalFormatSymbols::getCurrencyPattern() const {
00443     return currPattern;
00444 }
00445 U_NAMESPACE_END
00446 
00447 #endif /* #if !UCONFIG_NO_FORMATTING */
00448 
00449 #endif // _DCFMTSYM
00450 //eof
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines