ICU 58.2  58.2
dcfmtsym.h
Go to the documentation of this file.
1 // Copyright (C) 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/unum.h"
38 
46 
87 public:
173  kFormatSymbolCount = kNineDigitSymbol + 2
174  };
175 
184  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
185 
197 
213  static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
214 
220 
225  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
226 
231  virtual ~DecimalFormatSymbols();
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 
287  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
288 
305  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
306  UBool beforeCurrency,
307  UErrorCode& status) const;
318  void setPatternForCurrencySpacing(UCurrencySpacing type,
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:
359 
360 #ifndef U_HIDE_INTERNAL_API
361 
364  inline UBool isCustomCurrencySymbol() const {
365  return fIsCustomCurrencySymbol;
366  }
367 
372  return fIsCustomIntlCurrencySymbol;
373  }
374 #endif /* U_HIDE_INTERNAL_API */
375 
388  inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
389 
390 #ifndef U_HIDE_INTERNAL_API
391 
395  inline const UChar* getCurrencyPattern(void) const;
396 #endif /* U_HIDE_INTERNAL_API */
397 
398 private:
414  UnicodeString fSymbols[kFormatSymbolCount];
415 
420  UnicodeString fNoSymbol;
421 
422  Locale locale;
423 
424  char actualLocale[ULOC_FULLNAME_CAPACITY];
425  char validLocale[ULOC_FULLNAME_CAPACITY];
426  const UChar* currPattern;
427 
428  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
429  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
430  UBool fIsCustomCurrencySymbol;
431  UBool fIsCustomIntlCurrencySymbol;
432 };
433 
434 // -------------------------------------
435 
436 inline UnicodeString
438  const UnicodeString *strPtr;
439  if(symbol < kFormatSymbolCount) {
440  strPtr = &fSymbols[symbol];
441  } else {
442  strPtr = &fNoSymbol;
443  }
444  return *strPtr;
445 }
446 
447 // See comments above for this function. Not hidden with #ifndef U_HIDE_INTERNAL_API
448 inline const UnicodeString &
450  const UnicodeString *strPtr;
451  if(symbol < kFormatSymbolCount) {
452  strPtr = &fSymbols[symbol];
453  } else {
454  strPtr = &fNoSymbol;
455  }
456  return *strPtr;
457 }
458 
459 // -------------------------------------
460 
461 inline void
462 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
463  if (symbol == kCurrencySymbol) {
464  fIsCustomCurrencySymbol = TRUE;
465  }
466  else if (symbol == kIntlCurrencySymbol) {
467  fIsCustomIntlCurrencySymbol = TRUE;
468  }
469  if(symbol<kFormatSymbolCount) {
470  fSymbols[symbol]=value;
471  }
472 
473  // If the zero digit is being set to a known zero digit according to Unicode,
474  // then we automatically set the corresponding 1-9 digits
475  if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
476  UChar32 sym = value.char32At(0);
477  if ( u_charDigitValue(sym) == 0 ) {
478  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
479  sym++;
480  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
481  }
482  }
483  }
484 }
485 
486 // -------------------------------------
487 
488 inline Locale
490  return locale;
491 }
492 
493 #ifndef U_HIDE_INTERNAL_API
494 inline const UChar*
496  return currPattern;
497 }
498 #endif /* U_HIDE_INTERNAL_API */
499 
501 
502 #endif /* #if !UCONFIG_NO_FORMATTING */
503 
504 #endif // _DCFMTSYM
505 //eof
UBool isCustomCurrencySymbol() const
Definition: dcfmtsym.h:364
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
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:489
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:321
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
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:462
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:360
UnicodeString getSymbol(ENumberFormatSymbol symbol) const
Get one of the format symbols by its enum constant.
Definition: dcfmtsym.h:437
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:357
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:263
C API: Unicode Properties.
C++ API: Common ICU base class UObject.
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:337
UBool isCustomIntlCurrencySymbol() const
Definition: dcfmtsym.h:371
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
const UChar * getCurrencyPattern(void) const
Returns that pattern stored in currecy info.
Definition: dcfmtsym.h:495
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
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 UChar 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:267
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
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:335
UBool operator!=(const DecimalFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dcfmtsym.h:249
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:449
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:259
C API: NumberFormat.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187