ICU 63.1  63.1
dcfmtsym.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File DCFMTSYM.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 03/18/97 clhuang Updated per C++ implementation.
16 * 03/27/97 helena Updated to pass the simple test after code review.
17 * 08/26/97 aliu Added currency/intl currency symbol support.
18 * 07/22/98 stephen Changed to match C++ style
19 * currencySymbol -> fCurrencySymbol
20 * Constants changed from CAPS to kCaps
21 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
22 * 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
23 * functions.
24 ********************************************************************************
25 */
26 
27 #ifndef DCFMTSYM_H
28 #define DCFMTSYM_H
29 
30 #include "unicode/utypes.h"
31 #include "unicode/uchar.h"
32 
33 #if !UCONFIG_NO_FORMATTING
34 
35 #include "unicode/uobject.h"
36 #include "unicode/locid.h"
37 #include "unicode/numsys.h"
38 #include "unicode/unum.h"
39 #include "unicode/unistr.h"
40 
48 
85 public:
171  kFormatSymbolCount = kNineDigitSymbol + 2
172  };
173 
182  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
183 
200  DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
201 
213 
229  static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
230 
236 
241  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
242 
247  virtual ~DecimalFormatSymbols();
248 
256  UBool operator==(const DecimalFormatSymbols& other) const;
257 
265  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
266 
276  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
277 
290  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
291 
296  inline Locale getLocale() const;
297 
303  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
304 
321  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
322  UBool beforeCurrency,
323  UErrorCode& status) const;
334  void setPatternForCurrencySpacing(UCurrencySpacing type,
335  UBool beforeCurrency,
336  const UnicodeString& pattern);
337 
343  virtual UClassID getDynamicClassID() const;
344 
350  static UClassID U_EXPORT2 getStaticClassID();
351 
352 private:
354 
367  void initialize(const Locale& locale, UErrorCode& success,
368  UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
369 
373  void initialize();
374 
375  void setCurrencyForSymbols();
376 
377 public:
378 
379 #ifndef U_HIDE_INTERNAL_API
380 
383  inline UBool isCustomCurrencySymbol() const {
384  return fIsCustomCurrencySymbol;
385  }
386 
391  return fIsCustomIntlCurrencySymbol;
392  }
393 
397  inline UChar32 getCodePointZero() const {
398  return fCodePointZero;
399  }
400 #endif /* U_HIDE_INTERNAL_API */
401 
417  inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
418 
419 #ifndef U_HIDE_INTERNAL_API
420 
435  inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
436 
441  inline const char16_t* getCurrencyPattern(void) const;
442 #endif /* U_HIDE_INTERNAL_API */
443 
444 private:
460  UnicodeString fSymbols[kFormatSymbolCount];
461 
466  UnicodeString fNoSymbol;
467 
482  UChar32 fCodePointZero;
483 
484  Locale locale;
485 
486  char actualLocale[ULOC_FULLNAME_CAPACITY];
487  char validLocale[ULOC_FULLNAME_CAPACITY];
488  const char16_t* currPattern;
489 
490  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
491  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
492  UBool fIsCustomCurrencySymbol;
493  UBool fIsCustomIntlCurrencySymbol;
494 };
495 
496 // -------------------------------------
497 
498 inline UnicodeString
499 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
500  const UnicodeString *strPtr;
501  if(symbol < kFormatSymbolCount) {
502  strPtr = &fSymbols[symbol];
503  } else {
504  strPtr = &fNoSymbol;
505  }
506  return *strPtr;
507 }
508 
509 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
510 inline const UnicodeString &
511 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
512  const UnicodeString *strPtr;
513  if(symbol < kFormatSymbolCount) {
514  strPtr = &fSymbols[symbol];
515  } else {
516  strPtr = &fNoSymbol;
517  }
518  return *strPtr;
519 }
520 
521 #ifndef U_HIDE_INTERNAL_API
522 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
523  if (digit < 0 || digit > 9) {
524  digit = 0;
525  }
526  if (digit == 0) {
527  return fSymbols[kZeroDigitSymbol];
528  }
529  ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
530  return fSymbols[key];
531 }
532 #endif /* U_HIDE_INTERNAL_API */
533 
534 // -------------------------------------
535 
536 inline void
537 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
538  if (symbol == kCurrencySymbol) {
539  fIsCustomCurrencySymbol = TRUE;
540  }
541  else if (symbol == kIntlCurrencySymbol) {
542  fIsCustomIntlCurrencySymbol = TRUE;
543  }
544  if(symbol<kFormatSymbolCount) {
545  fSymbols[symbol]=value;
546  }
547 
548  // If the zero digit is being set to a known zero digit according to Unicode,
549  // then we automatically set the corresponding 1-9 digits
550  // Also record updates to fCodePointZero. Be conservative if in doubt.
551  if (symbol == kZeroDigitSymbol) {
552  UChar32 sym = value.char32At(0);
553  if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
554  fCodePointZero = sym;
555  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
556  sym++;
557  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
558  }
559  } else {
560  fCodePointZero = -1;
561  }
562  } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
563  fCodePointZero = -1;
564  }
565 }
566 
567 // -------------------------------------
568 
569 inline Locale
570 DecimalFormatSymbols::getLocale() const {
571  return locale;
572 }
573 
574 #ifndef U_HIDE_INTERNAL_API
575 inline const char16_t*
576 DecimalFormatSymbols::getCurrencyPattern() const {
577  return currPattern;
578 }
579 #endif /* U_HIDE_INTERNAL_API */
580 
582 
583 #endif /* #if !UCONFIG_NO_FORMATTING */
584 
585 #endif // _DCFMTSYM
586 //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:233
icu::DecimalFormatSymbols::kExponentialSymbol
@ kExponentialSymbol
The exponential symbol.
Definition: dcfmtsym.h:114
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UNUM_CURRENCY_SPACING_COUNT
@ UNUM_CURRENCY_SPACING_COUNT
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:345
icu::DecimalFormatSymbols::kDigitSymbol
@ kDigitSymbol
Character representing a digit in the pattern.
Definition: dcfmtsym.h:102
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
icu::DecimalFormatSymbols::kExponentMultiplicationSymbol
@ kExponentMultiplicationSymbol
Multiplication sign.
Definition: dcfmtsym.h:169
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
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::isCustomCurrencySymbol
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:383
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:265
icu::DecimalFormatSymbols::kSixDigitSymbol
@ kSixDigitSymbol
Six.
Definition: dcfmtsym.h:153
icu::DecimalFormatSymbols::kPatternSeparatorSymbol
@ kPatternSeparatorSymbol
The pattern separator.
Definition: dcfmtsym.h:96
unum.h
C API: Compatibility APIs for number formatting.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
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:389
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:90
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
icu::DecimalFormatSymbols::kGroupingSeparatorSymbol
@ kGroupingSeparatorSymbol
The grouping separator.
Definition: dcfmtsym.h:94
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
TRUE
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:229
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:331
icu::DecimalFormatSymbols::kTwoDigitSymbol
@ kTwoDigitSymbol
Two.
Definition: dcfmtsym.h:137
numsys.h
C++ API: NumberingSystem object.
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:264
icu::DecimalFormatSymbols::isCustomIntlCurrencySymbol
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:390
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.
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
icu::DecimalFormatSymbols::getCodePointZero
UChar32 getCodePointZero() const
Definition: dcfmtsym.h:397
icu::DecimalFormatSymbols::ENumberFormatSymbol
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:90
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.
locid.h
C++ API: Locale ID object.
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.
U_NAMESPACE_END
#define U_NAMESPACE_END
Definition: uversion.h:138
icu::DecimalFormatSymbols::kSignificantDigitSymbol
@ kSignificantDigitSymbol
Significant digit symbol.
Definition: dcfmtsym.h:125
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
Definition: uversion.h:137
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:192
icu::DecimalFormatSymbols::kCurrencySymbol
@ kCurrencySymbol
The currency symbol.
Definition: dcfmtsym.h:108
unistr.h
C++ API: Unicode String.
icu::DecimalFormatSymbols::kPadEscapeSymbol
@ kPadEscapeSymbol
Escape padding character.
Definition: dcfmtsym.h:118
icu::DecimalFormatSymbols::kOneDigitSymbol
@ kOneDigitSymbol
One.
Definition: dcfmtsym.h:133