ICU 73.2  73.2
dcfmtsym.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 ********************************************************************************
00005 *   Copyright (C) 1997-2016, International Business Machines
00006 *   Corporation and others.  All Rights Reserved.
00007 ********************************************************************************
00008 *
00009 * File DCFMTSYM.H
00010 *
00011 * Modification History:
00012 *
00013 *   Date        Name        Description
00014 *   02/19/97    aliu        Converted from java.
00015 *   03/18/97    clhuang     Updated per C++ implementation.
00016 *   03/27/97    helena      Updated to pass the simple test after code review.
00017 *   08/26/97    aliu        Added currency/intl currency symbol support.
00018 *   07/22/98    stephen     Changed to match C++ style
00019 *                            currencySymbol -> fCurrencySymbol
00020 *                            Constants changed from CAPS to kCaps
00021 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
00022 *   09/22/00    grhoten     Marked deprecation tags with a pointer to replacement
00023 *                            functions.
00024 ********************************************************************************
00025 */
00026 
00027 #ifndef DCFMTSYM_H
00028 #define DCFMTSYM_H
00029 
00030 #include "unicode/utypes.h"
00031 
00032 #if U_SHOW_CPLUSPLUS_API
00033 
00034 #if !UCONFIG_NO_FORMATTING
00035 
00036 #include "unicode/uchar.h"
00037 #include "unicode/uobject.h"
00038 #include "unicode/locid.h"
00039 #include "unicode/numsys.h"
00040 #include "unicode/unum.h"
00041 #include "unicode/unistr.h"
00042 
00049 U_NAMESPACE_BEGIN
00050 
00086 class U_I18N_API DecimalFormatSymbols : public UObject {
00087 public:
00092     enum ENumberFormatSymbol {
00094         kDecimalSeparatorSymbol,
00096         kGroupingSeparatorSymbol,
00098         kPatternSeparatorSymbol,
00100         kPercentSymbol,
00102         kZeroDigitSymbol,
00104         kDigitSymbol,
00106         kMinusSignSymbol,
00108         kPlusSignSymbol,
00110         kCurrencySymbol,
00112         kIntlCurrencySymbol,
00114         kMonetarySeparatorSymbol,
00116         kExponentialSymbol,
00118         kPerMillSymbol,
00120         kPadEscapeSymbol,
00122         kInfinitySymbol,
00124         kNaNSymbol,
00127         kSignificantDigitSymbol,
00131         kMonetaryGroupingSeparatorSymbol,
00135         kOneDigitSymbol,
00139         kTwoDigitSymbol,
00143         kThreeDigitSymbol,
00147         kFourDigitSymbol,
00151         kFiveDigitSymbol,
00155         kSixDigitSymbol,
00159         kSevenDigitSymbol,
00163         kEightDigitSymbol,
00167         kNineDigitSymbol,
00171         kExponentMultiplicationSymbol,
00172 #ifndef U_HIDE_INTERNAL_API
00173 
00176         kApproximatelySignSymbol,
00177 #endif  /* U_HIDE_INTERNAL_API */
00178 
00179         kFormatSymbolCount = kExponentMultiplicationSymbol + 2
00180     };
00181 
00190     DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
00191 
00208     DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
00209 
00220     DecimalFormatSymbols(UErrorCode& status);
00221 
00237     static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
00238 
00243     DecimalFormatSymbols(const DecimalFormatSymbols&);
00244 
00249     DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
00250 
00255     virtual ~DecimalFormatSymbols();
00256 
00264     bool operator==(const DecimalFormatSymbols& other) const;
00265 
00273     bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
00274 
00284     inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
00285 
00298     void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits);
00299 
00300 #ifndef U_HIDE_INTERNAL_API
00301 
00308     void setCurrency(const char16_t* currency, UErrorCode& status);
00309 #endif  // U_HIDE_INTERNAL_API
00310 
00315     inline Locale getLocale() const;
00316 
00322     Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00323 
00340      const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
00341                                                  UBool beforeCurrency,
00342                                                  UErrorCode& status) const;
00353      void setPatternForCurrencySpacing(UCurrencySpacing type,
00354                                        UBool beforeCurrency,
00355                                        const UnicodeString& pattern);
00356 
00362     virtual UClassID getDynamicClassID() const override;
00363 
00369     static UClassID U_EXPORT2 getStaticClassID();
00370 
00371 private:
00372     DecimalFormatSymbols();
00373 
00386     void initialize(const Locale& locale, UErrorCode& success,
00387                     UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
00388 
00392     void initialize();
00393 
00394 public:
00395 
00396 #ifndef U_HIDE_INTERNAL_API
00397 
00400     inline UBool isCustomCurrencySymbol() const {
00401         return fIsCustomCurrencySymbol;
00402     }
00403 
00407     inline UBool isCustomIntlCurrencySymbol() const {
00408         return fIsCustomIntlCurrencySymbol;
00409     }
00410 
00414     inline UChar32 getCodePointZero() const {
00415         return fCodePointZero;
00416     }
00417 #endif  /* U_HIDE_INTERNAL_API */
00418 
00434     inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
00435 
00436 #ifndef U_HIDE_INTERNAL_API
00437 
00452     inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
00453 
00458     inline const char16_t* getCurrencyPattern(void) const;
00459 
00464     inline const char* getNumberingSystemName(void) const;
00465 #endif  /* U_HIDE_INTERNAL_API */
00466 
00467 private:
00482     UnicodeString fSymbols[kFormatSymbolCount];
00483 
00487     UnicodeString fNoSymbol;
00488 
00503     UChar32 fCodePointZero;
00504 
00505     Locale locale;
00506 
00507     char actualLocale[ULOC_FULLNAME_CAPACITY];
00508     char validLocale[ULOC_FULLNAME_CAPACITY];
00509     const char16_t* currPattern = nullptr;
00510 
00511     UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
00512     UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
00513     UBool fIsCustomCurrencySymbol;
00514     UBool fIsCustomIntlCurrencySymbol;
00515     char nsName[kInternalNumSysNameCapacity+1] = {};
00516 };
00517 
00518 // -------------------------------------
00519 
00520 inline UnicodeString
00521 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
00522     const UnicodeString *strPtr;
00523     if(symbol < kFormatSymbolCount) {
00524         strPtr = &fSymbols[symbol];
00525     } else {
00526         strPtr = &fNoSymbol;
00527     }
00528     return *strPtr;
00529 }
00530 
00531 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
00532 inline const UnicodeString &
00533 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
00534     const UnicodeString *strPtr;
00535     if(symbol < kFormatSymbolCount) {
00536         strPtr = &fSymbols[symbol];
00537     } else {
00538         strPtr = &fNoSymbol;
00539     }
00540     return *strPtr;
00541 }
00542 
00543 #ifndef U_HIDE_INTERNAL_API
00544 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
00545     if (digit < 0 || digit > 9) {
00546         digit = 0;
00547     }
00548     if (digit == 0) {
00549         return fSymbols[kZeroDigitSymbol];
00550     }
00551     ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
00552     return fSymbols[key];
00553 }
00554 #endif /* U_HIDE_INTERNAL_API */
00555 
00556 // -------------------------------------
00557 
00558 inline void
00559 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) {
00560     if (symbol == kCurrencySymbol) {
00561         fIsCustomCurrencySymbol = true;
00562     }
00563     else if (symbol == kIntlCurrencySymbol) {
00564         fIsCustomIntlCurrencySymbol = true;
00565     }
00566     if(symbol<kFormatSymbolCount) {
00567         fSymbols[symbol]=value;
00568     }
00569 
00570     // If the zero digit is being set to a known zero digit according to Unicode,
00571     // then we automatically set the corresponding 1-9 digits
00572     // Also record updates to fCodePointZero. Be conservative if in doubt.
00573     if (symbol == kZeroDigitSymbol) {
00574         UChar32 sym = value.char32At(0);
00575         if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
00576             fCodePointZero = sym;
00577             for ( int8_t i = 1 ; i<= 9 ; i++ ) {
00578                 sym++;
00579                 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
00580             }
00581         } else {
00582             fCodePointZero = -1;
00583         }
00584     } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
00585         fCodePointZero = -1;
00586     }
00587 }
00588 
00589 // -------------------------------------
00590 
00591 inline Locale
00592 DecimalFormatSymbols::getLocale() const {
00593     return locale;
00594 }
00595 
00596 #ifndef U_HIDE_INTERNAL_API
00597 inline const char16_t*
00598 DecimalFormatSymbols::getCurrencyPattern() const {
00599     return currPattern;
00600 }
00601 inline const char*
00602 DecimalFormatSymbols::getNumberingSystemName() const {
00603     return nsName;
00604 }
00605 #endif /* U_HIDE_INTERNAL_API */
00606 
00607 U_NAMESPACE_END
00608 
00609 #endif /* #if !UCONFIG_NO_FORMATTING */
00610 
00611 #endif /* U_SHOW_CPLUSPLUS_API */
00612 
00613 #endif // _DCFMTSYM
00614 //eof