ICU 54.1 54.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
numfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2014, 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 #include "unicode/udisplaycontext.h"
41
42 class NumberFormatTest;
43
44 U_NAMESPACE_BEGIN
45
46 class SharedNumberFormat;
47
48 #if !UCONFIG_NO_SERVICE
49 class NumberFormatFactory;
50 class StringEnumeration;
51 #endif
52
172 class U_I18N_API NumberFormat : public Format {
173 public:
189 enum EAlignmentFields {
191 kIntegerField = UNUM_INTEGER_FIELD,
193 kFractionField = UNUM_FRACTION_FIELD,
195 kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD,
197 kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD,
199 kExponentSignField = UNUM_EXPONENT_SIGN_FIELD,
201 kExponentField = UNUM_EXPONENT_FIELD,
203 kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD,
205 kCurrencyField = UNUM_CURRENCY_FIELD,
207 kPercentField = UNUM_PERCENT_FIELD,
209 kPermillField = UNUM_PERMILL_FIELD,
211 kSignField = UNUM_SIGN_FIELD,
212
218 INTEGER_FIELD = UNUM_INTEGER_FIELD,
220 FRACTION_FIELD = UNUM_FRACTION_FIELD
221 };
222
227 virtual ~NumberFormat();
228
235 virtual UBool operator==(const Format& other) const;
236
237
238 using Format::format;
239
255 virtual UnicodeString& format(const Formattable& obj,
256 UnicodeString& appendTo,
257 FieldPosition& pos,
258 UErrorCode& status) const;
259
276 virtual UnicodeString& format(const Formattable& obj,
277 UnicodeString& appendTo,
278 FieldPositionIterator* posIter,
279 UErrorCode& status) const;
280
309 virtual void parseObject(const UnicodeString& source,
310 Formattable& result,
311 ParsePosition& parse_pos) const;
312
323 UnicodeString& format( double number,
324 UnicodeString& appendTo) const;
325
336 UnicodeString& format( int32_t number,
337 UnicodeString& appendTo) const;
338
349 UnicodeString& format( int64_t number,
350 UnicodeString& appendTo) const;
351
364 virtual UnicodeString& format(double number,
365 UnicodeString& appendTo,
366 FieldPosition& pos) const = 0;
381 virtual UnicodeString& format(double number,
382 UnicodeString& appendTo,
383 FieldPosition& pos,
384 UErrorCode &status) const;
399 virtual UnicodeString& format(double number,
400 UnicodeString& appendTo,
401 FieldPositionIterator* posIter,
402 UErrorCode& status) const;
415 virtual UnicodeString& format(int32_t number,
416 UnicodeString& appendTo,
417 FieldPosition& pos) const = 0;
418
432 virtual UnicodeString& format(int32_t number,
433 UnicodeString& appendTo,
434 FieldPosition& pos,
435 UErrorCode &status) const;
436
451 virtual UnicodeString& format(int32_t number,
452 UnicodeString& appendTo,
453 FieldPositionIterator* posIter,
454 UErrorCode& status) const;
468 virtual UnicodeString& format(int64_t number,
469 UnicodeString& appendTo,
470 FieldPosition& pos) const;
471
485 virtual UnicodeString& format(int64_t number,
486 UnicodeString& appendTo,
487 FieldPosition& pos,
488 UErrorCode& status) const;
503 virtual UnicodeString& format(int64_t number,
504 UnicodeString& appendTo,
505 FieldPositionIterator* posIter,
506 UErrorCode& status) const;
507
524 virtual UnicodeString& format(const StringPiece &number,
525 UnicodeString& appendTo,
526 FieldPositionIterator* posIter,
527 UErrorCode& status) const;
528 public:
546 virtual UnicodeString& format(const DigitList &number,
547 UnicodeString& appendTo,
548 FieldPositionIterator* posIter,
549 UErrorCode& status) const;
550
568 virtual UnicodeString& format(const DigitList &number,
569 UnicodeString& appendTo,
570 FieldPosition& pos,
571 UErrorCode& status) const;
572
573 public:
574
594 virtual void parse(const UnicodeString& text,
595 Formattable& result,
596 ParsePosition& parsePosition) const = 0;
597
611 virtual void parse(const UnicodeString& text,
612 Formattable& result,
613 UErrorCode& status) const;
614
634 virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
635 ParsePosition& pos) const;
636
648 UBool isParseIntegerOnly(void) const;
649
657 virtual void setParseIntegerOnly(UBool value);
658
666 virtual void setLenient(UBool enable);
667
676 virtual UBool isLenient(void) const;
677
686 static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
687
696 static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
697 UErrorCode&);
698
707 static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale,
708 UNumberFormatStyle style,
709 UErrorCode& errorCode);
710
711 #ifndef U_HIDE_INTERNAL_API
712
718 static NumberFormat* internalCreateInstance(
719 const Locale& desiredLocale,
720 UNumberFormatStyle style,
721 UErrorCode& errorCode);
722
730 static const SharedNumberFormat* U_EXPORT2 createSharedInstance(
731 const Locale& inLocale, UNumberFormatStyle style, UErrorCode& status);
732
733 #endif /* U_HIDE_INTERNAL_API */
734
739 static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
740
746 static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
747 UErrorCode&);
748
753 static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
754
760 static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
761 UErrorCode&);
762
767 static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
768
774 static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
775 UErrorCode&);
776
782 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
783
784 #if !UCONFIG_NO_SERVICE
785
795 static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
796
809 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
810
817 static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
818 #endif /* UCONFIG_NO_SERVICE */
819
829 UBool isGroupingUsed(void) const;
830
837 virtual void setGroupingUsed(UBool newValue);
838
847 int32_t getMaximumIntegerDigits(void) const;
848
861 virtual void setMaximumIntegerDigits(int32_t newValue);
862
871 int32_t getMinimumIntegerDigits(void) const;
872
883 virtual void setMinimumIntegerDigits(int32_t newValue);
884
893 int32_t getMaximumFractionDigits(void) const;
894
905 virtual void setMaximumFractionDigits(int32_t newValue);
906
915 int32_t getMinimumFractionDigits(void) const;
916
927 virtual void setMinimumFractionDigits(int32_t newValue);
928
941 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
942
950 const UChar* getCurrency() const;
951
952 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
962 virtual void setContext(UDisplayContext value, UErrorCode& status);
963
964 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
975 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
976
977 public:
978
987 static UClassID U_EXPORT2 getStaticClassID(void);
988
1000 virtual UClassID getDynamicClassID(void) const = 0;
1001
1002 protected:
1003
1008 NumberFormat();
1009
1014 NumberFormat(const NumberFormat&);
1015
1020 NumberFormat& operator=(const NumberFormat&);
1021
1030 virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
1031
1032 #ifndef U_HIDE_INTERNAL_API
1033
1039 static NumberFormat* makeInstance(const Locale& desiredLocale,
1040 UNumberFormatStyle style,
1041 UBool mustBeDecimalFormat,
1042 UErrorCode& errorCode);
1043 #endif /* U_HIDE_INTERNAL_API */
1044
1045 private:
1046
1047 static UBool isStyleSupported(UNumberFormatStyle style);
1048
1056 static NumberFormat* makeInstance(const Locale& desiredLocale,
1057 UNumberFormatStyle style,
1058 UErrorCode& errorCode);
1059
1060 UBool fGroupingUsed;
1061 int32_t fMaxIntegerDigits;
1062 int32_t fMinIntegerDigits;
1063 int32_t fMaxFractionDigits;
1064 int32_t fMinFractionDigits;
1065
1066 protected:
1067 static const int32_t gDefaultMaxIntegerDigits;
1068 static const int32_t gDefaultMinIntegerDigits;
1069
1070 private:
1071 UBool fParseIntegerOnly;
1072 UBool fLenient; // TRUE => lenient parse is enabled
1073
1074 // ISO currency code
1075 UChar fCurrency[4];
1076
1077 UDisplayContext fCapitalizationContext;
1078
1079 friend class ICUNumberFormatFactory; // access to makeInstance
1080 friend class ICUNumberFormatService;
1081 friend class ::NumberFormatTest; // access to isStyleSupported()
1082 };
1083
1084 #if !UCONFIG_NO_SERVICE
1085
1093 class U_I18N_API NumberFormatFactory : public UObject {
1094 public:
1095
1100 virtual ~NumberFormatFactory();
1101
1108 virtual UBool visible(void) const = 0;
1109
1115 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
1116
1124 virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
1125 };
1126
1131 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
1132 protected:
1137 const UBool _visible;
1138
1143 UnicodeString _id;
1144
1145 public:
1149 SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
1150
1154 virtual ~SimpleNumberFormatFactory();
1155
1159 virtual UBool visible(void) const;
1160
1164 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
1165 };
1166 #endif /* #if !UCONFIG_NO_SERVICE */
1167
1168 // -------------------------------------
1169
1170 inline UBool
1171 NumberFormat::isParseIntegerOnly() const
1172 {
1173 return fParseIntegerOnly;
1174 }
1175
1176 inline UBool
1177 NumberFormat::isLenient() const
1178 {
1179 return fLenient;
1180 }
1181
1182 U_NAMESPACE_END
1183
1184 #endif /* #if !UCONFIG_NO_FORMATTING */
1185
1186 #endif // _NUMFMT
1187 //eof