1999-12-28 23:57:50 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
2005-03-16 18:46:54 +00:00
|
|
|
* Copyright (C) 1997-2005, International Business Machines
|
1999-12-28 23:57:50 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File DCFMTSYM.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
2000-03-22 19:19:33 +00:00
|
|
|
*
|
1999-12-28 23:57:50 +00:00
|
|
|
* 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.
|
2000-09-22 22:56:03 +00:00
|
|
|
* 07/22/98 stephen Changed to match C++ style
|
1999-12-28 23:57:50 +00:00
|
|
|
* currencySymbol -> fCurrencySymbol
|
|
|
|
* Constants changed from CAPS to kCaps
|
|
|
|
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
|
2000-09-22 22:56:03 +00:00
|
|
|
* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
|
|
|
|
* functions.
|
1999-12-28 23:57:50 +00:00
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DCFMTSYM_H
|
|
|
|
#define DCFMTSYM_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/locid.h"
|
|
|
|
|
2005-06-22 22:39:36 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief C++ API: Symbols for formatting numbers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* This class represents the set of symbols needed by DecimalFormat
|
|
|
|
* to format numbers. DecimalFormat creates for itself an instance of
|
|
|
|
* DecimalFormatSymbols from its locale data. If you need to change any
|
|
|
|
* of these symbols, you can get the DecimalFormatSymbols object from
|
|
|
|
* your DecimalFormat and modify it.
|
|
|
|
* <P>
|
|
|
|
* Here are the special characters used in the parts of the
|
|
|
|
* subpattern, with notes on their usage.
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* Symbol Meaning
|
|
|
|
* 0 a digit
|
|
|
|
* # a digit, zero shows as absent
|
|
|
|
* . placeholder for decimal separator
|
|
|
|
* , placeholder for grouping separator.
|
|
|
|
* ; separates formats.
|
|
|
|
* - default negative prefix.
|
|
|
|
* % divide by 100 and show as percentage
|
|
|
|
* X any other characters can be used in the prefix or suffix
|
|
|
|
* ' used to quote special characters in a prefix or suffix.
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
2000-08-07 23:02:51 +00:00
|
|
|
* [Notes]
|
1999-12-28 23:57:50 +00:00
|
|
|
* <P>
|
|
|
|
* If there is no explicit negative subpattern, - is prefixed to the
|
|
|
|
* positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
|
|
|
|
* <P>
|
|
|
|
* The grouping separator is commonly used for thousands, but in some
|
|
|
|
* countries for ten-thousands. The interval is a constant number of
|
|
|
|
* digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-06-27 01:19:20 +00:00
|
|
|
class U_I18N_API DecimalFormatSymbols : public UObject {
|
1999-12-28 23:57:50 +00:00
|
|
|
public:
|
2000-05-25 01:10:55 +00:00
|
|
|
/**
|
|
|
|
* Constants for specifying a number format symbol.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2000-05-25 01:10:55 +00:00
|
|
|
*/
|
|
|
|
enum ENumberFormatSymbol {
|
2000-05-25 23:15:29 +00:00
|
|
|
/** The decimal separator */
|
|
|
|
kDecimalSeparatorSymbol,
|
|
|
|
/** The grouping separator */
|
|
|
|
kGroupingSeparatorSymbol,
|
|
|
|
/** The pattern separator */
|
|
|
|
kPatternSeparatorSymbol,
|
|
|
|
/** The percent sign */
|
|
|
|
kPercentSymbol,
|
|
|
|
/** Zero*/
|
|
|
|
kZeroDigitSymbol,
|
|
|
|
/** Character representing a digit in the pattern */
|
|
|
|
kDigitSymbol,
|
|
|
|
/** The minus sign */
|
|
|
|
kMinusSignSymbol,
|
|
|
|
/** The plus sign */
|
|
|
|
kPlusSignSymbol,
|
|
|
|
/** The currency symbol */
|
|
|
|
kCurrencySymbol,
|
|
|
|
/** The international currency symbol */
|
|
|
|
kIntlCurrencySymbol,
|
|
|
|
/** The monetary separator */
|
|
|
|
kMonetarySeparatorSymbol,
|
|
|
|
/** The exponential symbol */
|
|
|
|
kExponentialSymbol,
|
2001-11-14 01:55:08 +00:00
|
|
|
/** Per mill symbol - replaces kPermillSymbol */
|
2001-09-17 21:50:19 +00:00
|
|
|
kPerMillSymbol,
|
2000-05-25 23:15:29 +00:00
|
|
|
/** Escape padding character */
|
|
|
|
kPadEscapeSymbol,
|
|
|
|
/** Infinity symbol */
|
|
|
|
kInfinitySymbol,
|
|
|
|
/** Nan symbol */
|
|
|
|
kNaNSymbol,
|
2004-03-25 17:42:28 +00:00
|
|
|
/** Significant digit symbol
|
|
|
|
* @draft ICU 3.0 */
|
|
|
|
kSignificantDigitSymbol,
|
2000-05-25 23:15:29 +00:00
|
|
|
/** count symbol constants */
|
|
|
|
kFormatSymbolCount
|
2000-05-25 01:10:55 +00:00
|
|
|
};
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Create a DecimalFormatSymbols object for the given locale.
|
|
|
|
*
|
|
|
|
* @param locale The locale to get symbols for.
|
|
|
|
* @param status Input/output parameter, set to success or
|
|
|
|
* failure code upon return.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a DecimalFormatSymbols object for the default locale.
|
|
|
|
* This constructor will not fail. If the resource file data is
|
|
|
|
* not available, it will use hard-coded last-resort data and
|
|
|
|
* set status to U_USING_FALLBACK_ERROR.
|
|
|
|
*
|
|
|
|
* @param status Input/output parameter, set to success or
|
|
|
|
* failure code upon return.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
DecimalFormatSymbols( UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
DecimalFormatSymbols(const DecimalFormatSymbols&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2004-08-26 20:39:32 +00:00
|
|
|
virtual ~DecimalFormatSymbols();
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if another object is semantically equal to this one.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param other the object to be compared with.
|
|
|
|
* @return true if another object is semantically equal to this one.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator==(const DecimalFormatSymbols& other) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if another object is semantically unequal to this one.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param other the object to be compared with.
|
|
|
|
* @return true if another object is semantically unequal to this one.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2000-05-25 01:10:55 +00:00
|
|
|
* 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.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param symbol Constant to indicate a number format symbol.
|
|
|
|
* @return the format symbols by the param 'symbol'
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2000-05-25 01:10:55 +00:00
|
|
|
*/
|
2003-09-18 00:40:29 +00:00
|
|
|
inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
|
2000-05-25 01:10:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param symbol Constant to indicate a number format symbol.
|
|
|
|
* @param value value of the format sybmol
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-03-04 19:15:06 +00:00
|
|
|
void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value);
|
2000-05-25 01:10:55 +00:00
|
|
|
|
2002-05-13 19:33:05 +00:00
|
|
|
/**
|
|
|
|
* Returns the locale for which this object was constructed.
|
2003-06-03 01:58:48 +00:00
|
|
|
* @stable ICU 2.6
|
2002-05-13 19:33:05 +00:00
|
|
|
*/
|
|
|
|
inline Locale getLocale() const;
|
|
|
|
|
2004-01-20 23:06:38 +00:00
|
|
|
/**
|
|
|
|
* Returns the locale for this object. Two flavors are available:
|
|
|
|
* valid and actual locale.
|
2005-06-22 23:38:06 +00:00
|
|
|
* @draft ICU 2.8 likely to change after ICU 3.0, based on feedback
|
2004-01-20 23:06:38 +00:00
|
|
|
*/
|
|
|
|
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
|
|
*
|
2003-11-18 02:37:24 +00:00
|
|
|
* @stable ICU 2.2
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2003-09-18 00:40:29 +00:00
|
|
|
virtual UClassID getDynamicClassID() const;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
|
|
*
|
2003-11-18 02:37:24 +00:00
|
|
|
* @stable ICU 2.2
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2004-08-24 17:38:33 +00:00
|
|
|
static UClassID U_EXPORT2 getStaticClassID();
|
2002-06-29 00:04:16 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
private:
|
2003-05-04 01:40:40 +00:00
|
|
|
DecimalFormatSymbols(); // default constructor not implemented
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Initializes the symbols from the LocaleElements resource bundle.
|
|
|
|
* Note: The organization of LocaleElements badly needs to be
|
|
|
|
* cleaned up.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param locale The locale to get symbols for.
|
|
|
|
* @param success Input/output parameter, set to success or
|
|
|
|
* failure code upon return.
|
|
|
|
* @param useLastResortData determine if use last resort data
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the symbols from the given array of UnicodeStrings.
|
|
|
|
* The array must be of the correct size.
|
2002-07-01 11:04:45 +00:00
|
|
|
*
|
|
|
|
* @param numberElements the number format symbols
|
2003-04-11 20:02:25 +00:00
|
|
|
* @param numberElementsLength length of numberElements
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2004-09-02 19:08:28 +00:00
|
|
|
void initialize(const UChar** numberElements, int32_t *numberElementsStrLen, int32_t numberElementsLength);
|
2000-05-25 23:15:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the symbols with default values.
|
|
|
|
*/
|
|
|
|
void initialize();
|
|
|
|
|
2002-05-13 19:33:05 +00:00
|
|
|
void setCurrencyForSymbols();
|
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
public:
|
2002-10-12 01:09:00 +00:00
|
|
|
/**
|
2002-10-15 00:36:11 +00:00
|
|
|
* _Internal_ function - more efficient version of getSymbol,
|
|
|
|
* returning a const reference to one of the symbol strings.
|
2002-10-12 01:09:00 +00:00
|
|
|
* The returned reference becomes invalid when the symbol is changed
|
|
|
|
* or when the DecimalFormatSymbols are destroyed.
|
2002-10-15 00:36:11 +00:00
|
|
|
* ### TODO markus 2002oct11: Consider proposing getConstSymbol() to be really public.
|
2002-10-12 01:09:00 +00:00
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
private:
|
2002-10-12 01:09:00 +00:00
|
|
|
/**
|
|
|
|
* Private symbol strings.
|
|
|
|
* They are either loaded from a resource bundle or otherwise owned.
|
|
|
|
* setSymbol() clones the symbol string.
|
|
|
|
* Readonly aliases can only come from a resource bundle, so that we can always
|
|
|
|
* use fastCopyFrom() with them.
|
|
|
|
*
|
|
|
|
* If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
|
|
|
|
* from private to protected,
|
|
|
|
* or when fSymbols can be set any other way that allows them to be readonly aliases
|
|
|
|
* to non-resource bundle strings,
|
|
|
|
* then regular UnicodeString copies must be used instead of fastCopyFrom().
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
2000-05-25 23:15:29 +00:00
|
|
|
UnicodeString fSymbols[kFormatSymbolCount];
|
2001-09-28 19:13:03 +00:00
|
|
|
|
2002-10-12 01:09:00 +00:00
|
|
|
/**
|
|
|
|
* Non-symbol variable for getConstSymbol(). Always empty.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
UnicodeString fNoSymbol;
|
|
|
|
|
2002-05-13 19:33:05 +00:00
|
|
|
Locale locale;
|
|
|
|
|
2004-01-20 23:06:38 +00:00
|
|
|
char actualLocale[ULOC_FULLNAME_CAPACITY];
|
|
|
|
char validLocale[ULOC_FULLNAME_CAPACITY];
|
1999-12-28 23:57:50 +00:00
|
|
|
};
|
2000-08-07 23:02:51 +00:00
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
// -------------------------------------
|
2000-08-07 23:02:51 +00:00
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
inline UnicodeString
|
|
|
|
DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
|
2003-09-18 22:36:45 +00:00
|
|
|
const UnicodeString *strPtr;
|
|
|
|
if(symbol < kFormatSymbolCount) {
|
|
|
|
strPtr = &fSymbols[symbol];
|
2000-05-25 01:10:55 +00:00
|
|
|
} else {
|
2003-09-18 22:36:45 +00:00
|
|
|
strPtr = &fNoSymbol;
|
2000-05-25 01:10:55 +00:00
|
|
|
}
|
2003-09-18 22:36:45 +00:00
|
|
|
return *strPtr;
|
2000-05-25 01:10:55 +00:00
|
|
|
}
|
2000-08-07 23:02:51 +00:00
|
|
|
|
2002-10-12 01:09:00 +00:00
|
|
|
inline const UnicodeString &
|
|
|
|
DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
|
2003-09-18 22:36:45 +00:00
|
|
|
const UnicodeString *strPtr;
|
|
|
|
if(symbol < kFormatSymbolCount) {
|
|
|
|
strPtr = &fSymbols[symbol];
|
2002-10-12 01:09:00 +00:00
|
|
|
} else {
|
2003-09-18 22:36:45 +00:00
|
|
|
strPtr = &fNoSymbol;
|
2002-10-12 01:09:00 +00:00
|
|
|
}
|
2003-09-18 22:36:45 +00:00
|
|
|
return *strPtr;
|
2002-10-12 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
// -------------------------------------
|
2000-08-07 23:02:51 +00:00
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
inline void
|
2003-03-04 19:15:06 +00:00
|
|
|
DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value) {
|
2000-05-25 23:15:29 +00:00
|
|
|
if(symbol<kFormatSymbolCount) {
|
2000-05-25 01:10:55 +00:00
|
|
|
fSymbols[symbol]=value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-13 19:33:05 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
inline Locale
|
|
|
|
DecimalFormatSymbols::getLocale() const {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#endif // _DCFMTSYM
|
|
|
|
//eof
|