ICU 49.1.1  49.1.1
numfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2012, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 ********************************************************************************
6 *
7 * File NUMFMT.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 * 04/17/97 aliu Changed DigitCount to int per code review.
15 * 07/20/98 stephen JDK 1.2 sync up. Added scientific support.
16 * Changed naming conventions to match C++ guidelines
17 * Derecated Java style constants (eg, INTEGER_FIELD)
18 ********************************************************************************
19 */
20 
21 #ifndef NUMFMT_H
22 #define NUMFMT_H
23 
24 
25 #include "unicode/utypes.h"
26 
32 #if !UCONFIG_NO_FORMATTING
33 
34 #include "unicode/unistr.h"
35 #include "unicode/format.h"
36 #include "unicode/unum.h" // UNumberFormatStyle
37 #include "unicode/locid.h"
38 #include "unicode/stringpiece.h"
39 #include "unicode/curramt.h"
40 
41 class NumberFormatTest;
42 
44 
45 #if !UCONFIG_NO_SERVICE
47 class StringEnumeration;
48 #endif
49 
167 public:
185  kIntegerField = UNUM_INTEGER_FIELD,
187  kFractionField = UNUM_FRACTION_FIELD,
189  kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD,
191  kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD,
193  kExponentSignField = UNUM_EXPONENT_SIGN_FIELD,
195  kExponentField = UNUM_EXPONENT_FIELD,
197  kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD,
199  kCurrencyField = UNUM_CURRENCY_FIELD,
201  kPercentField = UNUM_PERCENT_FIELD,
203  kPermillField = UNUM_PERMILL_FIELD,
205  kSignField = UNUM_SIGN_FIELD,
206 
212  INTEGER_FIELD = UNUM_INTEGER_FIELD,
214  FRACTION_FIELD = UNUM_FRACTION_FIELD
215  };
216 
221  virtual ~NumberFormat();
222 
229  virtual UBool operator==(const Format& other) const;
230 
231 
232  using Format::format;
233 
249  virtual UnicodeString& format(const Formattable& obj,
250  UnicodeString& appendTo,
251  FieldPosition& pos,
252  UErrorCode& status) const;
253 
270  virtual UnicodeString& format(const Formattable& obj,
271  UnicodeString& appendTo,
272  FieldPositionIterator* posIter,
273  UErrorCode& status) const;
274 
303  virtual void parseObject(const UnicodeString& source,
304  Formattable& result,
305  ParsePosition& parse_pos) const;
306 
317  UnicodeString& format( double number,
318  UnicodeString& appendTo) const;
319 
330  UnicodeString& format( int32_t number,
331  UnicodeString& appendTo) const;
332 
343  UnicodeString& format( int64_t number,
344  UnicodeString& appendTo) const;
345 
358  virtual UnicodeString& format(double number,
359  UnicodeString& appendTo,
360  FieldPosition& pos) const = 0;
375  virtual UnicodeString& format(double number,
376  UnicodeString& appendTo,
377  FieldPositionIterator* posIter,
378  UErrorCode& status) const;
391  virtual UnicodeString& format(int32_t number,
392  UnicodeString& appendTo,
393  FieldPosition& pos) const = 0;
394 
409  virtual UnicodeString& format(int32_t number,
410  UnicodeString& appendTo,
411  FieldPositionIterator* posIter,
412  UErrorCode& status) const;
426  virtual UnicodeString& format(int64_t number,
427  UnicodeString& appendTo,
428  FieldPosition& pos) const;
443  virtual UnicodeString& format(int64_t number,
444  UnicodeString& appendTo,
445  FieldPositionIterator* posIter,
446  UErrorCode& status) const;
447 
464  virtual UnicodeString& format(const StringPiece &number,
465  UnicodeString& appendTo,
466  FieldPositionIterator* posIter,
467  UErrorCode& status) const;
468 public:
486  virtual UnicodeString& format(const DigitList &number,
487  UnicodeString& appendTo,
488  FieldPositionIterator* posIter,
489  UErrorCode& status) const;
490 
508  virtual UnicodeString& format(const DigitList &number,
509  UnicodeString& appendTo,
510  FieldPosition& pos,
511  UErrorCode& status) const;
512 
513 public:
514 
525  UnicodeString& format(const Formattable& obj,
526  UnicodeString& appendTo,
527  UErrorCode& status) const;
528 
550  virtual void parse(const UnicodeString& text,
551  Formattable& result,
552  ParsePosition& parsePosition) const = 0;
553 
569  virtual void parse( const UnicodeString& text,
570  Formattable& result,
571  UErrorCode& status) const;
572 
573 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
593  virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
594  ParsePosition& pos) const;
595 
607  UBool isParseIntegerOnly(void) const;
608 
616  virtual void setParseIntegerOnly(UBool value);
617 
625  virtual void setLenient(UBool enable);
626 
635  virtual UBool isLenient(void) const;
636 
645  static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
646 
655  static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
656  UErrorCode&);
657 
666  static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale,
667  UNumberFormatStyle style,
668  UErrorCode& errorCode);
669 
674  static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
675 
681  static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
682  UErrorCode&);
683 
688  static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
689 
695  static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
696  UErrorCode&);
697 
702  static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
703 
709  static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
710  UErrorCode&);
711 
717  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
718 
719 #if !UCONFIG_NO_SERVICE
720 
727  static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
728 
738  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
739 
746  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
747 #endif /* UCONFIG_NO_SERVICE */
748 
758  UBool isGroupingUsed(void) const;
759 
766  virtual void setGroupingUsed(UBool newValue);
767 
776  int32_t getMaximumIntegerDigits(void) const;
777 
790  virtual void setMaximumIntegerDigits(int32_t newValue);
791 
800  int32_t getMinimumIntegerDigits(void) const;
801 
812  virtual void setMinimumIntegerDigits(int32_t newValue);
813 
822  int32_t getMaximumFractionDigits(void) const;
823 
834  virtual void setMaximumFractionDigits(int32_t newValue);
835 
844  int32_t getMinimumFractionDigits(void) const;
845 
856  virtual void setMinimumFractionDigits(int32_t newValue);
857 
870  virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
871 
879  const UChar* getCurrency() const;
880 
881 public:
882 
891  static UClassID U_EXPORT2 getStaticClassID(void);
892 
904  virtual UClassID getDynamicClassID(void) const = 0;
905 
906 protected:
907 
912  NumberFormat();
913 
918  NumberFormat(const NumberFormat&);
919 
925 
934  virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
935 
936 private:
937 
938  static UBool isStyleSupported(UNumberFormatStyle style);
939 
947  static NumberFormat* makeInstance(const Locale& desiredLocale,
948  UNumberFormatStyle style,
949  UErrorCode& errorCode);
950 
951  UBool fGroupingUsed;
952  int32_t fMaxIntegerDigits;
953  int32_t fMinIntegerDigits;
954  int32_t fMaxFractionDigits;
955  int32_t fMinFractionDigits;
956  UBool fParseIntegerOnly;
957  UBool fLenient; // TRUE => lenient parse is enabled
958 
959  // ISO currency code
960  UChar fCurrency[4];
961 
962  friend class ICUNumberFormatFactory; // access to makeInstance
963  friend class ICUNumberFormatService;
964  friend class ::NumberFormatTest; // access to isStyleSupported()
965 };
966 
967 #if !UCONFIG_NO_SERVICE
968 
977 public:
978 
983  virtual ~NumberFormatFactory();
984 
991  virtual UBool visible(void) const = 0;
992 
998  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
999 
1007  virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
1008 };
1009 
1015 protected:
1021 
1027 
1028 public:
1032  SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
1033 
1037  virtual ~SimpleNumberFormatFactory();
1038 
1042  virtual UBool visible(void) const;
1043 
1047  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
1048 };
1049 #endif /* #if !UCONFIG_NO_SERVICE */
1050 
1051 // -------------------------------------
1052 
1053 inline UBool
1055 {
1056  return fParseIntegerOnly;
1057 }
1058 
1059 inline UBool
1061 {
1062  return fLenient;
1063 }
1064 
1065 inline UnicodeString&
1067  UnicodeString& appendTo,
1068  UErrorCode& status) const {
1069  return Format::format(obj, appendTo, status);
1070 }
1071 
1073 
1074 #endif /* #if !UCONFIG_NO_FORMATTING */
1075 
1076 #endif // _NUMFMT
1077 //eof