X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/4388f060552cc537e71e957d32f35e9d75a61233..0f5d89e82340278ed3d7d50029f37cab2c41a57e:/icuSources/i18n/unicode/dcfmtsym.h diff --git a/icuSources/i18n/unicode/dcfmtsym.h b/icuSources/i18n/unicode/dcfmtsym.h index 2d013d52..090976d6 100644 --- a/icuSources/i18n/unicode/dcfmtsym.h +++ b/icuSources/i18n/unicode/dcfmtsym.h @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************** -* Copyright (C) 1997-2012, International Business Machines +* Copyright (C) 1997-2016, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************** * @@ -32,7 +34,9 @@ #include "unicode/uobject.h" #include "unicode/locid.h" +#include "unicode/numsys.h" #include "unicode/unum.h" +#include "unicode/unistr.h" /** * \file @@ -40,6 +44,7 @@ */ +#if U_SHOW_CPLUSPLUS_API U_NAMESPACE_BEGIN /** @@ -76,10 +81,6 @@ U_NAMESPACE_BEGIN * If you supply a pattern with multiple grouping characters, the interval * between the last one and the end of the integer is the one that is * used. So "#,##,###,####" == "######,####" == "##,####,####". - *
- * This class only handles localized digits where the 10 digits are - * contiguous in Unicode, from 0 to 9. Other digits sets (such as - * superscripts) would need a different subclass. */ class U_I18N_API DecimalFormatSymbols : public UObject { public: @@ -163,8 +164,12 @@ public: * @stable ICU 4.6 */ kNineDigitSymbol, + /** Multiplication sign. + * @stable ICU 54 + */ + kExponentMultiplicationSymbol, /** count symbol constants */ - kFormatSymbolCount + kFormatSymbolCount = kNineDigitSymbol + 2 }; /** @@ -177,6 +182,26 @@ public: */ DecimalFormatSymbols(const Locale& locale, UErrorCode& status); +#ifndef U_HIDE_DRAFT_API + /** + * Creates a DecimalFormatSymbols instance for the given locale with digits and symbols + * corresponding to the given NumberingSystem. + * + * This constructor behaves equivalently to the normal constructor called with a locale having a + * "numbers=xxxx" keyword specifying the numbering system by name. + * + * In this constructor, the NumberingSystem argument will be used even if the locale has its own + * "numbers=xxxx" keyword. + * + * @param locale The locale to get symbols for. + * @param ns The numbering system. + * @param status Input/output parameter, set to success or + * failure code upon return. + * @draft ICU 60 + */ + DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status); +#endif /* U_HIDE_DRAFT_API */ + /** * Create a DecimalFormatSymbols object for the default locale. * This constructor will not fail. If the resource file data is @@ -187,7 +212,24 @@ public: * 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. @@ -311,7 +353,7 @@ public: static UClassID U_EXPORT2 getStaticClassID(); private: - DecimalFormatSymbols(); // default constructor not implemented + DecimalFormatSymbols(); /** * Initializes the symbols from the LocaleElements resource bundle. @@ -322,8 +364,11 @@ private: * @param success Input/output parameter, set to success or * failure code upon return. * @param useLastResortData determine if use last resort data + * @param ns The NumberingSystem to use; otherwise, fall + * back to the locale. */ - void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE); + void initialize(const Locale& locale, UErrorCode& success, + UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr); /** * Initialize the symbols with default values. @@ -333,25 +378,70 @@ private: 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; + } + + /** + * @internal For ICU use only + */ + inline UChar32 getCodePointZero() const { + return fCodePointZero; + } +#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. + * Note: moved #ifndef U_HIDE_INTERNAL_API after this, since this is needed for inline in DecimalFormat + * + * This is not currently stable API, but if you think it should be stable, + * post a comment on the following ticket and the ICU team will take a look: + * http://bugs.icu-project.org/trac/ticket/13580 * * @param symbol Constant to indicate a number format symbol. * @return the format symbol by the param 'symbol' * @internal */ - inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const; + inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const; + +#ifndef U_HIDE_INTERNAL_API + /** + * Returns the const UnicodeString reference, like getConstSymbol, + * corresponding to the digit with the given value. This is equivalent + * to accessing the symbol from getConstSymbol with the corresponding + * key, such as kZeroDigitSymbol or kOneDigitSymbol. + * + * This is not currently stable API, but if you think it should be stable, + * post a comment on the following ticket and the ICU team will take a look: + * http://bugs.icu-project.org/trac/ticket/13580 + * + * @param digit The digit, an integer between 0 and 9 inclusive. + * If outside the range 0 to 9, the zero digit is returned. + * @return the format symbol for the given digit. + * @internal This API is currently for ICU use only. + */ + inline const UnicodeString& getConstDigitSymbol(int32_t digit) const; /** * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API. * @internal */ - inline const UChar* getCurrencyPattern(void) const; + inline const char16_t* getCurrencyPattern(void) const; #endif /* U_HIDE_INTERNAL_API */ private: @@ -378,14 +468,32 @@ private: */ UnicodeString fNoSymbol; + /** + * Dealing with code points is faster than dealing with strings when formatting. Because of + * this, we maintain a value containing the zero code point that is used whenever digitStrings + * represents a sequence of ten code points in order. + * + *
If the value stored here is positive, it means that the code point stored in this value + * corresponds to the digitStrings array, and codePointZero can be used instead of the + * digitStrings array for the purposes of efficient formatting; if -1, then digitStrings does + * *not* contain a sequence of code points, and it must be used directly. + * + *
It is assumed that codePointZero always shadows the value in digitStrings. codePointZero
+ * should never be set directly; rather, it should be updated only when digitStrings mutates.
+ * That is, the flow of information is digitStrings -> codePointZero, not the other way.
+ */
+ UChar32 fCodePointZero;
+
Locale locale;
char actualLocale[ULOC_FULLNAME_CAPACITY];
char validLocale[ULOC_FULLNAME_CAPACITY];
- const UChar* currPattern;
+ const char16_t* currPattern;
UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
+ UBool fIsCustomCurrencySymbol;
+ UBool fIsCustomIntlCurrencySymbol;
};
// -------------------------------------
@@ -401,7 +509,7 @@ DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
return *strPtr;
}
-#ifndef U_HIDE_INTERNAL_API
+// See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
inline const UnicodeString &
DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
const UnicodeString *strPtr;
@@ -412,27 +520,50 @@ DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
}
return *strPtr;
}
-#endif
+#ifndef U_HIDE_INTERNAL_API
+inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
+ if (digit < 0 || digit > 9) {
+ digit = 0;
+ }
+ if (digit == 0) {
+ return fSymbols[kZeroDigitSymbol];
+ }
+ ENumberFormatSymbol key = static_cast