ICU 54.1  54.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dcfmtsym.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2014, 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:
171  kFormatSymbolCount
172  };
173 
182  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
183 
195 
211  static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
212 
218 
223  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
224 
229  virtual ~DecimalFormatSymbols();
230 
238  UBool operator==(const DecimalFormatSymbols& other) const;
239 
247  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
248 
258  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
259 
272  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
273 
278  inline Locale getLocale() const;
279 
285  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
286 
303  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
304  UBool beforeCurrency,
305  UErrorCode& status) const;
316  void setPatternForCurrencySpacing(UCurrencySpacing type,
317  UBool beforeCurrency,
318  const UnicodeString& pattern);
319 
325  virtual UClassID getDynamicClassID() const;
326 
332  static UClassID U_EXPORT2 getStaticClassID();
333 
334 private:
336 
347  void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
348 
352  void initialize();
353 
354  void setCurrencyForSymbols();
355 
356 public:
369  inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
370 
371 #ifndef U_HIDE_INTERNAL_API
372 
376  inline const UChar* getCurrencyPattern(void) const;
377 #endif /* U_HIDE_INTERNAL_API */
378 
379 private:
395  UnicodeString fSymbols[kFormatSymbolCount];
396 
401  UnicodeString fNoSymbol;
402 
403  Locale locale;
404 
405  char actualLocale[ULOC_FULLNAME_CAPACITY];
406  char validLocale[ULOC_FULLNAME_CAPACITY];
407  const UChar* currPattern;
408 
409  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
410  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
411 };
412 
413 // -------------------------------------
414 
415 inline UnicodeString
416 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
417  const UnicodeString *strPtr;
418  if(symbol < kFormatSymbolCount) {
419  strPtr = &fSymbols[symbol];
420  } else {
421  strPtr = &fNoSymbol;
422  }
423  return *strPtr;
424 }
425 
426 //#ifndef U_HIDE_INTERNAL_API
427 // See comments above for this function. Not hidden.
428 inline const UnicodeString &
429 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
430  const UnicodeString *strPtr;
431  if(symbol < kFormatSymbolCount) {
432  strPtr = &fSymbols[symbol];
433  } else {
434  strPtr = &fNoSymbol;
435  }
436  return *strPtr;
437 }
438 
439 //#endif /* U_HIDE_INTERNAL_API */
440 
441 
442 // -------------------------------------
443 
444 inline void
445 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
446  if(symbol<kFormatSymbolCount) {
447  fSymbols[symbol]=value;
448  }
449 
450  // If the zero digit is being set to a known zero digit according to Unicode,
451  // then we automatically set the corresponding 1-9 digits
452  if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
453  UChar32 sym = value.char32At(0);
454  if ( u_charDigitValue(sym) == 0 ) {
455  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
456  sym++;
457  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
458  }
459  }
460  }
461 }
462 
463 // -------------------------------------
464 
465 inline Locale
466 DecimalFormatSymbols::getLocale() const {
467  return locale;
468 }
469 
470 #ifndef U_HIDE_INTERNAL_API
471 inline const UChar*
472 DecimalFormatSymbols::getCurrencyPattern() const {
473  return currPattern;
474 }
475 #endif /* U_HIDE_INTERNAL_API */
476 
478 
479 #endif /* #if !UCONFIG_NO_FORMATTING */
480 
481 #endif // _DCFMTSYM
482 //eof