| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************** | 2 ******************************************************************************** |
| 3 * Copyright (C) 1997-2013, International Business Machines Corporation and other
s. | 3 * Copyright (C) 1997-2014, International Business Machines Corporation and other
s. |
| 4 * All Rights Reserved. | 4 * All Rights Reserved. |
| 5 ******************************************************************************** | 5 ******************************************************************************** |
| 6 * | 6 * |
| 7 * File NUMFMT.H | 7 * File NUMFMT.H |
| 8 * | 8 * |
| 9 * Modification History: | 9 * Modification History: |
| 10 * | 10 * |
| 11 * Date Name Description | 11 * Date Name Description |
| 12 * 02/19/97 aliu Converted from java. | 12 * 02/19/97 aliu Converted from java. |
| 13 * 03/18/97 clhuang Updated per C++ implementation. | 13 * 03/18/97 clhuang Updated per C++ implementation. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #if !UCONFIG_NO_FORMATTING | 32 #if !UCONFIG_NO_FORMATTING |
| 33 | 33 |
| 34 #include "unicode/unistr.h" | 34 #include "unicode/unistr.h" |
| 35 #include "unicode/format.h" | 35 #include "unicode/format.h" |
| 36 #include "unicode/unum.h" // UNumberFormatStyle | 36 #include "unicode/unum.h" // UNumberFormatStyle |
| 37 #include "unicode/locid.h" | 37 #include "unicode/locid.h" |
| 38 #include "unicode/stringpiece.h" | 38 #include "unicode/stringpiece.h" |
| 39 #include "unicode/curramt.h" | 39 #include "unicode/curramt.h" |
| 40 #include "unicode/udisplaycontext.h" |
| 40 | 41 |
| 41 class NumberFormatTest; | 42 class NumberFormatTest; |
| 42 | 43 |
| 43 U_NAMESPACE_BEGIN | 44 U_NAMESPACE_BEGIN |
| 44 | 45 |
| 46 class SharedNumberFormat; |
| 47 |
| 45 #if !UCONFIG_NO_SERVICE | 48 #if !UCONFIG_NO_SERVICE |
| 46 class NumberFormatFactory; | 49 class NumberFormatFactory; |
| 47 class StringEnumeration; | 50 class StringEnumeration; |
| 48 #endif | 51 #endif |
| 49 | 52 |
| 50 /** | 53 /** |
| 51 * | 54 * |
| 52 * Abstract base class for all number formats. Provides interface for | 55 * Abstract base class for all number formats. Provides interface for |
| 53 * formatting and parsing a number. Also provides methods for | 56 * formatting and parsing a number. Also provides methods for |
| 54 * determining which locales have number formats, and what their names | 57 * determining which locales have number formats, and what their names |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 * @param desiredLocale the given locale. | 701 * @param desiredLocale the given locale. |
| 699 * @param style the given style. | 702 * @param style the given style. |
| 700 * @param errorCode Output param filled with success/failure status. | 703 * @param errorCode Output param filled with success/failure status. |
| 701 * @return A new NumberFormat instance. | 704 * @return A new NumberFormat instance. |
| 702 * @stable ICU 4.8 | 705 * @stable ICU 4.8 |
| 703 */ | 706 */ |
| 704 static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, | 707 static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale, |
| 705 UNumberFormatStyle style, | 708 UNumberFormatStyle style, |
| 706 UErrorCode& errorCode); | 709 UErrorCode& errorCode); |
| 707 | 710 |
| 711 #ifndef U_HIDE_INTERNAL_API |
| 712 |
| 713 /** |
| 714 * ICU use only. |
| 715 * Creates NumberFormat instance without using the cache. |
| 716 * @internal |
| 717 */ |
| 718 static NumberFormat* internalCreateInstance( |
| 719 const Locale& desiredLocale, |
| 720 UNumberFormatStyle style, |
| 721 UErrorCode& errorCode); |
| 722 |
| 723 /** |
| 724 * ICU use only. |
| 725 * Returns handle to the shared, cached NumberFormat instance for given |
| 726 * locale. On success, caller must call removeRef() on returned value |
| 727 * once it is done with the shared instance. |
| 728 * @internal |
| 729 */ |
| 730 static const SharedNumberFormat* U_EXPORT2 createSharedInstance( |
| 731 const Locale& inLocale, UNumberFormatStyle style, UErrorCode& status
); |
| 732 |
| 733 #endif /* U_HIDE_INTERNAL_API */ |
| 734 |
| 708 /** | 735 /** |
| 709 * Returns a currency format for the current default locale. | 736 * Returns a currency format for the current default locale. |
| 710 * @stable ICU 2.0 | 737 * @stable ICU 2.0 |
| 711 */ | 738 */ |
| 712 static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&); | 739 static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&); |
| 713 | 740 |
| 714 /** | 741 /** |
| 715 * Returns a currency format for the specified locale. | 742 * Returns a currency format for the specified locale. |
| 716 * @param inLocale the given locale. | 743 * @param inLocale the given locale. |
| 717 * @stable ICU 2.0 | 744 * @stable ICU 2.0 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 /** | 777 /** |
| 751 * Get the set of Locales for which NumberFormats are installed. | 778 * Get the set of Locales for which NumberFormats are installed. |
| 752 * @param count Output param to receive the size of the locales | 779 * @param count Output param to receive the size of the locales |
| 753 * @stable ICU 2.0 | 780 * @stable ICU 2.0 |
| 754 */ | 781 */ |
| 755 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); | 782 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); |
| 756 | 783 |
| 757 #if !UCONFIG_NO_SERVICE | 784 #if !UCONFIG_NO_SERVICE |
| 758 /** | 785 /** |
| 759 * Register a new NumberFormatFactory. The factory will be adopted. | 786 * Register a new NumberFormatFactory. The factory will be adopted. |
| 787 * Because ICU may choose to cache NumberFormat objects internally, |
| 788 * this must be called at application startup, prior to any calls to |
| 789 * NumberFormat::createInstance to avoid undefined behavior. |
| 760 * @param toAdopt the NumberFormatFactory instance to be adopted | 790 * @param toAdopt the NumberFormatFactory instance to be adopted |
| 761 * @param status the in/out status code, no special meanings are assigned | 791 * @param status the in/out status code, no special meanings are assigned |
| 762 * @return a registry key that can be used to unregister this factory | 792 * @return a registry key that can be used to unregister this factory |
| 763 * @stable ICU 2.6 | 793 * @stable ICU 2.6 |
| 764 */ | 794 */ |
| 765 static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt,
UErrorCode& status); | 795 static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt,
UErrorCode& status); |
| 766 | 796 |
| 767 /** | 797 /** |
| 768 * Unregister a previously-registered NumberFormatFactory using the key retu
rned from the | 798 * Unregister a previously-registered NumberFormatFactory using the key retu
rned from the |
| 769 * register call. Key becomes invalid after a successful call and should no
t be used again. | 799 * register call. Key becomes invalid after a successful call and should no
t be used again. |
| 770 * The NumberFormatFactory corresponding to the key will be deleted. | 800 * The NumberFormatFactory corresponding to the key will be deleted. |
| 801 * Because ICU may choose to cache NumberFormat objects internally, |
| 802 * this should be called during application shutdown, after all calls to |
| 803 * NumberFormat::createInstance to avoid undefined behavior. |
| 771 * @param key the registry key returned by a previous call to registerFactor
y | 804 * @param key the registry key returned by a previous call to registerFactor
y |
| 772 * @param status the in/out status code, no special meanings are assigned | 805 * @param status the in/out status code, no special meanings are assigned |
| 773 * @return TRUE if the factory for the key was successfully unregistered | 806 * @return TRUE if the factory for the key was successfully unregistered |
| 774 * @stable ICU 2.6 | 807 * @stable ICU 2.6 |
| 775 */ | 808 */ |
| 776 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); | 809 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); |
| 777 | 810 |
| 778 /** | 811 /** |
| 779 * Return a StringEnumeration over the locales available at the time of the
call, | 812 * Return a StringEnumeration over the locales available at the time of the
call, |
| 780 * including registered locales. | 813 * including registered locales. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); | 941 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); |
| 909 | 942 |
| 910 /** | 943 /** |
| 911 * Gets the currency used to display currency | 944 * Gets the currency used to display currency |
| 912 * amounts. This may be an empty string for some subclasses. | 945 * amounts. This may be an empty string for some subclasses. |
| 913 * @return a 3-letter null-terminated ISO code indicating | 946 * @return a 3-letter null-terminated ISO code indicating |
| 914 * the currency in use, or a pointer to the empty string. | 947 * the currency in use, or a pointer to the empty string. |
| 915 * @stable ICU 2.6 | 948 * @stable ICU 2.6 |
| 916 */ | 949 */ |
| 917 const UChar* getCurrency() const; | 950 const UChar* getCurrency() const; |
| 951 |
| 952 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since
it is virtual */ |
| 953 /** |
| 954 * Set a particular UDisplayContext value in the formatter, such as |
| 955 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. |
| 956 * @param value The UDisplayContext value to set. |
| 957 * @param status Input/output status. If at entry this indicates a failure |
| 958 * status, the function will do nothing; otherwise this will b
e |
| 959 * updated with any new status from the function. |
| 960 * @draft ICU 53 |
| 961 */ |
| 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 */ |
| 965 /** |
| 966 * Get the formatter's UDisplayContext value for the specified UDisplayConte
xtType, |
| 967 * such as UDISPCTX_TYPE_CAPITALIZATION. |
| 968 * @param type The UDisplayContextType whose value to return |
| 969 * @param status Input/output status. If at entry this indicates a failure |
| 970 * status, the function will do nothing; otherwise this will b
e |
| 971 * updated with any new status from the function. |
| 972 * @return The UDisplayContextValue for the specified type. |
| 973 * @draft ICU 53 |
| 974 */ |
| 975 virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& sta
tus) const; |
| 918 | 976 |
| 919 public: | 977 public: |
| 920 | 978 |
| 921 /** | 979 /** |
| 922 * Return the class ID for this class. This is useful for | 980 * Return the class ID for this class. This is useful for |
| 923 * comparing to a return value from getDynamicClassID(). Note that, | 981 * comparing to a return value from getDynamicClassID(). Note that, |
| 924 * because NumberFormat is an abstract base class, no fully constructed obje
ct | 982 * because NumberFormat is an abstract base class, no fully constructed obje
ct |
| 925 * will have the class ID returned by NumberFormat::getStaticClassID(). | 983 * will have the class ID returned by NumberFormat::getStaticClassID(). |
| 926 * @return The class ID for all objects of this class. | 984 * @return The class ID for all objects of this class. |
| 927 * @stable ICU 2.0 | 985 * @stable ICU 2.0 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 * Creates the specified decimal format style of the desired locale. | 1050 * Creates the specified decimal format style of the desired locale. |
| 993 * @param desiredLocale the given locale. | 1051 * @param desiredLocale the given locale. |
| 994 * @param style the given style. | 1052 * @param style the given style. |
| 995 * @param errorCode Output param filled with success/failure status. | 1053 * @param errorCode Output param filled with success/failure status. |
| 996 * @return A new NumberFormat instance. | 1054 * @return A new NumberFormat instance. |
| 997 */ | 1055 */ |
| 998 static NumberFormat* makeInstance(const Locale& desiredLocale, | 1056 static NumberFormat* makeInstance(const Locale& desiredLocale, |
| 999 UNumberFormatStyle style, | 1057 UNumberFormatStyle style, |
| 1000 UErrorCode& errorCode); | 1058 UErrorCode& errorCode); |
| 1001 | 1059 |
| 1002 UBool fGroupingUsed; | 1060 UBool fGroupingUsed; |
| 1003 int32_t fMaxIntegerDigits; | 1061 int32_t fMaxIntegerDigits; |
| 1004 int32_t fMinIntegerDigits; | 1062 int32_t fMinIntegerDigits; |
| 1005 int32_t fMaxFractionDigits; | 1063 int32_t fMaxFractionDigits; |
| 1006 int32_t fMinFractionDigits; | 1064 int32_t fMinFractionDigits; |
| 1007 | 1065 |
| 1008 protected: | 1066 protected: |
| 1009 static const int32_t gDefaultMaxIntegerDigits; | 1067 static const int32_t gDefaultMaxIntegerDigits; |
| 1010 static const int32_t gDefaultMinIntegerDigits; | 1068 static const int32_t gDefaultMinIntegerDigits; |
| 1011 | 1069 |
| 1012 private: | 1070 private: |
| 1013 UBool fParseIntegerOnly; | 1071 UBool fParseIntegerOnly; |
| 1014 UBool fLenient; // TRUE => lenient parse is enabled | 1072 UBool fLenient; // TRUE => lenient parse is enabled |
| 1015 | 1073 |
| 1016 // ISO currency code | 1074 // ISO currency code |
| 1017 UChar fCurrency[4]; | 1075 UChar fCurrency[4]; |
| 1018 | 1076 |
| 1077 UDisplayContext fCapitalizationContext; |
| 1078 |
| 1019 friend class ICUNumberFormatFactory; // access to makeInstance | 1079 friend class ICUNumberFormatFactory; // access to makeInstance |
| 1020 friend class ICUNumberFormatService; | 1080 friend class ICUNumberFormatService; |
| 1021 friend class ::NumberFormatTest; // access to isStyleSupported() | 1081 friend class ::NumberFormatTest; // access to isStyleSupported() |
| 1022 }; | 1082 }; |
| 1023 | 1083 |
| 1024 #if !UCONFIG_NO_SERVICE | 1084 #if !UCONFIG_NO_SERVICE |
| 1025 /** | 1085 /** |
| 1026 * A NumberFormatFactory is used to register new number formats. The factory | 1086 * A NumberFormatFactory is used to register new number formats. The factory |
| 1027 * should be able to create any of the predefined formats for each locale it | 1087 * should be able to create any of the predefined formats for each locale it |
| 1028 * supports. When registered, the locales it supports extend or override the | 1088 * supports. When registered, the locales it supports extend or override the |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 { | 1178 { |
| 1119 return fLenient; | 1179 return fLenient; |
| 1120 } | 1180 } |
| 1121 | 1181 |
| 1122 U_NAMESPACE_END | 1182 U_NAMESPACE_END |
| 1123 | 1183 |
| 1124 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1184 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| 1125 | 1185 |
| 1126 #endif // _NUMFMT | 1186 #endif // _NUMFMT |
| 1127 //eof | 1187 //eof |
| OLD | NEW |