ICU 50.2 50.2
dcfmtsym.h
Go to the documentation of this file.
1/*
2********************************************************************************
3* Copyright (C) 1997-2012, International Business Machines
4* Corporation and others. All Rights Reserved.
5********************************************************************************
6*
7* File DCFMTSYM.H
8*
9* Modification History:
10*
11* Date Name Description
12* 02/19/97 aliu Converted from java.
13* 03/18/97 clhuang Updated per C++ implementation.
14* 03/27/97 helena Updated to pass the simple test after code review.
15* 08/26/97 aliu Added currency/intl currency symbol support.
16* 07/22/98 stephen Changed to match C++ style
17* currencySymbol -> fCurrencySymbol
18* Constants changed from CAPS to kCaps
19* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
20* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
21* functions.
22********************************************************************************
23*/
24
25#ifndef DCFMTSYM_H
26#define DCFMTSYM_H
27
28#include "unicode/utypes.h"
29#include "unicode/uchar.h"
30
31#if !UCONFIG_NO_FORMATTING
32
33#include "unicode/uobject.h"
34#include "unicode/locid.h"
35#include "unicode/unum.h"
36
41
42
44
85public:
169
178 DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
179
191
197
203
209
218
226 UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
227
237 inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
238
251 void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
252
257 inline Locale getLocale() const;
258
265
283 UBool beforeCurrency,
284 UErrorCode& status) const;
296 UBool beforeCurrency,
297 const UnicodeString& pattern);
298
305
311 static UClassID U_EXPORT2 getStaticClassID();
312
313private:
314 DecimalFormatSymbols(); // default constructor not implemented
315
326 void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
327
331 void initialize();
332
333 void setCurrencyForSymbols();
334
335public:
336#ifndef U_HIDE_INTERNAL_API
348 inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
349
354 inline const UChar* getCurrencyPattern(void) const;
355#endif /* U_HIDE_INTERNAL_API */
356
357private:
374
379 UnicodeString fNoSymbol;
380
381 Locale locale;
382
383 char actualLocale[ULOC_FULLNAME_CAPACITY];
384 char validLocale[ULOC_FULLNAME_CAPACITY];
385 const UChar* currPattern;
386
387 UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
388 UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
389};
390
391// -------------------------------------
392
393inline UnicodeString
395 const UnicodeString *strPtr;
396 if(symbol < kFormatSymbolCount) {
397 strPtr = &fSymbols[symbol];
398 } else {
399 strPtr = &fNoSymbol;
400 }
401 return *strPtr;
402}
403
404#ifndef U_HIDE_INTERNAL_API
405inline const UnicodeString &
407 const UnicodeString *strPtr;
408 if(symbol < kFormatSymbolCount) {
409 strPtr = &fSymbols[symbol];
410 } else {
411 strPtr = &fNoSymbol;
412 }
413 return *strPtr;
414}
415#endif
416
417
418// -------------------------------------
419
420inline void
421DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
422 if(symbol<kFormatSymbolCount) {
423 fSymbols[symbol]=value;
424 }
425
426 // If the zero digit is being set to a known zero digit according to Unicode,
427 // then we automatically set the corresponding 1-9 digits
428 if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
429 UChar32 sym = value.char32At(0);
430 if ( u_charDigitValue(sym) == 0 ) {
431 for ( int8_t i = 1 ; i<= 9 ; i++ ) {
432 sym++;
433 fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
434 }
435 }
436 }
437}
438
439// -------------------------------------
440
441inline Locale
443 return locale;
444}
445
446#ifndef U_HIDE_INTERNAL_API
447inline const UChar*
449 return currPattern;
450}
451#endif
452
454
455#endif /* #if !UCONFIG_NO_FORMATTING */
456
457#endif // _DCFMTSYM
458//eof
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:406
DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition dcfmtsym.h:90
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition dcfmtsym.h:116
@ kInfinitySymbol
Infinity symbol.
Definition dcfmtsym.h:120
@ kGroupingSeparatorSymbol
The grouping separator.
Definition dcfmtsym.h:94
@ kMonetarySeparatorSymbol
The monetary separator.
Definition dcfmtsym.h:112
@ kPlusSignSymbol
The plus sign.
Definition dcfmtsym.h:106
@ kSevenDigitSymbol
Seven.
Definition dcfmtsym.h:157
@ kNaNSymbol
Nan symbol.
Definition dcfmtsym.h:122
@ kSignificantDigitSymbol
Significant digit symbol.
Definition dcfmtsym.h:125
@ kPercentSymbol
The percent sign.
Definition dcfmtsym.h:98
@ kThreeDigitSymbol
Three.
Definition dcfmtsym.h:141
@ kPadEscapeSymbol
Escape padding character.
Definition dcfmtsym.h:118
@ kEightDigitSymbol
Eight.
Definition dcfmtsym.h:161
@ kDigitSymbol
Character representing a digit in the pattern.
Definition dcfmtsym.h:102
@ kCurrencySymbol
The currency symbol.
Definition dcfmtsym.h:108
@ kMinusSignSymbol
The minus sign.
Definition dcfmtsym.h:104
@ kIntlCurrencySymbol
The international currency symbol.
Definition dcfmtsym.h:110
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition dcfmtsym.h:129
@ kPatternSeparatorSymbol
The pattern separator.
Definition dcfmtsym.h:96
@ kExponentialSymbol
The exponential symbol.
Definition dcfmtsym.h:114
@ kDecimalSeparatorSymbol
The decimal separator.
Definition dcfmtsym.h:92
@ kFormatSymbolCount
count symbol constants
Definition dcfmtsym.h:167
DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
Locale getLocale() const
Returns the locale for which this object was constructed.
Definition dcfmtsym.h:442
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition dcfmtsym.h:226
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits)
Set one of the format symbols by its enum constant.
Definition dcfmtsym.h:421
DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
virtual ~DecimalFormatSymbols()
Destructor.
const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition dcfmtsym.h:394
UBool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
const UChar * getCurrencyPattern(void) const
Returns that pattern stored in currecy info.
Definition dcfmtsym.h:448
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length UChar code units of the string.
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
C++ API: Locale ID object.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C API: Unicode Properties.
int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition uloc.h:262
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition uloc.h:336
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:298
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
#define TRUE
The TRUE value of a UBool.
Definition umachine.h:204
#define FALSE
The FALSE value of a UBool.
Definition umachine.h:208
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition umachine.h:278
C API: NumberFormat.
UCurrencySpacing
Constants for specifying currency spacing.
Definition unum.h:257
@ UNUM_CURRENCY_SPACING_COUNT
Definition unum.h:265
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129