ICU 49.1.1
49.1.1
|
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2012, International Business Machines Corporation and others. 00004 * All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File NUMFMT.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 02/19/97 aliu Converted from java. 00013 * 03/18/97 clhuang Updated per C++ implementation. 00014 * 04/17/97 aliu Changed DigitCount to int per code review. 00015 * 07/20/98 stephen JDK 1.2 sync up. Added scientific support. 00016 * Changed naming conventions to match C++ guidelines 00017 * Derecated Java style constants (eg, INTEGER_FIELD) 00018 ******************************************************************************** 00019 */ 00020 00021 #ifndef NUMFMT_H 00022 #define NUMFMT_H 00023 00024 00025 #include "unicode/utypes.h" 00026 00032 #if !UCONFIG_NO_FORMATTING 00033 00034 #include "unicode/unistr.h" 00035 #include "unicode/format.h" 00036 #include "unicode/unum.h" // UNumberFormatStyle 00037 #include "unicode/locid.h" 00038 #include "unicode/stringpiece.h" 00039 #include "unicode/curramt.h" 00040 00041 class NumberFormatTest; 00042 00043 U_NAMESPACE_BEGIN 00044 00045 #if !UCONFIG_NO_SERVICE 00046 class NumberFormatFactory; 00047 class StringEnumeration; 00048 #endif 00049 00166 class U_I18N_API NumberFormat : public Format { 00167 public: 00183 enum EAlignmentFields { 00185 kIntegerField = UNUM_INTEGER_FIELD, 00187 kFractionField = UNUM_FRACTION_FIELD, 00189 kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD, 00191 kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD, 00193 kExponentSignField = UNUM_EXPONENT_SIGN_FIELD, 00195 kExponentField = UNUM_EXPONENT_FIELD, 00197 kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD, 00199 kCurrencyField = UNUM_CURRENCY_FIELD, 00201 kPercentField = UNUM_PERCENT_FIELD, 00203 kPermillField = UNUM_PERMILL_FIELD, 00205 kSignField = UNUM_SIGN_FIELD, 00206 00212 INTEGER_FIELD = UNUM_INTEGER_FIELD, 00214 FRACTION_FIELD = UNUM_FRACTION_FIELD 00215 }; 00216 00221 virtual ~NumberFormat(); 00222 00229 virtual UBool operator==(const Format& other) const; 00230 00231 00232 using Format::format; 00233 00249 virtual UnicodeString& format(const Formattable& obj, 00250 UnicodeString& appendTo, 00251 FieldPosition& pos, 00252 UErrorCode& status) const; 00253 00270 virtual UnicodeString& format(const Formattable& obj, 00271 UnicodeString& appendTo, 00272 FieldPositionIterator* posIter, 00273 UErrorCode& status) const; 00274 00303 virtual void parseObject(const UnicodeString& source, 00304 Formattable& result, 00305 ParsePosition& parse_pos) const; 00306 00317 UnicodeString& format( double number, 00318 UnicodeString& appendTo) const; 00319 00330 UnicodeString& format( int32_t number, 00331 UnicodeString& appendTo) const; 00332 00343 UnicodeString& format( int64_t number, 00344 UnicodeString& appendTo) const; 00345 00358 virtual UnicodeString& format(double number, 00359 UnicodeString& appendTo, 00360 FieldPosition& pos) const = 0; 00375 virtual UnicodeString& format(double number, 00376 UnicodeString& appendTo, 00377 FieldPositionIterator* posIter, 00378 UErrorCode& status) const; 00391 virtual UnicodeString& format(int32_t number, 00392 UnicodeString& appendTo, 00393 FieldPosition& pos) const = 0; 00394 00409 virtual UnicodeString& format(int32_t number, 00410 UnicodeString& appendTo, 00411 FieldPositionIterator* posIter, 00412 UErrorCode& status) const; 00426 virtual UnicodeString& format(int64_t number, 00427 UnicodeString& appendTo, 00428 FieldPosition& pos) const; 00443 virtual UnicodeString& format(int64_t number, 00444 UnicodeString& appendTo, 00445 FieldPositionIterator* posIter, 00446 UErrorCode& status) const; 00447 00464 virtual UnicodeString& format(const StringPiece &number, 00465 UnicodeString& appendTo, 00466 FieldPositionIterator* posIter, 00467 UErrorCode& status) const; 00468 public: 00486 virtual UnicodeString& format(const DigitList &number, 00487 UnicodeString& appendTo, 00488 FieldPositionIterator* posIter, 00489 UErrorCode& status) const; 00490 00508 virtual UnicodeString& format(const DigitList &number, 00509 UnicodeString& appendTo, 00510 FieldPosition& pos, 00511 UErrorCode& status) const; 00512 00513 public: 00514 00525 UnicodeString& format(const Formattable& obj, 00526 UnicodeString& appendTo, 00527 UErrorCode& status) const; 00528 00550 virtual void parse(const UnicodeString& text, 00551 Formattable& result, 00552 ParsePosition& parsePosition) const = 0; 00553 00569 virtual void parse( const UnicodeString& text, 00570 Formattable& result, 00571 UErrorCode& status) const; 00572 00573 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */ 00593 virtual CurrencyAmount* parseCurrency(const UnicodeString& text, 00594 ParsePosition& pos) const; 00595 00607 UBool isParseIntegerOnly(void) const; 00608 00616 virtual void setParseIntegerOnly(UBool value); 00617 00625 virtual void setLenient(UBool enable); 00626 00635 virtual UBool isLenient(void) const; 00636 00645 static NumberFormat* U_EXPORT2 createInstance(UErrorCode&); 00646 00655 static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale, 00656 UErrorCode&); 00657 00666 static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, 00667 UNumberFormatStyle style, 00668 UErrorCode& errorCode); 00669 00674 static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&); 00675 00681 static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale, 00682 UErrorCode&); 00683 00688 static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&); 00689 00695 static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale, 00696 UErrorCode&); 00697 00702 static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&); 00703 00709 static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale, 00710 UErrorCode&); 00711 00717 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); 00718 00719 #if !UCONFIG_NO_SERVICE 00720 00727 static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status); 00728 00738 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); 00739 00746 static StringEnumeration* U_EXPORT2 getAvailableLocales(void); 00747 #endif /* UCONFIG_NO_SERVICE */ 00748 00758 UBool isGroupingUsed(void) const; 00759 00766 virtual void setGroupingUsed(UBool newValue); 00767 00776 int32_t getMaximumIntegerDigits(void) const; 00777 00790 virtual void setMaximumIntegerDigits(int32_t newValue); 00791 00800 int32_t getMinimumIntegerDigits(void) const; 00801 00812 virtual void setMinimumIntegerDigits(int32_t newValue); 00813 00822 int32_t getMaximumFractionDigits(void) const; 00823 00834 virtual void setMaximumFractionDigits(int32_t newValue); 00835 00844 int32_t getMinimumFractionDigits(void) const; 00845 00856 virtual void setMinimumFractionDigits(int32_t newValue); 00857 00870 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); 00871 00879 const UChar* getCurrency() const; 00880 00881 public: 00882 00891 static UClassID U_EXPORT2 getStaticClassID(void); 00892 00904 virtual UClassID getDynamicClassID(void) const = 0; 00905 00906 protected: 00907 00912 NumberFormat(); 00913 00918 NumberFormat(const NumberFormat&); 00919 00924 NumberFormat& operator=(const NumberFormat&); 00925 00934 virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const; 00935 00936 private: 00937 00938 static UBool isStyleSupported(UNumberFormatStyle style); 00939 00947 static NumberFormat* makeInstance(const Locale& desiredLocale, 00948 UNumberFormatStyle style, 00949 UErrorCode& errorCode); 00950 00951 UBool fGroupingUsed; 00952 int32_t fMaxIntegerDigits; 00953 int32_t fMinIntegerDigits; 00954 int32_t fMaxFractionDigits; 00955 int32_t fMinFractionDigits; 00956 UBool fParseIntegerOnly; 00957 UBool fLenient; // TRUE => lenient parse is enabled 00958 00959 // ISO currency code 00960 UChar fCurrency[4]; 00961 00962 friend class ICUNumberFormatFactory; // access to makeInstance 00963 friend class ICUNumberFormatService; 00964 friend class ::NumberFormatTest; // access to isStyleSupported() 00965 }; 00966 00967 #if !UCONFIG_NO_SERVICE 00968 00976 class U_I18N_API NumberFormatFactory : public UObject { 00977 public: 00978 00983 virtual ~NumberFormatFactory(); 00984 00991 virtual UBool visible(void) const = 0; 00992 00998 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0; 00999 01007 virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0; 01008 }; 01009 01014 class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory { 01015 protected: 01020 const UBool _visible; 01021 01026 UnicodeString _id; 01027 01028 public: 01032 SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE); 01033 01037 virtual ~SimpleNumberFormatFactory(); 01038 01042 virtual UBool visible(void) const; 01043 01047 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const; 01048 }; 01049 #endif /* #if !UCONFIG_NO_SERVICE */ 01050 01051 // ------------------------------------- 01052 01053 inline UBool 01054 NumberFormat::isParseIntegerOnly() const 01055 { 01056 return fParseIntegerOnly; 01057 } 01058 01059 inline UBool 01060 NumberFormat::isLenient() const 01061 { 01062 return fLenient; 01063 } 01064 01065 inline UnicodeString& 01066 NumberFormat::format(const Formattable& obj, 01067 UnicodeString& appendTo, 01068 UErrorCode& status) const { 01069 return Format::format(obj, appendTo, status); 01070 } 01071 01072 U_NAMESPACE_END 01073 01074 #endif /* #if !UCONFIG_NO_FORMATTING */ 01075 01076 #endif // _NUMFMT 01077 //eof