ICU 55.1  55.1
dcfmtsym.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2015, 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 
44 
85 public:
166 #ifndef U_HIDE_DRAFT_API
167 
171 #endif /* U_HIDE_DRAFT_API */
172 
173  kFormatSymbolCount = kNineDigitSymbol + 2
174  };
175 
184  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
185 
197 
214 
220 
226 
232 
240  UBool operator==(const DecimalFormatSymbols& other) const;
241 
249  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
250 
260  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
261 
274  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
275 
280  inline Locale getLocale() const;
281 
288 
306  UBool beforeCurrency,
307  UErrorCode& status) const;
319  UBool beforeCurrency,
320  const UnicodeString& pattern);
321 
327  virtual UClassID getDynamicClassID() const;
328 
334  static UClassID U_EXPORT2 getStaticClassID();
335 
336 private:
338 
349  void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
350 
354  void initialize();
355 
356  void setCurrencyForSymbols();
357 
358 public:
371  inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
372 
373 #ifndef U_HIDE_INTERNAL_API
374 
378  inline const UChar* getCurrencyPattern(void) const;
379 #endif /* U_HIDE_INTERNAL_API */
380 
381 private:
397  UnicodeString fSymbols[kFormatSymbolCount];
398 
403  UnicodeString fNoSymbol;
404 
405  Locale locale;
406 
407  char actualLocale[ULOC_FULLNAME_CAPACITY];
408  char validLocale[ULOC_FULLNAME_CAPACITY];
409  const UChar* currPattern;
410 
411  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
412  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
413 };
414 
415 // -------------------------------------
416 
417 inline UnicodeString
418 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
419  const UnicodeString *strPtr;
420  if(symbol < kFormatSymbolCount) {
421  strPtr = &fSymbols[symbol];
422  } else {
423  strPtr = &fNoSymbol;
424  }
425  return *strPtr;
426 }
427 
428 //#ifndef U_HIDE_INTERNAL_API
429 // See comments above for this function. Not hidden.
430 inline const UnicodeString &
431 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
432  const UnicodeString *strPtr;
433  if(symbol < kFormatSymbolCount) {
434  strPtr = &fSymbols[symbol];
435  } else {
436  strPtr = &fNoSymbol;
437  }
438  return *strPtr;
439 }
440 
441 //#endif /* U_HIDE_INTERNAL_API */
442 
443 
444 // -------------------------------------
445 
446 inline void
447 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
448  if(symbol<kFormatSymbolCount) {
449  fSymbols[symbol]=value;
450  }
451 
452  // If the zero digit is being set to a known zero digit according to Unicode,
453  // then we automatically set the corresponding 1-9 digits
454  if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
455  UChar32 sym = value.char32At(0);
456  if ( u_charDigitValue(sym) == 0 ) {
457  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
458  sym++;
459  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
460  }
461  }
462  }
463 }
464 
465 // -------------------------------------
466 
467 inline Locale
468 DecimalFormatSymbols::getLocale() const {
469  return locale;
470 }
471 
472 #ifndef U_HIDE_INTERNAL_API
473 inline const UChar*
474 DecimalFormatSymbols::getCurrencyPattern() const {
475  return currPattern;
476 }
477 #endif /* U_HIDE_INTERNAL_API */
478 
480 
481 #endif /* #if !UCONFIG_NO_FORMATTING */
482 
483 #endif // _DCFMTSYM
484 //eof
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
icu::DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
@ kMonetaryGroupingSeparatorSymbol
The monetary grouping separator.
Definition: dcfmtsym.h:129
icu::DecimalFormatSymbols::kNaNSymbol
@ kNaNSymbol
Nan symbol.
Definition: dcfmtsym.h:122
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:242
icu::DecimalFormatSymbols::kExponentialSymbol
@ kExponentialSymbol
The exponential symbol.
Definition: dcfmtsym.h:114
icu::DecimalFormatSymbols::operator=
DecimalFormatSymbols & operator=(const DecimalFormatSymbols &)
Assignment operator.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(const Locale &locale, UErrorCode &status)
Create a DecimalFormatSymbols object for the given locale.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UNUM_CURRENCY_SPACING_COUNT
@ UNUM_CURRENCY_SPACING_COUNT
Definition: unum.h:301
icu::DecimalFormatSymbols::kDigitSymbol
@ kDigitSymbol
Character representing a digit in the pattern.
Definition: dcfmtsym.h:102
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:358
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition: dcfmtsym.h:170
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:336
icu::DecimalFormatSymbols::operator==
UBool operator==(const DecimalFormatSymbols &other) const
Return true if another object is semantically equal to this one.
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(const DecimalFormatSymbols &)
Copy constructor.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::DecimalFormatSymbols::kFiveDigitSymbol
@ kFiveDigitSymbol
Five.
Definition: dcfmtsym.h:149
icu::DecimalFormatSymbols::kPlusSignSymbol
@ kPlusSignSymbol
The plus sign.
Definition: dcfmtsym.h:106
icu::DecimalFormatSymbols::kSevenDigitSymbol
@ kSevenDigitSymbol
Seven.
Definition: dcfmtsym.h:157
icu::DecimalFormatSymbols::setPatternForCurrencySpacing
void setPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, const UnicodeString &pattern)
Set pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::kMinusSignSymbol
@ kMinusSignSymbol
The minus sign.
Definition: dcfmtsym.h:104
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
icu::DecimalFormatSymbols::operator!=
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:249
icu::DecimalFormatSymbols::kSixDigitSymbol
@ kSixDigitSymbol
Six.
Definition: dcfmtsym.h:153
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
@ kPatternSeparatorSymbol
The pattern separator.
Definition: dcfmtsym.h:96
icu::DecimalFormatSymbols::DecimalFormatSymbols
DecimalFormatSymbols(UErrorCode &status)
Create a DecimalFormatSymbols object for the default locale.
unum.h
C API: NumberFormat.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
icu::DecimalFormatSymbols::kEightDigitSymbol
@ kEightDigitSymbol
Eight.
Definition: dcfmtsym.h:161
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:332
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
@ kGroupingSeparatorSymbol
The grouping separator.
Definition: dcfmtsym.h:94
TRUE
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:238
icu::DecimalFormatSymbols::kZeroDigitSymbol
@ kZeroDigitSymbol
Zero.
Definition: dcfmtsym.h:100
icu::DecimalFormatSymbols::kNineDigitSymbol
@ kNineDigitSymbol
Nine.
Definition: dcfmtsym.h:165
UCurrencySpacing
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:293
icu::DecimalFormatSymbols::getPatternForCurrencySpacing
const UnicodeString & getPatternForCurrencySpacing(UCurrencySpacing type, UBool beforeCurrency, UErrorCode &status) const
Get pattern string for 'CurrencySpacing' that can be applied to currency format.
icu::DecimalFormatSymbols::kTwoDigitSymbol
@ kTwoDigitSymbol
Two.
Definition: dcfmtsym.h:137
icu::DecimalFormatSymbols::~DecimalFormatSymbols
virtual ~DecimalFormatSymbols()
Destructor.
icu::DecimalFormatSymbols::kThreeDigitSymbol
@ kThreeDigitSymbol
Three.
Definition: dcfmtsym.h:141
icu::DecimalFormatSymbols::kMonetarySeparatorSymbol
@ kMonetarySeparatorSymbol
The monetary separator.
Definition: dcfmtsym.h:112
ULOC_FULLNAME_CAPACITY
#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
icu::UnicodeString::countChar32
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.
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:90
icu::DecimalFormatSymbols::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::DecimalFormatSymbols::kFourDigitSymbol
@ kFourDigitSymbol
Four.
Definition: dcfmtsym.h:145
icu::DecimalFormatSymbols::kDecimalSeparatorSymbol
@ kDecimalSeparatorSymbol
The decimal separator.
Definition: dcfmtsym.h:92
uchar.h
C API: Unicode Properties.
u_charDigitValue
int32_t u_charDigitValue(UChar32 c)
Returns the decimal digit value of a decimal digit character.
UChar
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:312
icu::DecimalFormatSymbols::createWithLastResortData
static DecimalFormatSymbols * createWithLastResortData(UErrorCode &status)
Creates a DecimalFormatSymbols object with last-resort data.
locid.h
C++ API: Locale ID object.
icu::DecimalFormatSymbols::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DecimalFormatSymbols::kPercentSymbol
@ kPercentSymbol
The percent sign.
Definition: dcfmtsym.h:98
icu::DecimalFormatSymbols::kInfinitySymbol
@ kInfinitySymbol
Infinity symbol.
Definition: dcfmtsym.h:120
uobject.h
C++ API: Common ICU base class UObject.
icu::DecimalFormatSymbols::getLocale
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::DecimalFormatSymbols::kSignificantDigitSymbol
@ kSignificantDigitSymbol
Significant digit symbol.
Definition: dcfmtsym.h:125
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::DecimalFormatSymbols::kIntlCurrencySymbol
@ kIntlCurrencySymbol
The international currency symbol.
Definition: dcfmtsym.h:110
icu::DecimalFormatSymbols::kPerMillSymbol
@ kPerMillSymbol
Per mill symbol - replaces kPermillSymbol.
Definition: dcfmtsym.h:116
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
icu::DecimalFormatSymbols::kCurrencySymbol
@ kCurrencySymbol
The currency symbol.
Definition: dcfmtsym.h:108
icu::DecimalFormatSymbols::kPadEscapeSymbol
@ kPadEscapeSymbol
Escape padding character.
Definition: dcfmtsym.h:118
icu::DecimalFormatSymbols::kOneDigitSymbol
@ kOneDigitSymbol
One.
Definition: dcfmtsym.h:133