+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
-* Copyright (C) 1997-2014, International Business Machines
+* Copyright (C) 1997-2016, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
#include "unicode/uobject.h"
#include "unicode/locid.h"
+#include "unicode/numsys.h"
#include "unicode/unum.h"
+#include "unicode/unistr.h"
/**
* \file
*/
+#if U_SHOW_CPLUSPLUS_API
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 "#,##,###,####" == "######,####" == "##,####,####".
- * <P>
- * 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:
* @stable ICU 4.6
*/
kNineDigitSymbol,
+ /** Multiplication sign.
+ * @stable ICU 54
+ */
+ kExponentMultiplicationSymbol,
/** count symbol constants */
- kFormatSymbolCount
+ kFormatSymbolCount = kNineDigitSymbol + 2
};
/**
*/
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
*/
DecimalFormatSymbols(UErrorCode& status);
-#ifndef U_HIDE_DRAFT_API
/**
* Creates a DecimalFormatSymbols object with last-resort data.
* Intended for callers who cache the symbols data and
* @param status Input/output parameter, set to success or
* failure code upon return.
* @return last-resort symbols
- * @draft ICU 52
+ * @stable ICU 52
*/
static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
-#endif /* U_HIDE_DRAFT_API */
/**
* Copy constructor.
* @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.
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, it is needed for inline in DecimalFormat
+ * 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:
*/
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.
+ *
+ * <p>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.
+ *
+ * <p>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;
};
// -------------------------------------
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;
return *strPtr;
}
-#endif /* U_HIDE_INTERNAL_API */
-
+#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<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
+ return fSymbols[key];
+}
+#endif
// -------------------------------------
inline void
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 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 ) {
+ // Also record updates to fCodePointZero. Be conservative if in doubt.
+ if (symbol == kZeroDigitSymbol) {
UChar32 sym = value.char32At(0);
- if ( u_charDigitValue(sym) == 0 ) {
+ if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
+ fCodePointZero = sym;
for ( int8_t i = 1 ; i<= 9 ; i++ ) {
sym++;
fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
}
+ } else {
+ fCodePointZero = -1;
}
+ } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
+ fCodePointZero = -1;
}
}
}
#ifndef U_HIDE_INTERNAL_API
-inline const UChar*
+inline const char16_t*
DecimalFormatSymbols::getCurrencyPattern() const {
return currPattern;
}
#endif /* U_HIDE_INTERNAL_API */
U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */