dcfmtsym.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2012, 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:
00336 #ifndef U_HIDE_INTERNAL_API
00337 
00348     inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
00349 
00354     inline const UChar* getCurrencyPattern(void) const;
00355 #endif  /* U_HIDE_INTERNAL_API */
00356 
00357 private:
00373     UnicodeString fSymbols[kFormatSymbolCount];
00374 
00379     UnicodeString fNoSymbol;
00380 
00381     Locale locale;
00382 
00383     char actualLocale[ULOC_FULLNAME_CAPACITY];
00384     char validLocale[ULOC_FULLNAME_CAPACITY];
00385     const UChar* currPattern;
00386 
00387     UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00388     UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00389 };
00390 
00391 // -------------------------------------
00392 
00393 inline UnicodeString
00394 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00395     const UnicodeString *strPtr;
00396     if(symbol < kFormatSymbolCount) {
00397         strPtr = &fSymbols[symbol];
00398     } else {
00399         strPtr = &fNoSymbol;
00400     }
00401     return *strPtr;
00402 }
00403 
00404 #ifndef U_HIDE_INTERNAL_API
00405 inline const UnicodeString &
00406 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00407     const UnicodeString *strPtr;
00408     if(symbol < kFormatSymbolCount) {
00409         strPtr = &fSymbols[symbol];
00410     } else {
00411         strPtr = &fNoSymbol;
00412     }
00413     return *strPtr;
00414 }
00415 #endif
00416 
00417 
00418 // -------------------------------------
00419 
00420 inline void
00421 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
00422     if(symbol<kFormatSymbolCount) {
00423         fSymbols[symbol]=value;
00424     }
00425 
00426     // If the zero digit is being set to a known zero digit according to Unicode,
00427     // then we automatically set the corresponding 1-9 digits
00428     if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
00429         UChar32 sym = value.char32At(0);
00430         if ( u_charDigitValue(sym) == 0 ) {
00431             for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00432                 sym++;
00433                 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00434             }
00435         }
00436     }
00437 }
00438 
00439 // -------------------------------------
00440 
00441 inline Locale
00442 DecimalFormatSymbols::getLocale() const {
00443     return locale;
00444 }
00445 
00446 #ifndef U_HIDE_INTERNAL_API
00447 inline const UChar*
00448 DecimalFormatSymbols::getCurrencyPattern() const {
00449     return currPattern;
00450 }
00451 #endif
00452 
00453 U_NAMESPACE_END
00454 
00455 #endif /* #if !UCONFIG_NO_FORMATTING */
00456 
00457 #endif // _DCFMTSYM
00458 //eof

Generated on 27 Oct 2013 for ICU 50.1.2 by  doxygen 1.4.7