ICU 67.1  67.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 
32 #if U_SHOW_CPLUSPLUS_API
33 
34 #if !UCONFIG_NO_FORMATTING
35 
36 #include "unicode/uchar.h"
37 #include "unicode/uobject.h"
38 #include "unicode/locid.h"
39 #include "unicode/numsys.h"
40 #include "unicode/unum.h"
41 #include "unicode/unistr.h"
42 
49 U_NAMESPACE_BEGIN
50 
87 public:
173  kFormatSymbolCount = kNineDigitSymbol + 2
174  };
175 
184  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
185 
202  DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
203 
215 
231  static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
232 
238 
243  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
244 
249  virtual ~DecimalFormatSymbols();
250 
258  UBool operator==(const DecimalFormatSymbols& other) const;
259 
267  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
268 
278  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
279 
292  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
293 
294 #ifndef U_HIDE_INTERNAL_API
295 
302  void setCurrency(const UChar* currency, UErrorCode& status);
303 #endif // U_HIDE_INTERNAL_API
304 
309  inline Locale getLocale() const;
310 
316  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
317 
334  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
335  UBool beforeCurrency,
336  UErrorCode& status) const;
347  void setPatternForCurrencySpacing(UCurrencySpacing type,
348  UBool beforeCurrency,
349  const UnicodeString& pattern);
350 
356  virtual UClassID getDynamicClassID() const;
357 
363  static UClassID U_EXPORT2 getStaticClassID();
364 
365 private:
367 
380  void initialize(const Locale& locale, UErrorCode& success,
381  UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
382 
386  void initialize();
387 
388 public:
389 
390 #ifndef U_HIDE_INTERNAL_API
391 
394  inline UBool isCustomCurrencySymbol() const {
395  return fIsCustomCurrencySymbol;
396  }
397 
402  return fIsCustomIntlCurrencySymbol;
403  }
404 
408  inline UChar32 getCodePointZero() const {
409  return fCodePointZero;
410  }
411 #endif /* U_HIDE_INTERNAL_API */
412 
428  inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
429 
430 #ifndef U_HIDE_INTERNAL_API
431 
446  inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
447 
452  inline const char16_t* getCurrencyPattern(void) const;
453 #endif /* U_HIDE_INTERNAL_API */
454 
455 private:
470  UnicodeString fSymbols[kFormatSymbolCount];
471 
475  UnicodeString fNoSymbol;
476 
491  UChar32 fCodePointZero;
492 
493  Locale locale;
494 
495  char actualLocale[ULOC_FULLNAME_CAPACITY];
496  char validLocale[ULOC_FULLNAME_CAPACITY];
497  const char16_t* currPattern;
498 
499  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
500  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
501  UBool fIsCustomCurrencySymbol;
502  UBool fIsCustomIntlCurrencySymbol;
503 };
504 
505 // -------------------------------------
506 
507 inline UnicodeString
509  const UnicodeString *strPtr;
510  if(symbol < kFormatSymbolCount) {
511  strPtr = &fSymbols[symbol];
512  } else {
513  strPtr = &fNoSymbol;
514  }
515  return *strPtr;
516 }
517 
518 // See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
519 inline const UnicodeString &
521  const UnicodeString *strPtr;
522  if(symbol < kFormatSymbolCount) {
523  strPtr = &fSymbols[symbol];
524  } else {
525  strPtr = &fNoSymbol;
526  }
527  return *strPtr;
528 }
529 
530 #ifndef U_HIDE_INTERNAL_API
531 inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
532  if (digit < 0 || digit > 9) {
533  digit = 0;
534  }
535  if (digit == 0) {
536  return fSymbols[kZeroDigitSymbol];
537  }
538  ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
539  return fSymbols[key];
540 }
541 #endif /* U_HIDE_INTERNAL_API */
542 
543 // -------------------------------------
544 
545 inline void
546 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
547  if (symbol == kCurrencySymbol) {
548  fIsCustomCurrencySymbol = TRUE;
549  }
550  else if (symbol == kIntlCurrencySymbol) {
551  fIsCustomIntlCurrencySymbol = TRUE;
552  }
553  if(symbol<kFormatSymbolCount) {
554  fSymbols[symbol]=value;
555  }
556 
557  // If the zero digit is being set to a known zero digit according to Unicode,
558  // then we automatically set the corresponding 1-9 digits
559  // Also record updates to fCodePointZero. Be conservative if in doubt.
560  if (symbol == kZeroDigitSymbol) {
561  UChar32 sym = value.char32At(0);
562  if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
563  fCodePointZero = sym;
564  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
565  sym++;
566  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
567  }
568  } else {
569  fCodePointZero = -1;
570  }
571  } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
572  fCodePointZero = -1;
573  }
574 }
575 
576 // -------------------------------------
577 
578 inline Locale
580  return locale;
581 }
582 
583 #ifndef U_HIDE_INTERNAL_API
584 inline const char16_t*
586  return currPattern;
587 }
588 #endif /* U_HIDE_INTERNAL_API */
589 
590 U_NAMESPACE_END
591 
592 #endif /* #if !UCONFIG_NO_FORMATTING */
593 
594 #endif /* U_SHOW_CPLUSPLUS_API */
595 
596 #endif // _DCFMTSYM
597 //eof
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:394
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
Escape padding character.
Definition: dcfmtsym.h:120
The international currency symbol.
Definition: dcfmtsym.h:112
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Locale getLocale() const
Returns the locale for which this object was constructed.
Definition: dcfmtsym.h:579
const char16_t * getCurrencyPattern(void) const
Returns that pattern stored in currecy info.
Definition: dcfmtsym.h:585
Defines numbering systems.
Definition: numsys.h:60
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:331
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:96
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:264
void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits)
Set one of the format symbols by its enum constant.
Definition: dcfmtsym.h:546
UChar32 getCodePointZero() const
Definition: dcfmtsym.h:408
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition: dcfmtsym.h:92
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition: dcfmtsym.h:508
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:425
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:265
C++ API: NumberingSystem object.
C API: Unicode Properties.
C++ API: Common ICU base class UObject.
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:376
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:401
const UnicodeString & getConstDigitSymbol(int32_t digit) const
Returns the const UnicodeString reference, like getConstSymbol, corresponding to the digit with the g...
Definition: dcfmtsym.h:531
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:338
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.
C++ API: Locale ID object.
Basic definitions for ICU, for both C and C++ APIs.
Character representing a digit in the pattern.
Definition: dcfmtsym.h:104
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:269
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
Per mill symbol - replaces kPermillSymbol.
Definition: dcfmtsym.h:118
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:346
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:267
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:520
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
C API: Compatibility APIs for number formatting.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195