ICU 4.8.1.1  4.8.1.1
 All Data Structures 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-2011, 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:
167  kFormatSymbolCount
168  };
169 
178  DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
179 
191 
197 
202  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
203 
208  virtual ~DecimalFormatSymbols();
209 
217  UBool operator==(const DecimalFormatSymbols& other) const;
218 
226  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
227 
237  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
238 
251  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
252 
257  inline Locale getLocale() const;
258 
264  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
265 
282  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
283  UBool beforeCurrency,
284  UErrorCode& status) const;
295  void setPatternForCurrencySpacing(UCurrencySpacing type,
296  UBool beforeCurrency,
297  const UnicodeString& pattern);
298 
304  virtual UClassID getDynamicClassID() const;
305 
311  static UClassID U_EXPORT2 getStaticClassID();
312 
313 private:
314  DecimalFormatSymbols(); // default constructor not implemented
315 
326  void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
327 
331  void initialize();
332 
333  void setCurrencyForSymbols();
334 
335 public:
347  inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
348 
353  inline const UChar* getCurrencyPattern(void) const;
354 
355 private:
371  UnicodeString fSymbols[kFormatSymbolCount];
372 
377  UnicodeString fNoSymbol;
378 
379  Locale locale;
380 
381  char actualLocale[ULOC_FULLNAME_CAPACITY];
382  char validLocale[ULOC_FULLNAME_CAPACITY];
383  const UChar* currPattern;
384 
385  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
386  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
387 };
388 
389 // -------------------------------------
390 
391 inline UnicodeString
393  const UnicodeString *strPtr;
394  if(symbol < kFormatSymbolCount) {
395  strPtr = &fSymbols[symbol];
396  } else {
397  strPtr = &fNoSymbol;
398  }
399  return *strPtr;
400 }
401 
402 inline const UnicodeString &
404  const UnicodeString *strPtr;
405  if(symbol < kFormatSymbolCount) {
406  strPtr = &fSymbols[symbol];
407  } else {
408  strPtr = &fNoSymbol;
409  }
410  return *strPtr;
411 }
412 
413 // -------------------------------------
414 
415 inline void
416 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
417  if(symbol<kFormatSymbolCount) {
418  fSymbols[symbol]=value;
419  }
420 
421  // If the zero digit is being set to a known zero digit according to Unicode,
422  // then we automatically set the corresponding 1-9 digits
423  if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
424  UChar32 sym = value.char32At(0);
425  if ( u_charDigitValue(sym) == 0 ) {
426  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
427  sym++;
428  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
429  }
430  }
431  }
432 }
433 
434 // -------------------------------------
435 
436 inline Locale
438  return locale;
439 }
440 
441 inline const UChar*
443  return currPattern;
444 }
446 
447 #endif /* #if !UCONFIG_NO_FORMATTING */
448 
449 #endif // _DCFMTSYM
450 //eof