Loading...
Searching...
No Matches
dcfmtsym.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
* Copyright (C) 1997-2016, International Business Machines
* 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.
* 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
* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
* functions.
********************************************************************************
*/
#ifndef DCFMTSYM_H
#define DCFMTSYM_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/uchar.h"
#include "unicode/uobject.h"
#include "unicode/locid.h"
#include "unicode/numsys.h"
#include "unicode/unum.h"
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
class U_I18N_API_CLASS DecimalFormatSymbols : public UObject {
public:
enum ENumberFormatSymbol {
kDecimalSeparatorSymbol,
kGroupingSeparatorSymbol,
kPatternSeparatorSymbol,
kPercentSymbol,
kZeroDigitSymbol,
kDigitSymbol,
kMinusSignSymbol,
kPlusSignSymbol,
kCurrencySymbol,
kIntlCurrencySymbol,
kMonetarySeparatorSymbol,
kExponentialSymbol,
kPerMillSymbol,
kPadEscapeSymbol,
kInfinitySymbol,
kNaNSymbol,
kSignificantDigitSymbol,
kMonetaryGroupingSeparatorSymbol,
kOneDigitSymbol,
kTwoDigitSymbol,
kThreeDigitSymbol,
kFourDigitSymbol,
kFiveDigitSymbol,
kSixDigitSymbol,
kSevenDigitSymbol,
kEightDigitSymbol,
kNineDigitSymbol,
kExponentMultiplicationSymbol,
#ifndef U_HIDE_INTERNAL_API
kApproximatelySignSymbol,
#endif /* U_HIDE_INTERNAL_API */
kFormatSymbolCount = kExponentMultiplicationSymbol + 2
};
U_I18N_API DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
U_I18N_API DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
U_I18N_API DecimalFormatSymbols(UErrorCode& status);
U_I18N_API static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
U_I18N_API DecimalFormatSymbols(const DecimalFormatSymbols&);
U_I18N_API DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
U_I18N_API virtual ~DecimalFormatSymbols();
U_I18N_API bool operator==(const DecimalFormatSymbols& other) const;
U_I18N_API bool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
U_I18N_API inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
U_I18N_API void setSymbol(ENumberFormatSymbol symbol,
const UnicodeString& value,
const UBool propagateDigits);
#ifndef U_HIDE_INTERNAL_API
U_I18N_API void setCurrency(const char16_t* currency, UErrorCode& status);
#endif // U_HIDE_INTERNAL_API
U_I18N_API inline Locale getLocale() const;
U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
U_I18N_API const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
UErrorCode& status) const;
U_I18N_API void setPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
const UnicodeString& pattern);
U_I18N_API virtual UClassID getDynamicClassID() const override;
U_I18N_API static UClassID getStaticClassID();
private:
DecimalFormatSymbols();
void initialize(const Locale& locale, UErrorCode& success,
UBool useLastResortData = false, const NumberingSystem* ns = nullptr);
void initialize();
public:
#ifndef U_HIDE_INTERNAL_API
U_I18N_API inline UBool isCustomCurrencySymbol() const {
return fIsCustomCurrencySymbol;
}
U_I18N_API inline UBool isCustomIntlCurrencySymbol() const {
return fIsCustomIntlCurrencySymbol;
}
U_I18N_API inline UChar32 getCodePointZero() const {
return fCodePointZero;
}
#endif /* U_HIDE_INTERNAL_API */
U_I18N_API inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
#ifndef U_HIDE_INTERNAL_API
U_I18N_API inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
U_I18N_API inline const char16_t* getCurrencyPattern() const;
U_I18N_API inline const char* getNumberingSystemName() const;
#endif /* U_HIDE_INTERNAL_API */
private:
UnicodeString fSymbols[kFormatSymbolCount];
UnicodeString fNoSymbol;
UChar32 fCodePointZero;
Locale locale;
Locale actualLocale;
Locale validLocale;
const char16_t* currPattern = nullptr;
UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
UBool fIsCustomCurrencySymbol;
UBool fIsCustomIntlCurrencySymbol;
char nsName[kInternalNumSysNameCapacity+1] = {};
};
// -------------------------------------
inline UnicodeString
DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
const UnicodeString *strPtr;
if(symbol < kFormatSymbolCount) {
strPtr = &fSymbols[symbol];
} else {
strPtr = &fNoSymbol;
}
return *strPtr;
}
// 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;
if(symbol < kFormatSymbolCount) {
strPtr = &fSymbols[symbol];
} else {
strPtr = &fNoSymbol;
}
return *strPtr;
}
#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 /* U_HIDE_INTERNAL_API */
// -------------------------------------
inline void
DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = 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
// Also record updates to fCodePointZero. Be conservative if in doubt.
if (symbol == kZeroDigitSymbol) {
UChar32 sym = value.char32At(0);
if ( propagateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
fCodePointZero = sym;
for ( int8_t i = 1 ; i<= 9 ; i++ ) {
sym++;
fSymbols[static_cast<int>(kOneDigitSymbol) + i - 1] = UnicodeString(sym);
}
} else {
fCodePointZero = -1;
}
} else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
fCodePointZero = -1;
}
}
// -------------------------------------
inline Locale
DecimalFormatSymbols::getLocale() const {
return locale;
}
#ifndef U_HIDE_INTERNAL_API
inline const char16_t*
DecimalFormatSymbols::getCurrencyPattern() const {
return currPattern;
}
inline const char*
DecimalFormatSymbols::getNumberingSystemName() const {
return nsName;
}
#endif /* U_HIDE_INTERNAL_API */
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _DCFMTSYM
//eof
icu::DecimalFormatSymbols::operator==
U_I18N_API bool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
icu::DecimalFormatSymbols::DecimalFormatSymbols
U_I18N_API DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
icu::DecimalFormatSymbols::~DecimalFormatSymbols
virtual U_I18N_API ~DecimalFormatSymbols()
Destructor.
icu::DecimalFormatSymbols::isCustomIntlCurrencySymbol
U_I18N_API UBool isCustomIntlCurrencySymbol() const
Definition dcfmtsym.h:410
icu::DecimalFormatSymbols::operator=
U_I18N_API DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition dcfmtsym.h:92
icu::DecimalFormatSymbols::kEightDigitSymbol
@ kEightDigitSymbol
Eight.
Definition dcfmtsym.h:163
icu::DecimalFormatSymbols::kThreeDigitSymbol
@ kThreeDigitSymbol
Three.
Definition dcfmtsym.h:143
icu::DecimalFormatSymbols::kDecimalSeparatorSymbol
@ kDecimalSeparatorSymbol
The decimal separator.
Definition dcfmtsym.h:94
icu::DecimalFormatSymbols::kNineDigitSymbol
@ kNineDigitSymbol
Nine.
Definition dcfmtsym.h:167
icu::DecimalFormatSymbols::kPlusSignSymbol
@ kPlusSignSymbol
The plus sign.
Definition dcfmtsym.h:108
icu::DecimalFormatSymbols::kMinusSignSymbol
@ kMinusSignSymbol
The minus sign.
Definition dcfmtsym.h:106
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition dcfmtsym.h:171
icu::DecimalFormatSymbols::kFormatSymbolCount
@ kFormatSymbolCount
count symbol constants
Definition dcfmtsym.h:179
icu::DecimalFormatSymbols::kInfinitySymbol
@ kInfinitySymbol
Infinity symbol.
Definition dcfmtsym.h:122
icu::DecimalFormatSymbols::kExponentialSymbol
@ kExponentialSymbol
The exponential symbol.
Definition dcfmtsym.h:116
icu::DecimalFormatSymbols::kPerMillSymbol
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition dcfmtsym.h:118
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
@ kPatternSeparatorSymbol
The pattern separator.
Definition dcfmtsym.h:98
icu::DecimalFormatSymbols::kCurrencySymbol
@ kCurrencySymbol
The currency symbol.
Definition dcfmtsym.h:110
icu::DecimalFormatSymbols::kSixDigitSymbol
@ kSixDigitSymbol
Six.
Definition dcfmtsym.h:155
icu::DecimalFormatSymbols::kTwoDigitSymbol
@ kTwoDigitSymbol
Two.
Definition dcfmtsym.h:139
icu::DecimalFormatSymbols::kFiveDigitSymbol
@ kFiveDigitSymbol
Five.
Definition dcfmtsym.h:151
icu::DecimalFormatSymbols::kSignificantDigitSymbol
@ kSignificantDigitSymbol
Significant digit symbol.
Definition dcfmtsym.h:127
icu::DecimalFormatSymbols::kIntlCurrencySymbol
@ kIntlCurrencySymbol
The international currency symbol.
Definition dcfmtsym.h:112
icu::DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition dcfmtsym.h:131
icu::DecimalFormatSymbols::kSevenDigitSymbol
@ kSevenDigitSymbol
Seven.
Definition dcfmtsym.h:159
icu::DecimalFormatSymbols::kPadEscapeSymbol
@ kPadEscapeSymbol
Escape padding character.
Definition dcfmtsym.h:120
icu::DecimalFormatSymbols::kPercentSymbol
@ kPercentSymbol
The percent sign.
Definition dcfmtsym.h:100
icu::DecimalFormatSymbols::kNaNSymbol
@ kNaNSymbol
Nan symbol.
Definition dcfmtsym.h:124
icu::DecimalFormatSymbols::kApproximatelySignSymbol
@ kApproximatelySignSymbol
Approximately sign.
Definition dcfmtsym.h:176
icu::DecimalFormatSymbols::kDigitSymbol
@ kDigitSymbol
Character representing a digit in the pattern.
Definition dcfmtsym.h:104
icu::DecimalFormatSymbols::kMonetarySeparatorSymbol
@ kMonetarySeparatorSymbol
The monetary separator.
Definition dcfmtsym.h:114
icu::DecimalFormatSymbols::kZeroDigitSymbol
@ kZeroDigitSymbol
Zero.
Definition dcfmtsym.h:102
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
@ kGroupingSeparatorSymbol
The grouping separator.
Definition dcfmtsym.h:96
icu::DecimalFormatSymbols::kOneDigitSymbol
@ kOneDigitSymbol
One.
Definition dcfmtsym.h:135
icu::DecimalFormatSymbols::kFourDigitSymbol
@ kFourDigitSymbol
Four.
Definition dcfmtsym.h:147
icu::DecimalFormatSymbols::getNumberingSystemName
U_I18N_API const char * getNumberingSystemName() const
Returns the numbering system with which this DecimalFormatSymbols was initialized.
Definition dcfmtsym.h:605
icu::DecimalFormatSymbols::getLocale
U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
icu::DecimalFormatSymbols::getCurrencyPattern
U_I18N_API const char16_t * getCurrencyPattern() const
Returns that pattern stored in currency info.
Definition dcfmtsym.h:601
icu::DecimalFormatSymbols::getConstSymbol
U_I18N_API const UnicodeString & getConstSymbol(ENumberFormatSymbol symbol) const
Internal function - more efficient version of getSymbol, returning a const reference to one of the sy...
Definition dcfmtsym.h:536
icu::DecimalFormatSymbols::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::DecimalFormatSymbols::DecimalFormatSymbols
U_I18N_API DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
icu::DecimalFormatSymbols::setPatternForCurrencySpacing
U_I18N_API void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::DecimalFormatSymbols
U_I18N_API DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
icu::DecimalFormatSymbols::isCustomCurrencySymbol
U_I18N_API UBool isCustomCurrencySymbol() const
Definition dcfmtsym.h:403
icu::DecimalFormatSymbols::getSymbol
U_I18N_API UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition dcfmtsym.h:524
icu::DecimalFormatSymbols::getConstDigitSymbol
U_I18N_API const UnicodeString & getConstDigitSymbol(int32_t digit) const
Returns the const UnicodeString reference, like getConstSymbol, corresponding to the digit with the g...
Definition dcfmtsym.h:547
icu::DecimalFormatSymbols::setCurrency
U_I18N_API void setCurrency(const char16_t *currency, UErrorCode &status)
Loads symbols for the specified currency into this instance.
icu::DecimalFormatSymbols::getLocale
U_I18N_API Locale getLocale() const
Returns the locale for which this object was constructed.
Definition dcfmtsym.h:595
icu::DecimalFormatSymbols::getCodePointZero
U_I18N_API UChar32 getCodePointZero() const
Definition dcfmtsym.h:417
icu::DecimalFormatSymbols::getPatternForCurrencySpacing
U_I18N_API const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::DecimalFormatSymbols
U_I18N_API DecimalFormatSymbols(const Locale &locale, const NumberingSystem &ns, UErrorCode &status)
Creates a DecimalFormatSymbols instance for the given locale with digits and symbols corresponding to...
icu::DecimalFormatSymbols::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DecimalFormatSymbols::setSymbol
U_I18N_API void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits)
Set one of the format symbols by its enum constant.
Definition dcfmtsym.h:562
icu::DecimalFormatSymbols::operator!=
U_I18N_API bool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition dcfmtsym.h:273
icu::DecimalFormatSymbols::createWithLastResortData
static U_I18N_API DecimalFormatSymbols * createWithLastResortData(UErrorCode &status)
Creates a DecimalFormatSymbols object with last-resort data.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::NumberingSystem
Defines numbering systems.
Definition numsys.h:60
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
icu::UnicodeString::countChar32
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
locid.h
C++ API: Locale ID object.
icu::operator==
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::kInternalNumSysNameCapacity
constexpr const size_t kInternalNumSysNameCapacity
Size of a numbering system name.
Definition numsys.h:42
numsys.h
C++ API: NumberingSystem object.
uchar.h
C API: Unicode Properties.
u_charDigitValue
U_CAPI int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition uloc.h:338
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:449
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
unistr.h
C++ API: Unicode String.
unum.h
C API: Compatibility APIs for number formatting.
UCurrencySpacing
UCurrencySpacing
Constants for specifying currency spacing.
Definition unum.h:301
UNUM_CURRENCY_SPACING_COUNT
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition unum.h:316
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316