ICU 52.1  52.1
dcfmtsym.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2013, 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 
192 #ifndef U_HIDE_DRAFT_API
193 
208  static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
209 #endif /* U_HIDE_DRAFT_API */
210 
216 
221  DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
222 
227  virtual ~DecimalFormatSymbols();
228 
236  UBool operator==(const DecimalFormatSymbols& other) const;
237 
245  UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
246 
256  inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
257 
270  void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
271 
276  inline Locale getLocale() const;
277 
283  Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
284 
301  const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
302  UBool beforeCurrency,
303  UErrorCode& status) const;
314  void setPatternForCurrencySpacing(UCurrencySpacing type,
315  UBool beforeCurrency,
316  const UnicodeString& pattern);
317 
323  virtual UClassID getDynamicClassID() const;
324 
330  static UClassID U_EXPORT2 getStaticClassID();
331 
332 private:
334 
345  void initialize(const Locale& locale, UErrorCode& success, UBool useLastResortData = FALSE);
346 
350  void initialize();
351 
352  void setCurrencyForSymbols();
353 
354 public:
355 #ifndef U_HIDE_INTERNAL_API
356 
367  inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
368 
373  inline const UChar* getCurrencyPattern(void) const;
374 #endif /* U_HIDE_INTERNAL_API */
375 
376 private:
392  UnicodeString fSymbols[kFormatSymbolCount];
393 
398  UnicodeString fNoSymbol;
399 
400  Locale locale;
401 
402  char actualLocale[ULOC_FULLNAME_CAPACITY];
403  char validLocale[ULOC_FULLNAME_CAPACITY];
404  const UChar* currPattern;
405 
406  UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
407  UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
408 };
409 
410 // -------------------------------------
411 
412 inline UnicodeString
413 DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
414  const UnicodeString *strPtr;
415  if(symbol < kFormatSymbolCount) {
416  strPtr = &fSymbols[symbol];
417  } else {
418  strPtr = &fNoSymbol;
419  }
420  return *strPtr;
421 }
422 
423 #ifndef U_HIDE_INTERNAL_API
424 
425 inline const UnicodeString &
426 DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
427  const UnicodeString *strPtr;
428  if(symbol < kFormatSymbolCount) {
429  strPtr = &fSymbols[symbol];
430  } else {
431  strPtr = &fNoSymbol;
432  }
433  return *strPtr;
434 }
435 
436 #endif /* U_HIDE_INTERNAL_API */
437 
438 
439 // -------------------------------------
440 
441 inline void
442 DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
443  if(symbol<kFormatSymbolCount) {
444  fSymbols[symbol]=value;
445  }
446 
447  // If the zero digit is being set to a known zero digit according to Unicode,
448  // then we automatically set the corresponding 1-9 digits
449  if ( propogateDigits && symbol == kZeroDigitSymbol && value.countChar32() == 1 ) {
450  UChar32 sym = value.char32At(0);
451  if ( u_charDigitValue(sym) == 0 ) {
452  for ( int8_t i = 1 ; i<= 9 ; i++ ) {
453  sym++;
454  fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
455  }
456  }
457  }
458 }
459 
460 // -------------------------------------
461 
462 inline Locale
463 DecimalFormatSymbols::getLocale() const {
464  return locale;
465 }
466 
467 #ifndef U_HIDE_INTERNAL_API
468 inline const UChar*
469 DecimalFormatSymbols::getCurrencyPattern() const {
470  return currPattern;
471 }
472 #endif /* U_HIDE_INTERNAL_API */
473 
475 
476 #endif /* #if !UCONFIG_NO_FORMATTING */
477 
478 #endif // _DCFMTSYM
479 //eof