]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/unicode/dcfmtsym.h
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / dcfmtsym.h
index bc5547d4cdd6d7a8c7674f077620f25fda081e97..9b406b14172b4323d3c889e13c645f38658f4867 100644 (file)
@@ -1,19 +1,19 @@
 /*
 ********************************************************************************
 /*
 ********************************************************************************
-*   Copyright (C) 1997-2007, International Business Machines
+*   Copyright (C) 1997-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
 * File DCFMTSYM.H
 *
 * Modification History:
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
 * File DCFMTSYM.H
 *
 * Modification History:
-* 
+*
 *   Date        Name        Description
 *   02/19/97    aliu        Converted from java.
 *   03/18/97    clhuang     Updated per C++ implementation.
 *   03/27/97    helena      Updated to pass the simple test after code review.
 *   08/26/97    aliu        Added currency/intl currency symbol support.
 *   Date        Name        Description
 *   02/19/97    aliu        Converted from java.
 *   03/18/97    clhuang     Updated per C++ implementation.
 *   03/27/97    helena      Updated to pass the simple test after code review.
 *   08/26/97    aliu        Added currency/intl currency symbol support.
-*   07/22/98    stephen     Changed to match C++ style 
+*   07/22/98    stephen     Changed to match C++ style
 *                            currencySymbol -> fCurrencySymbol
 *                            Constants changed from CAPS to kCaps
 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
 *                            currencySymbol -> fCurrencySymbol
 *                            Constants changed from CAPS to kCaps
 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
 *                            functions.
 ********************************************************************************
 */
 *                            functions.
 ********************************************************************************
 */
+
 #ifndef DCFMTSYM_H
 #define DCFMTSYM_H
 #ifndef DCFMTSYM_H
 #define DCFMTSYM_H
+
 #include "unicode/utypes.h"
 #include "unicode/utypes.h"
+#include "unicode/uchar.h"
 
 #if !UCONFIG_NO_FORMATTING
 
 #include "unicode/uobject.h"
 #include "unicode/locid.h"
 
 #if !UCONFIG_NO_FORMATTING
 
 #include "unicode/uobject.h"
 #include "unicode/locid.h"
+#include "unicode/unum.h"
 
 /**
 
 /**
- * \file 
+ * \file
  * \brief C++ API: Symbols for formatting numbers.
  */
 
  * \brief C++ API: Symbols for formatting numbers.
  */
 
@@ -121,12 +123,52 @@ public:
         /** Significant digit symbol
          * @stable ICU 3.0 */
         kSignificantDigitSymbol,
         /** Significant digit symbol
          * @stable ICU 3.0 */
         kSignificantDigitSymbol,
-        /** The monetary grouping separator 
+        /** The monetary grouping separator
          * @stable ICU 3.6
          */
         kMonetaryGroupingSeparatorSymbol,
          * @stable ICU 3.6
          */
         kMonetaryGroupingSeparatorSymbol,
+        /** One
+         * @stable ICU 4.6
+         */
+        kOneDigitSymbol,
+        /** Two
+         * @stable ICU 4.6
+         */
+        kTwoDigitSymbol,
+        /** Three
+         * @stable ICU 4.6
+         */
+        kThreeDigitSymbol,
+        /** Four
+         * @stable ICU 4.6
+         */
+        kFourDigitSymbol,
+        /** Five
+         * @stable ICU 4.6
+         */
+        kFiveDigitSymbol,
+        /** Six
+         * @stable ICU 4.6
+         */
+        kSixDigitSymbol,
+        /** Seven
+         * @stable ICU 4.6
+         */
+        kSevenDigitSymbol,
+        /** Eight
+         * @stable ICU 4.6
+         */
+        kEightDigitSymbol,
+        /** Nine
+         * @stable ICU 4.6
+         */
+        kNineDigitSymbol,
+        /** Multiplication sign.
+         * @stable ICU 54
+         */
+        kExponentMultiplicationSymbol,
         /** count symbol constants */
         /** count symbol constants */
-        kFormatSymbolCount
+        kFormatSymbolCount = kNineDigitSymbol + 2
     };
 
     /**
     };
 
     /**
@@ -149,7 +191,24 @@ public:
      *                  failure code upon return.
      * @stable ICU 2.0
      */
      *                  failure code upon return.
      * @stable ICU 2.0
      */
-    DecimalFormatSymbols( UErrorCode& status);
+    DecimalFormatSymbols(UErrorCode& status);
+
+    /**
+     * Creates a DecimalFormatSymbols object with last-resort data.
+     * Intended for callers who cache the symbols data and
+     * set all symbols on the resulting object.
+     *
+     * The last-resort symbols are similar to those for the root data,
+     * except that the grouping separators are empty,
+     * the NaN symbol is U+FFFD rather than "NaN",
+     * and the CurrencySpacing patterns are empty.
+     *
+     * @param status    Input/output parameter, set to success or
+     *                  failure code upon return.
+     * @return last-resort symbols
+     * @stable ICU 52
+     */
+    static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
 
     /**
      * Copy constructor.
 
     /**
      * Copy constructor.
@@ -190,7 +249,7 @@ public:
     /**
      * Get one of the format symbols by its enum constant.
      * Each symbol is stored as a string so that graphemes
     /**
      * Get one of the format symbols by its enum constant.
      * Each symbol is stored as a string so that graphemes
-     * (characters with modifyer letters) can be used.
+     * (characters with modifier letters) can be used.
      *
      * @param symbol    Constant to indicate a number format symbol.
      * @return    the format symbols by the param 'symbol'
      *
      * @param symbol    Constant to indicate a number format symbol.
      * @return    the format symbols by the param 'symbol'
@@ -201,13 +260,16 @@ public:
     /**
      * Set one of the format symbols by its enum constant.
      * Each symbol is stored as a string so that graphemes
     /**
      * Set one of the format symbols by its enum constant.
      * Each symbol is stored as a string so that graphemes
-     * (characters with modifyer letters) can be used.
+     * (characters with modifier letters) can be used.
      *
      * @param symbol    Constant to indicate a number format symbol.
      *
      * @param symbol    Constant to indicate a number format symbol.
-     * @param value     value of the format sybmol
+     * @param value     value of the format symbol
+     * @param propogateDigits If false, setting the zero digit will not automatically set 1-9.
+     *     The default behavior is to automatically set 1-9 if zero is being set and the value
+     *     it is being set to corresponds to a known Unicode zero digit.
      * @stable ICU 2.0
      */
      * @stable ICU 2.0
      */
-    void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value);
+    void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
 
     /**
      * Returns the locale for which this object was constructed.
 
     /**
      * Returns the locale for which this object was constructed.
@@ -222,6 +284,39 @@ public:
      */
     Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
 
      */
     Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
 
+    /**
+      * Get pattern string for 'CurrencySpacing' that can be applied to
+      * currency format.
+      * This API gets the CurrencySpacing data from ResourceBundle. The pattern can
+      * be empty if there is no data from current locale and its parent locales.
+      *
+      * @param type :  UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
+      * @param beforeCurrency : true if the pattern is for before currency symbol.
+      *                         false if the pattern is for after currency symbol.
+      * @param status: Input/output parameter, set to success or
+      *                  failure code upon return.
+      * @return pattern string for currencyMatch, surroundingMatch or spaceInsert.
+      *     Return empty string if there is no data for this locale and its parent
+      *     locales.
+      * @stable ICU 4.8
+      */
+     const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
+                                                 UBool beforeCurrency,
+                                                 UErrorCode& status) const;
+     /**
+       * Set pattern string for 'CurrencySpacing' that can be applied to
+       * currency format.
+       *
+       * @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
+       * @param beforeCurrency : true if the pattern is for before currency symbol.
+       *                         false if the pattern is for after currency symbol.
+       * @param pattern : pattern string to override current setting.
+       * @stable ICU 4.8
+       */
+     void setPatternForCurrencySpacing(UCurrencySpacing type,
+                                       UBool beforeCurrency,
+                                       const UnicodeString& pattern);
+
     /**
      * ICU "poor man's RTTI", returns a UClassID for the actual class.
      *
     /**
      * ICU "poor man's RTTI", returns a UClassID for the actual class.
      *
@@ -237,7 +332,7 @@ public:
     static UClassID U_EXPORT2 getStaticClassID();
 
 private:
     static UClassID U_EXPORT2 getStaticClassID();
 
 private:
-    DecimalFormatSymbols(); // default constructor not implemented
+    DecimalFormatSymbols();
 
     /**
      * Initializes the symbols from the LocaleElements resource bundle.
 
     /**
      * Initializes the symbols from the LocaleElements resource bundle.
@@ -251,15 +346,6 @@ private:
      */
     void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
 
      */
     void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
 
-    /**
-     * Initialize the symbols from the given array of UnicodeStrings.
-     * The array must be of the correct size.
-     * 
-     * @param numberElements    the number format symbols
-     * @param numberElementsLength length of numberElements
-     */
-    void initialize(const UChar** numberElements, int32_t *numberElementsStrLen, int32_t numberElementsLength);
-
     /**
      * Initialize the symbols with default values.
      */
     /**
      * Initialize the symbols with default values.
      */
@@ -268,12 +354,30 @@ private:
     void setCurrencyForSymbols();
 
 public:
     void setCurrencyForSymbols();
 
 public:
+
+#ifndef U_HIDE_INTERNAL_API
+    /**
+     * @internal For ICU use only
+     */
+    inline UBool isCustomCurrencySymbol() const {
+        return fIsCustomCurrencySymbol;
+    }
+
+    /**
+     * @internal For ICU use only
+     */
+    inline UBool isCustomIntlCurrencySymbol() const {
+        return fIsCustomIntlCurrencySymbol;
+    }
+#endif  /* U_HIDE_INTERNAL_API */
+
     /**
      * _Internal_ function - more efficient version of getSymbol,
      * returning a const reference to one of the symbol strings.
      * The returned reference becomes invalid when the symbol is changed
      * or when the DecimalFormatSymbols are destroyed.
      * ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
     /**
      * _Internal_ function - more efficient version of getSymbol,
      * returning a const reference to one of the symbol strings.
      * The returned reference becomes invalid when the symbol is changed
      * or when the DecimalFormatSymbols are destroyed.
      * ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
+     * Note: moved #ifndef U_HIDE_INTERNAL_API after this, since this is needed for inline in DecimalFormat
      *
      * @param symbol Constant to indicate a number format symbol.
      * @return the format symbol by the param 'symbol'
      *
      * @param symbol Constant to indicate a number format symbol.
      * @return the format symbol by the param 'symbol'
@@ -281,11 +385,13 @@ public:
      */
     inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
 
      */
     inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
 
+#ifndef U_HIDE_INTERNAL_API
     /**
      * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
      * @internal
      */
     inline const UChar* getCurrencyPattern(void) const;
     /**
      * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
      * @internal
      */
     inline const UChar* getCurrencyPattern(void) const;
+#endif  /* U_HIDE_INTERNAL_API */
 
 private:
     /**
 
 private:
     /**
@@ -316,6 +422,11 @@ private:
     char actualLocale[ULOC_FULLNAME_CAPACITY];
     char validLocale[ULOC_FULLNAME_CAPACITY];
     const UChar* currPattern;
     char actualLocale[ULOC_FULLNAME_CAPACITY];
     char validLocale[ULOC_FULLNAME_CAPACITY];
     const UChar* currPattern;
+
+    UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
+    UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
+    UBool fIsCustomCurrencySymbol;
+    UBool fIsCustomIntlCurrencySymbol;
 };
 
 // -------------------------------------
 };
 
 // -------------------------------------
@@ -331,6 +442,7 @@ DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
     return *strPtr;
 }
 
     return *strPtr;
 }
 
+// See comments above for this function. Not hidden with #ifndef U_HIDE_INTERNAL_API
 inline const UnicodeString &
 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
     const UnicodeString *strPtr;
 inline const UnicodeString &
 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
     const UnicodeString *strPtr;
@@ -345,10 +457,28 @@ DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
 // -------------------------------------
 
 inline void
 // -------------------------------------
 
 inline void
-DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value) {
+DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
+    if (symbol == kCurrencySymbol) {
+        fIsCustomCurrencySymbol = TRUE;
+    }
+    else if (symbol == kIntlCurrencySymbol) {
+        fIsCustomIntlCurrencySymbol = TRUE;
+    }
     if(symbol<kFormatSymbolCount) {
         fSymbols[symbol]=value;
     }
     if(symbol<kFormatSymbolCount) {
         fSymbols[symbol]=value;
     }
+
+    // If the zero digit is being set to a known zero digit according to Unicode,
+    // then we automatically set the corresponding 1-9 digits
+    if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
+        UChar32 sym = value.char32At(0);
+        if ( u_charDigitValue(sym) == 0 ) {
+            for ( int8_t i = 1 ; i<= 9 ; i++ ) {
+                sym++;
+                fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
+            }
+        }
+    }
 }
 
 // -------------------------------------
 }
 
 // -------------------------------------
@@ -358,10 +488,13 @@ DecimalFormatSymbols::getLocale() const {
     return locale;
 }
 
     return locale;
 }
 
+#ifndef U_HIDE_INTERNAL_API
 inline const UChar*
 DecimalFormatSymbols::getCurrencyPattern() const {
     return currPattern;
 }
 inline const UChar*
 DecimalFormatSymbols::getCurrencyPattern() const {
     return currPattern;
 }
+#endif /* U_HIDE_INTERNAL_API */
+
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_FORMATTING */