OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************** | 2 ******************************************************************************** |
3 * Copyright (C) 1997-2014, International Business Machines | 3 * Copyright (C) 1997-2015, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ******************************************************************************** | 5 ******************************************************************************** |
6 * | 6 * |
7 * File DECIMFMT.H | 7 * File DECIMFMT.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/20/97 clhuang Updated per C++ implementation. | 13 * 03/20/97 clhuang Updated per C++ implementation. |
(...skipping 20 matching lines...) Expand all Loading... |
34 #if !UCONFIG_NO_FORMATTING | 34 #if !UCONFIG_NO_FORMATTING |
35 | 35 |
36 #include "unicode/dcfmtsym.h" | 36 #include "unicode/dcfmtsym.h" |
37 #include "unicode/numfmt.h" | 37 #include "unicode/numfmt.h" |
38 #include "unicode/locid.h" | 38 #include "unicode/locid.h" |
39 #include "unicode/fpositer.h" | 39 #include "unicode/fpositer.h" |
40 #include "unicode/stringpiece.h" | 40 #include "unicode/stringpiece.h" |
41 #include "unicode/curramt.h" | 41 #include "unicode/curramt.h" |
42 #include "unicode/enumset.h" | 42 #include "unicode/enumset.h" |
43 | 43 |
| 44 #ifndef U_HIDE_INTERNAL_API |
44 /** | 45 /** |
45 * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE | 46 * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE |
46 * @internal | 47 * @internal |
47 */ | 48 */ |
48 #if UCONFIG_FORMAT_FASTPATHS_49 | 49 #if UCONFIG_FORMAT_FASTPATHS_49 |
49 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16 | 50 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16 |
50 #endif | 51 #endif |
| 52 #endif /* U_HIDE_INTERNAL_API */ |
51 | 53 |
52 U_NAMESPACE_BEGIN | 54 U_NAMESPACE_BEGIN |
53 | 55 |
54 class DigitList; | 56 class DigitList; |
55 class ChoiceFormat; | 57 class ChoiceFormat; |
56 class CurrencyPluralInfo; | 58 class CurrencyPluralInfo; |
57 class Hashtable; | 59 class Hashtable; |
58 class UnicodeSet; | 60 class UnicodeSet; |
59 class FieldPositionHandler; | 61 class FieldPositionHandler; |
60 class DecimalFormatStaticSets; | 62 class DecimalFormatStaticSets; |
61 class FixedDecimal; | 63 class FixedDecimal; |
| 64 class DecimalFormatImpl; |
| 65 class PluralRules; |
| 66 class VisibleDigitsWithExponent; |
62 | 67 |
63 // explicit template instantiation. see digitlst.h | 68 // explicit template instantiation. see digitlst.h |
64 #if defined (_MSC_VER) | 69 #if defined (_MSC_VER) |
65 template class U_I18N_API EnumSet<UNumberFormatAttribute, | 70 template class U_I18N_API EnumSet<UNumberFormatAttribute, |
66 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, | 71 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, |
67 UNUM_LIMIT_BOOLEAN_ATTRIBUTE>; | 72 UNUM_LIMIT_BOOLEAN_ATTRIBUTE>; |
68 #endif | 73 #endif |
69 | 74 |
70 /** | 75 /** |
71 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal | 76 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 * @stable ICU 51 | 806 * @stable ICU 51 |
802 */ | 807 */ |
803 virtual int32_t getAttribute( UNumberFormatAttribute attr, | 808 virtual int32_t getAttribute( UNumberFormatAttribute attr, |
804 UErrorCode &status) const; | 809 UErrorCode &status) const; |
805 | 810 |
806 | 811 |
807 /** | 812 /** |
808 * Set whether or not grouping will be used in this format. | 813 * Set whether or not grouping will be used in this format. |
809 * @param newValue True, grouping will be used in this format. | 814 * @param newValue True, grouping will be used in this format. |
810 * @see getGroupingUsed | 815 * @see getGroupingUsed |
811 * @draft ICU 53 | 816 * @stable ICU 53 |
812 */ | 817 */ |
813 virtual void setGroupingUsed(UBool newValue); | 818 virtual void setGroupingUsed(UBool newValue); |
814 | 819 |
815 /** | 820 /** |
816 * Sets whether or not numbers should be parsed as integers only. | 821 * Sets whether or not numbers should be parsed as integers only. |
817 * @param value set True, this format will parse numbers as integers | 822 * @param value set True, this format will parse numbers as integers |
818 * only. | 823 * only. |
819 * @see isParseIntegerOnly | 824 * @see isParseIntegerOnly |
820 * @draft ICU 53 | 825 * @stable ICU 53 |
821 */ | 826 */ |
822 virtual void setParseIntegerOnly(UBool value); | 827 virtual void setParseIntegerOnly(UBool value); |
823 | 828 |
824 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since
it is virtual */ | |
825 /** | 829 /** |
826 * Set a particular UDisplayContext value in the formatter, such as | 830 * Set a particular UDisplayContext value in the formatter, such as |
827 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. | 831 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. |
828 * @param value The UDisplayContext value to set. | 832 * @param value The UDisplayContext value to set. |
829 * @param status Input/output status. If at entry this indicates a failure | 833 * @param status Input/output status. If at entry this indicates a failure |
830 * status, the function will do nothing; otherwise this will b
e | 834 * status, the function will do nothing; otherwise this will b
e |
831 * updated with any new status from the function. | 835 * updated with any new status from the function. |
832 * @draft ICU 53 | 836 * @stable ICU 53 |
833 */ | 837 */ |
834 virtual void setContext(UDisplayContext value, UErrorCode& status); | 838 virtual void setContext(UDisplayContext value, UErrorCode& status); |
835 | 839 |
836 /** | 840 /** |
837 * Create a DecimalFormat from the given pattern and symbols. | 841 * Create a DecimalFormat from the given pattern and symbols. |
838 * Use this constructor when you need to completely customize the | 842 * Use this constructor when you need to completely customize the |
839 * behavior of the format. | 843 * behavior of the format. |
840 * <P> | 844 * <P> |
841 * To obtain standard formats for a given | 845 * To obtain standard formats for a given |
842 * locale, use the factory methods on NumberFormat such as | 846 * locale, use the factory methods on NumberFormat such as |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 * @return Reference to 'appendTo' parameter. | 1111 * @return Reference to 'appendTo' parameter. |
1108 * @internal | 1112 * @internal |
1109 */ | 1113 */ |
1110 virtual UnicodeString& format(const DigitList &number, | 1114 virtual UnicodeString& format(const DigitList &number, |
1111 UnicodeString& appendTo, | 1115 UnicodeString& appendTo, |
1112 FieldPositionIterator* posIter, | 1116 FieldPositionIterator* posIter, |
1113 UErrorCode& status) const; | 1117 UErrorCode& status) const; |
1114 | 1118 |
1115 /** | 1119 /** |
1116 * Format a decimal number. | 1120 * Format a decimal number. |
| 1121 * @param number The number |
| 1122 * @param appendTo Output parameter to receive result. |
| 1123 * Result is appended to existing contents. |
| 1124 * @param pos On input: an alignment field, if desired. |
| 1125 * On output: the offsets of the alignment field. |
| 1126 * @param status Output param filled with success/failure status. |
| 1127 * @return Reference to 'appendTo' parameter. |
| 1128 * @internal |
| 1129 */ |
| 1130 virtual UnicodeString& format( |
| 1131 const VisibleDigitsWithExponent &number, |
| 1132 UnicodeString& appendTo, |
| 1133 FieldPosition& pos, |
| 1134 UErrorCode& status) const; |
| 1135 |
| 1136 /** |
| 1137 * Format a decimal number. |
| 1138 * @param number The number |
| 1139 * @param appendTo Output parameter to receive result. |
| 1140 * Result is appended to existing contents. |
| 1141 * @param posIter On return, can be used to iterate over positions |
| 1142 * of fields generated by this format call. |
| 1143 * @param status Output param filled with success/failure status. |
| 1144 * @return Reference to 'appendTo' parameter. |
| 1145 * @internal |
| 1146 */ |
| 1147 virtual UnicodeString& format( |
| 1148 const VisibleDigitsWithExponent &number, |
| 1149 UnicodeString& appendTo, |
| 1150 FieldPositionIterator* posIter, |
| 1151 UErrorCode& status) const; |
| 1152 |
| 1153 /** |
| 1154 * Format a decimal number. |
1117 * The number is a DigitList wrapper onto a floating point decimal number. | 1155 * The number is a DigitList wrapper onto a floating point decimal number. |
1118 * The default implementation in NumberFormat converts the decimal number | 1156 * The default implementation in NumberFormat converts the decimal number |
1119 * to a double and formats that. | 1157 * to a double and formats that. |
1120 * | 1158 * |
1121 * @param number The number, a DigitList format Decimal Floating Point. | 1159 * @param number The number, a DigitList format Decimal Floating Point. |
1122 * @param appendTo Output parameter to receive result. | 1160 * @param appendTo Output parameter to receive result. |
1123 * Result is appended to existing contents. | 1161 * Result is appended to existing contents. |
1124 * @param pos On input: an alignment field, if desired. | 1162 * @param pos On input: an alignment field, if desired. |
1125 * On output: the offsets of the alignment field. | 1163 * On output: the offsets of the alignment field. |
1126 * @param status Output param filled with success/failure status. | 1164 * @param status Output param filled with success/failure status. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 * size is used for all intervals, not just the least significant. | 1642 * size is used for all intervals, not just the least significant. |
1605 * | 1643 * |
1606 * @param newValue the new value of the secondary grouping size. | 1644 * @param newValue the new value of the secondary grouping size. |
1607 * @see getSecondaryGroupingSize | 1645 * @see getSecondaryGroupingSize |
1608 * @see NumberFormat#setGroupingUsed | 1646 * @see NumberFormat#setGroupingUsed |
1609 * @see DecimalFormatSymbols::setGroupingSeparator | 1647 * @see DecimalFormatSymbols::setGroupingSeparator |
1610 * @stable ICU 2.4 | 1648 * @stable ICU 2.4 |
1611 */ | 1649 */ |
1612 virtual void setSecondaryGroupingSize(int32_t newValue); | 1650 virtual void setSecondaryGroupingSize(int32_t newValue); |
1613 | 1651 |
| 1652 #ifndef U_HIDE_INTERNAL_API |
| 1653 |
| 1654 /** |
| 1655 * Returns the minimum number of grouping digits. |
| 1656 * Grouping separators are output if there are at least this many |
| 1657 * digits to the left of the first (rightmost) grouping separator, |
| 1658 * that is, there are at least (minimum grouping + grouping size) integer di
gits. |
| 1659 * (Subject to isGroupingUsed().) |
| 1660 * |
| 1661 * For example, if this value is 2, and the grouping size is 3, then |
| 1662 * 9999 -> "9999" and 10000 -> "10,000" |
| 1663 * |
| 1664 * This is a technology preview. This API may change behavior or may be remo
ved. |
| 1665 * |
| 1666 * The default value for this attribute is 0. |
| 1667 * A value of 1, 0, or lower, means that the use of grouping separators |
| 1668 * only depends on the grouping size (and on isGroupingUsed()). |
| 1669 * Currently, the corresponding CLDR data is not used; this is likely to cha
nge. |
| 1670 * |
| 1671 * @see setMinimumGroupingDigits |
| 1672 * @see getGroupingSize |
| 1673 * @internal technology preview |
| 1674 */ |
| 1675 int32_t getMinimumGroupingDigits() const; |
| 1676 |
| 1677 /** |
| 1678 * Sets the minimum grouping digits. Setting to a value less than or |
| 1679 * equal to 1 turns off minimum grouping digits. |
| 1680 * |
| 1681 * @param newValue the new value of minimum grouping digits. |
| 1682 * @see getMinimumGroupingDigits |
| 1683 * @internal technology preview |
| 1684 */ |
| 1685 virtual void setMinimumGroupingDigits(int32_t newValue); |
| 1686 |
| 1687 #endif /* U_HIDE_INTERNAL_API */ |
| 1688 |
1614 /** | 1689 /** |
1615 * Allows you to get the behavior of the decimal separator with integers. | 1690 * Allows you to get the behavior of the decimal separator with integers. |
1616 * (The decimal separator will always appear with decimals.) | 1691 * (The decimal separator will always appear with decimals.) |
1617 * | 1692 * |
1618 * @return TRUE if the decimal separator always appear with decimals. | 1693 * @return TRUE if the decimal separator always appear with decimals. |
1619 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 | 1694 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 |
1620 * @stable ICU 2.0 | 1695 * @stable ICU 2.0 |
1621 */ | 1696 */ |
1622 UBool isDecimalSeparatorAlwaysShown(void) const; | 1697 UBool isDecimalSeparatorAlwaysShown(void) const; |
1623 | 1698 |
1624 /** | 1699 /** |
1625 * Allows you to set the behavior of the decimal separator with integers. | 1700 * Allows you to set the behavior of the decimal separator with integers. |
1626 * (The decimal separator will always appear with decimals.) | 1701 * (The decimal separator will always appear with decimals.) |
1627 * | 1702 * |
1628 * @param newValue set TRUE if the decimal separator will always appear w
ith decimals. | 1703 * @param newValue set TRUE if the decimal separator will always appear w
ith decimals. |
1629 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 | 1704 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 |
1630 * @stable ICU 2.0 | 1705 * @stable ICU 2.0 |
1631 */ | 1706 */ |
1632 virtual void setDecimalSeparatorAlwaysShown(UBool newValue); | 1707 virtual void setDecimalSeparatorAlwaysShown(UBool newValue); |
1633 | 1708 |
1634 #ifndef U_HIDE_DRAFT_API | |
1635 /** | 1709 /** |
1636 * Allows you to get the parse behavior of the pattern decimal mark. | 1710 * Allows you to get the parse behavior of the pattern decimal mark. |
1637 * | 1711 * |
1638 * @return TRUE if input must contain a match to decimal mark in pattern | 1712 * @return TRUE if input must contain a match to decimal mark in pattern |
1639 * @draft ICU 54 | 1713 * @stable ICU 54 |
1640 */ | 1714 */ |
1641 UBool isDecimalPatternMatchRequired(void) const; | 1715 UBool isDecimalPatternMatchRequired(void) const; |
1642 #endif /* U_HIDE_DRAFT_API */ | |
1643 | 1716 |
1644 /** | 1717 /** |
1645 * Allows you to set the behavior of the pattern decimal mark. | 1718 * Allows you to set the behavior of the pattern decimal mark. |
1646 * | 1719 * |
1647 * if TRUE, the input must have a decimal mark if one was specified in the p
attern. When | 1720 * if TRUE, the input must have a decimal mark if one was specified in the p
attern. When |
1648 * FALSE the decimal mark may be omitted from the input. | 1721 * FALSE the decimal mark may be omitted from the input. |
1649 * | 1722 * |
1650 * @param newValue set TRUE if input must contain a match to decimal mark
in pattern | 1723 * @param newValue set TRUE if input must contain a match to decimal mark
in pattern |
1651 * @draft ICU 54 | 1724 * @stable ICU 54 |
1652 */ | 1725 */ |
1653 virtual void setDecimalPatternMatchRequired(UBool newValue); | 1726 virtual void setDecimalPatternMatchRequired(UBool newValue); |
1654 | 1727 |
1655 | 1728 |
1656 /** | 1729 /** |
1657 * Synthesizes a pattern string that represents the current state | 1730 * Synthesizes a pattern string that represents the current state |
1658 * of this Format object. | 1731 * of this Format object. |
1659 * | 1732 * |
1660 * @param result Output param which will receive the pattern. | 1733 * @param result Output param which will receive the pattern. |
1661 * Previous contents are deleted. | 1734 * Previous contents are deleted. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 */ | 1960 */ |
1888 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); | 1961 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); |
1889 | 1962 |
1890 /** | 1963 /** |
1891 * Sets the currency used to display currency amounts. See | 1964 * Sets the currency used to display currency amounts. See |
1892 * setCurrency(const UChar*, UErrorCode&). | 1965 * setCurrency(const UChar*, UErrorCode&). |
1893 * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&). | 1966 * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&). |
1894 */ | 1967 */ |
1895 virtual void setCurrency(const UChar* theCurrency); | 1968 virtual void setCurrency(const UChar* theCurrency); |
1896 | 1969 |
1897 #ifndef U_HIDE_DRAFT_API | |
1898 /** | 1970 /** |
1899 * Sets the <tt>Currency Context</tt> object used to display currency. | 1971 * Sets the <tt>Currency Context</tt> object used to display currency. |
1900 * This takes effect immediately, if this format is a | 1972 * This takes effect immediately, if this format is a |
1901 * currency format. | 1973 * currency format. |
1902 * @param currencyContext new currency context object to use. | 1974 * @param currencyContext new currency context object to use. |
1903 * @draft ICU 54 | 1975 * @stable ICU 54 |
1904 */ | 1976 */ |
1905 void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec); | 1977 void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec); |
1906 | 1978 |
1907 /** | 1979 /** |
1908 * Returns the <tt>Currency Context</tt> object used to display currency | 1980 * Returns the <tt>Currency Context</tt> object used to display currency |
1909 * @draft ICU 54 | 1981 * @stable ICU 54 |
1910 */ | 1982 */ |
1911 UCurrencyUsage getCurrencyUsage() const; | 1983 UCurrencyUsage getCurrencyUsage() const; |
1912 #endif /* U_HIDE_DRAFT_API */ | |
1913 | 1984 |
1914 | 1985 |
1915 #ifndef U_HIDE_DEPRECATED_API | 1986 #ifndef U_HIDE_DEPRECATED_API |
1916 /** | 1987 /** |
1917 * The resource tags we use to retrieve decimal format data from | 1988 * The resource tags we use to retrieve decimal format data from |
1918 * locale resource bundles. | 1989 * locale resource bundles. |
1919 * @deprecated ICU 3.4. This string has no public purpose. Please don't use
it. | 1990 * @deprecated ICU 3.4. This string has no public purpose. Please don't use
it. |
1920 */ | 1991 */ |
1921 static const char fgNumberPatterns[]; | 1992 static const char fgNumberPatterns[]; |
1922 #endif /* U_HIDE_DEPRECATED_API */ | 1993 #endif /* U_HIDE_DEPRECATED_API */ |
(...skipping 15 matching lines...) Expand all Loading... |
1938 */ | 2009 */ |
1939 FixedDecimal getFixedDecimal(const Formattable &number, UErrorCode &status)
const; | 2010 FixedDecimal getFixedDecimal(const Formattable &number, UErrorCode &status)
const; |
1940 | 2011 |
1941 /** | 2012 /** |
1942 * Get a FixedDecimal corresponding to a DigitList as it would be | 2013 * Get a FixedDecimal corresponding to a DigitList as it would be |
1943 * formatted by this DecimalFormat. Note: the DigitList may be modified. | 2014 * formatted by this DecimalFormat. Note: the DigitList may be modified. |
1944 * Internal, not intended for public use. | 2015 * Internal, not intended for public use. |
1945 * @internal | 2016 * @internal |
1946 */ | 2017 */ |
1947 FixedDecimal getFixedDecimal(DigitList &number, UErrorCode &status) const; | 2018 FixedDecimal getFixedDecimal(DigitList &number, UErrorCode &status) const; |
| 2019 |
| 2020 /** |
| 2021 * Get a VisibleDigitsWithExponent corresponding to a double |
| 2022 * as it would be formatted by this DecimalFormat. |
| 2023 * Internal, not intended for public use. |
| 2024 * @internal |
| 2025 */ |
| 2026 VisibleDigitsWithExponent &initVisibleDigitsWithExponent( |
| 2027 double number, |
| 2028 VisibleDigitsWithExponent &digits, |
| 2029 UErrorCode &status) const; |
| 2030 |
| 2031 /** |
| 2032 * Get a VisibleDigitsWithExponent corresponding to a formattable |
| 2033 * as it would be formatted by this DecimalFormat. |
| 2034 * Internal, not intended for public use. |
| 2035 * @internal |
| 2036 */ |
| 2037 VisibleDigitsWithExponent &initVisibleDigitsWithExponent( |
| 2038 const Formattable &number, |
| 2039 VisibleDigitsWithExponent &digits, |
| 2040 UErrorCode &status) const; |
| 2041 |
| 2042 /** |
| 2043 * Get a VisibleDigitsWithExponent corresponding to a DigitList |
| 2044 * as it would be formatted by this DecimalFormat. |
| 2045 * Note: the DigitList may be modified. |
| 2046 * Internal, not intended for public use. |
| 2047 * @internal |
| 2048 */ |
| 2049 VisibleDigitsWithExponent &initVisibleDigitsWithExponent( |
| 2050 DigitList &number, |
| 2051 VisibleDigitsWithExponent &digits, |
| 2052 UErrorCode &status) const; |
| 2053 |
1948 #endif /* U_HIDE_INTERNAL_API */ | 2054 #endif /* U_HIDE_INTERNAL_API */ |
1949 | 2055 |
1950 public: | 2056 public: |
1951 | 2057 |
1952 /** | 2058 /** |
1953 * Return the class ID for this class. This is useful only for | 2059 * Return the class ID for this class. This is useful only for |
1954 * comparing to a return value from getDynamicClassID(). For example: | 2060 * comparing to a return value from getDynamicClassID(). For example: |
1955 * <pre> | 2061 * <pre> |
1956 * . Base* polymorphic_pointer = createPolymorphicObject(); | 2062 * . Base* polymorphic_pointer = createPolymorphicObject(); |
1957 * . if (polymorphic_pointer->getDynamicClassID() == | 2063 * . if (polymorphic_pointer->getDynamicClassID() == |
(...skipping 14 matching lines...) Expand all Loading... |
1972 * given class have the same class ID. Objects of | 2078 * given class have the same class ID. Objects of |
1973 * other classes have different class IDs. | 2079 * other classes have different class IDs. |
1974 * @stable ICU 2.0 | 2080 * @stable ICU 2.0 |
1975 */ | 2081 */ |
1976 virtual UClassID getDynamicClassID(void) const; | 2082 virtual UClassID getDynamicClassID(void) const; |
1977 | 2083 |
1978 private: | 2084 private: |
1979 | 2085 |
1980 DecimalFormat(); // default constructor not implemented | 2086 DecimalFormat(); // default constructor not implemented |
1981 | 2087 |
1982 int32_t precision() const; | |
1983 | |
1984 /** | 2088 /** |
1985 * Initialize all fields of a new DecimalFormatter to a safe default value
. | 2089 * Initialize all fields of a new DecimalFormatter to a safe default value
. |
1986 * Common code for use by constructors. | 2090 * Common code for use by constructors. |
1987 */ | 2091 */ |
1988 void init(); | 2092 void init(); |
1989 | 2093 |
1990 /** | 2094 /** |
1991 * Do real work of constructing a new DecimalFormat. | 2095 * Do real work of constructing a new DecimalFormat. |
1992 */ | 2096 */ |
1993 void construct(UErrorCode& status, | 2097 void construct(UErrorCode& status, |
1994 UParseError& parseErr, | 2098 UParseError& parseErr, |
1995 const UnicodeString* pattern = 0, | 2099 const UnicodeString* pattern = 0, |
1996 DecimalFormatSymbols* symbolsToAdopt = 0 | 2100 DecimalFormatSymbols* symbolsToAdopt = 0 |
1997 ); | 2101 ); |
1998 | 2102 |
1999 /** | |
2000 * Does the real work of generating a pattern. | |
2001 * | |
2002 * @param result Output param which will receive the pattern. | |
2003 * Previous contents are deleted. | |
2004 * @param localized TRUE return localized pattern. | |
2005 * @return A reference to 'result'. | |
2006 */ | |
2007 UnicodeString& toPattern(UnicodeString& result, UBool localized) const; | |
2008 | |
2009 /** | |
2010 * Does the real work of applying a pattern. | |
2011 * @param pattern The pattern to be applied. | |
2012 * @param localized If true, the pattern is localized; else false. | |
2013 * @param parseError Struct to recieve information on position | |
2014 * of error if an error is encountered | |
2015 * @param status Output param set to success/failure code on | |
2016 * exit. If the pattern is invalid, this will be | |
2017 * set to a failure result. | |
2018 */ | |
2019 void applyPattern(const UnicodeString& pattern, | |
2020 UBool localized, | |
2021 UParseError& parseError, | |
2022 UErrorCode& status); | |
2023 | |
2024 /* | |
2025 * similar to applyPattern, but without re-gen affix for currency | |
2026 */ | |
2027 void applyPatternInternally(const UnicodeString& pluralCount, | |
2028 const UnicodeString& pattern, | |
2029 UBool localized, | |
2030 UParseError& parseError, | |
2031 UErrorCode& status); | |
2032 | |
2033 /* | |
2034 * only apply pattern without expand affixes | |
2035 */ | |
2036 void applyPatternWithoutExpandAffix(const UnicodeString& pattern, | |
2037 UBool localized, | |
2038 UParseError& parseError, | |
2039 UErrorCode& status); | |
2040 | |
2041 | |
2042 /* | |
2043 * expand affixes (after apply patter) and re-compute fFormatWidth | |
2044 */ | |
2045 void expandAffixAdjustWidth(const UnicodeString* pluralCount); | |
2046 | |
2047 | |
2048 /** | |
2049 * Do the work of formatting a number, either a double or a long. | |
2050 * | |
2051 * @param appendTo Output parameter to receive result. | |
2052 * Result is appended to existing contents. | |
2053 * @param handler Records information about field positions. | |
2054 * @param digits the digits to be formatted. | |
2055 * @param isInteger if TRUE format the digits as Integer. | |
2056 * @return Reference to 'appendTo' parameter. | |
2057 */ | |
2058 UnicodeString& subformat(UnicodeString& appendTo, | |
2059 FieldPositionHandler& handler, | |
2060 DigitList& digits, | |
2061 UBool isInteger, | |
2062 UErrorCode &status) const; | |
2063 | |
2064 | |
2065 void parse(const UnicodeString& text, | 2103 void parse(const UnicodeString& text, |
2066 Formattable& result, | 2104 Formattable& result, |
2067 ParsePosition& pos, | 2105 ParsePosition& pos, |
2068 UChar* currency) const; | 2106 UChar* currency) const; |
2069 | 2107 |
2070 enum { | 2108 enum { |
2071 fgStatusInfinite, | 2109 fgStatusInfinite, |
2072 fgStatusLength // Leave last in list. | 2110 fgStatusLength // Leave last in list. |
2073 } StatusFlags; | 2111 } StatusFlags; |
2074 | 2112 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 static UBool matchDecimal(UChar32 symbolChar, | 2176 static UBool matchDecimal(UChar32 symbolChar, |
2139 UBool sawDecimal, UChar32 sawDecimalChar, | 2177 UBool sawDecimal, UChar32 sawDecimalChar, |
2140 const UnicodeSet *sset, UChar32 schar); | 2178 const UnicodeSet *sset, UChar32 schar); |
2141 | 2179 |
2142 static UBool matchGrouping(UChar32 groupingChar, | 2180 static UBool matchGrouping(UChar32 groupingChar, |
2143 UBool sawGrouping, UChar32 sawGroupingChar, | 2181 UBool sawGrouping, UChar32 sawGroupingChar, |
2144 const UnicodeSet *sset, | 2182 const UnicodeSet *sset, |
2145 UChar32 decimalChar, const UnicodeSet *decimalSet, | 2183 UChar32 decimalChar, const UnicodeSet *decimalSet, |
2146 UChar32 schar); | 2184 UChar32 schar); |
2147 | 2185 |
2148 /** | |
2149 * Get a decimal format symbol. | |
2150 * Returns a const reference to the symbol string. | |
2151 * @internal | |
2152 */ | |
2153 inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberForm
atSymbol symbol) const; | |
2154 | |
2155 int32_t appendAffix(UnicodeString& buf, | |
2156 double number, | |
2157 FieldPositionHandler& handler, | |
2158 UBool isNegative, | |
2159 UBool isPrefix) const; | |
2160 | |
2161 /** | |
2162 * Append an affix to the given UnicodeString, using quotes if | |
2163 * there are special characters. Single quotes themselves must be | |
2164 * escaped in either case. | |
2165 */ | |
2166 void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix, | |
2167 UBool localized) const; | |
2168 | |
2169 void appendAffixPattern(UnicodeString& appendTo, | |
2170 const UnicodeString* affixPattern, | |
2171 const UnicodeString& expAffix, UBool localized) cons
t; | |
2172 | |
2173 void expandAffix(const UnicodeString& pattern, | |
2174 UnicodeString& affix, | |
2175 double number, | |
2176 FieldPositionHandler& handler, | |
2177 UBool doFormat, | |
2178 const UnicodeString* pluralCount) const; | |
2179 | |
2180 void expandAffixes(const UnicodeString* pluralCount); | |
2181 | |
2182 void addPadding(UnicodeString& appendTo, | |
2183 FieldPositionHandler& handler, | |
2184 int32_t prefixLen, int32_t suffixLen) const; | |
2185 | |
2186 UBool isGroupingPosition(int32_t pos) const; | |
2187 | |
2188 void setCurrencyForSymbols(); | |
2189 | |
2190 // similar to setCurrency without re-compute the affixes for currency. | |
2191 // If currency changes, the affix pattern for currency is not changed, | |
2192 // but the affix will be changed. So, affixes need to be | |
2193 // re-computed in setCurrency(), but not in setCurrencyInternally(). | |
2194 virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec)
; | |
2195 | |
2196 // set up currency affix patterns for mix parsing. | 2186 // set up currency affix patterns for mix parsing. |
2197 // The patterns saved here are the affix patterns of default currency | 2187 // The patterns saved here are the affix patterns of default currency |
2198 // pattern and the unique affix patterns of the plural currency patterns. | 2188 // pattern and the unique affix patterns of the plural currency patterns. |
2199 // Those patterns are used by parseForCurrency(). | 2189 // Those patterns are used by parseForCurrency(). |
2200 void setupCurrencyAffixPatterns(UErrorCode& status); | 2190 void setupCurrencyAffixPatterns(UErrorCode& status); |
2201 | 2191 |
2202 // set up the currency affixes used in currency plural formatting. | |
2203 // It sets up both fAffixesForCurrency for currency pattern if the current | |
2204 // pattern contains 3 currency signs, | |
2205 // and it sets up fPluralAffixesForCurrency for currency plural patterns. | |
2206 void setupCurrencyAffixes(const UnicodeString& pattern, | |
2207 UBool setupForCurrentPattern, | |
2208 UBool setupForPluralPattern, | |
2209 UErrorCode& status); | |
2210 | |
2211 // get the currency rounding with respect to currency usage | 2192 // get the currency rounding with respect to currency usage |
2212 double getCurrencyRounding(const UChar* currency, | 2193 double getCurrencyRounding(const UChar* currency, |
2213 UErrorCode* ec) const; | 2194 UErrorCode* ec) const; |
2214 | 2195 |
2215 // get the currency fraction with respect to currency usage | 2196 // get the currency fraction with respect to currency usage |
2216 int getCurrencyFractionDigits(const UChar* currency, | 2197 int getCurrencyFractionDigits(const UChar* currency, |
2217 UErrorCode* ec) const; | 2198 UErrorCode* ec) const; |
2218 | 2199 |
2219 // hashtable operations | 2200 // hashtable operations |
2220 Hashtable* initHashForAffixPattern(UErrorCode& status); | 2201 Hashtable* initHashForAffixPattern(UErrorCode& status); |
2221 Hashtable* initHashForAffix(UErrorCode& status); | |
2222 | 2202 |
2223 void deleteHashForAffixPattern(); | 2203 void deleteHashForAffixPattern(); |
2224 void deleteHashForAffix(Hashtable*& table); | |
2225 | 2204 |
2226 void copyHashForAffixPattern(const Hashtable* source, | 2205 void copyHashForAffixPattern(const Hashtable* source, |
2227 Hashtable* target, UErrorCode& status); | 2206 Hashtable* target, UErrorCode& status); |
2228 void copyHashForAffix(const Hashtable* source, | |
2229 Hashtable* target, UErrorCode& status); | |
2230 | 2207 |
2231 UnicodeString& _format(int64_t number, | 2208 DecimalFormatImpl *fImpl; |
2232 UnicodeString& appendTo, | |
2233 FieldPositionHandler& handler, | |
2234 UErrorCode &status) const; | |
2235 UnicodeString& _format(double number, | |
2236 UnicodeString& appendTo, | |
2237 FieldPositionHandler& handler, | |
2238 UErrorCode &status) const; | |
2239 UnicodeString& _format(const DigitList &number, | |
2240 UnicodeString& appendTo, | |
2241 FieldPositionHandler& handler, | |
2242 UErrorCode &status) const; | |
2243 | 2209 |
2244 /** | 2210 /** |
2245 * Constants. | 2211 * Constants. |
2246 */ | 2212 */ |
2247 | 2213 |
2248 UnicodeString fPositivePrefix; | |
2249 UnicodeString fPositiveSuffix; | |
2250 UnicodeString fNegativePrefix; | |
2251 UnicodeString fNegativeSuffix; | |
2252 UnicodeString* fPosPrefixPattern; | |
2253 UnicodeString* fPosSuffixPattern; | |
2254 UnicodeString* fNegPrefixPattern; | |
2255 UnicodeString* fNegSuffixPattern; | |
2256 | |
2257 /** | |
2258 * Formatter for ChoiceFormat-based currency names. If this field | |
2259 * is not null, then delegate to it to format currency symbols. | |
2260 * @since ICU 2.6 | |
2261 */ | |
2262 ChoiceFormat* fCurrencyChoice; | |
2263 | |
2264 DigitList * fMultiplier; // NULL for multiplier of one | |
2265 int32_t fScale; | |
2266 int32_t fGroupingSize; | |
2267 int32_t fGroupingSize2; | |
2268 UBool fDecimalSeparatorAlwaysShown; | |
2269 DecimalFormatSymbols* fSymbols; | |
2270 | |
2271 UBool fUseSignificantDigits; | |
2272 int32_t fMinSignificantDigits; | |
2273 int32_t fMaxSignificantDigits; | |
2274 | |
2275 UBool fUseExponentialNotation; | |
2276 int8_t fMinExponentDigits; | |
2277 UBool fExponentSignAlwaysShown; | |
2278 | 2214 |
2279 EnumSet<UNumberFormatAttribute, | 2215 EnumSet<UNumberFormatAttribute, |
2280 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, | 2216 UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, |
2281 UNUM_LIMIT_BOOLEAN_ATTRIBUTE> | 2217 UNUM_LIMIT_BOOLEAN_ATTRIBUTE> |
2282 fBoolFlags; | 2218 fBoolFlags; |
2283 | 2219 |
2284 DigitList* fRoundingIncrement; // NULL if no rounding incremen
t specified. | |
2285 ERoundingMode fRoundingMode; | |
2286 | 2220 |
2287 UChar32 fPad; | |
2288 int32_t fFormatWidth; | |
2289 EPadPosition fPadPosition; | |
2290 | |
2291 /* | |
2292 * Following are used for currency format | |
2293 */ | |
2294 // pattern used in this formatter | |
2295 UnicodeString fFormatPattern; | |
2296 // style is only valid when decimal formatter is constructed by | 2221 // style is only valid when decimal formatter is constructed by |
2297 // DecimalFormat(pattern, decimalFormatSymbol, style) | 2222 // DecimalFormat(pattern, decimalFormatSymbol, style) |
2298 int fStyle; | 2223 int fStyle; |
2299 /* | |
2300 * Represents whether this is a currency format, and which | |
2301 * currency format style. | |
2302 * 0: not currency format type; | |
2303 * 1: currency style -- symbol name, such as "$" for US dollar. | |
2304 * 2: currency style -- ISO name, such as USD for US dollar. | |
2305 * 3: currency style -- plural long name, such as "US Dollar" for | |
2306 * "1.00 US Dollar", or "US Dollars" for | |
2307 * "3.00 US Dollars". | |
2308 */ | |
2309 int fCurrencySignCount; | |
2310 | 2224 |
2311 | 2225 |
2312 /* For currency parsing purose, | |
2313 * Need to remember all prefix patterns and suffix patterns of | |
2314 * every currency format pattern, | |
2315 * including the pattern of default currecny style | |
2316 * and plural currency style. And the patterns are set through applyPattern. | |
2317 */ | |
2318 // TODO: innerclass? | |
2319 /* This is not needed in the class declaration, so it is moved into decimfmp
.cpp | |
2320 struct AffixPatternsForCurrency : public UMemory { | |
2321 // negative prefix pattern | |
2322 UnicodeString negPrefixPatternForCurrency; | |
2323 // negative suffix pattern | |
2324 UnicodeString negSuffixPatternForCurrency; | |
2325 // positive prefix pattern | |
2326 UnicodeString posPrefixPatternForCurrency; | |
2327 // positive suffix pattern | |
2328 UnicodeString posSuffixPatternForCurrency; | |
2329 int8_t patternType; | |
2330 | |
2331 AffixPatternsForCurrency(const UnicodeString& negPrefix, | |
2332 const UnicodeString& negSuffix, | |
2333 const UnicodeString& posPrefix, | |
2334 const UnicodeString& posSuffix, | |
2335 int8_t type) { | |
2336 negPrefixPatternForCurrency = negPrefix; | |
2337 negSuffixPatternForCurrency = negSuffix; | |
2338 posPrefixPatternForCurrency = posPrefix; | |
2339 posSuffixPatternForCurrency = posSuffix; | |
2340 patternType = type; | |
2341 } | |
2342 }; | |
2343 */ | |
2344 | |
2345 /* affix for currency formatting when the currency sign in the pattern | |
2346 * equals to 3, such as the pattern contains 3 currency sign or | |
2347 * the formatter style is currency plural format style. | |
2348 */ | |
2349 /* This is not needed in the class declaration, so it is moved into decimfmp
.cpp | |
2350 struct AffixesForCurrency : public UMemory { | |
2351 // negative prefix | |
2352 UnicodeString negPrefixForCurrency; | |
2353 // negative suffix | |
2354 UnicodeString negSuffixForCurrency; | |
2355 // positive prefix | |
2356 UnicodeString posPrefixForCurrency; | |
2357 // positive suffix | |
2358 UnicodeString posSuffixForCurrency; | |
2359 | |
2360 int32_t formatWidth; | |
2361 | |
2362 AffixesForCurrency(const UnicodeString& negPrefix, | |
2363 const UnicodeString& negSuffix, | |
2364 const UnicodeString& posPrefix, | |
2365 const UnicodeString& posSuffix) { | |
2366 negPrefixForCurrency = negPrefix; | |
2367 negSuffixForCurrency = negSuffix; | |
2368 posPrefixForCurrency = posPrefix; | |
2369 posSuffixForCurrency = posSuffix; | |
2370 } | |
2371 }; | |
2372 */ | |
2373 | |
2374 // Affix pattern set for currency. | 2226 // Affix pattern set for currency. |
2375 // It is a set of AffixPatternsForCurrency, | 2227 // It is a set of AffixPatternsForCurrency, |
2376 // each element of the set saves the negative prefix pattern, | 2228 // each element of the set saves the negative prefix pattern, |
2377 // negative suffix pattern, positive prefix pattern, | 2229 // negative suffix pattern, positive prefix pattern, |
2378 // and positive suffix pattern of a pattern. | 2230 // and positive suffix pattern of a pattern. |
2379 // It is used for currency mixed style parsing. | 2231 // It is used for currency mixed style parsing. |
2380 // It is actually is a set. | 2232 // It is actually is a set. |
2381 // The set contains the default currency pattern from the locale, | 2233 // The set contains the default currency pattern from the locale, |
2382 // and the currency plural patterns. | 2234 // and the currency plural patterns. |
2383 // Since it is a set, it does not contain duplicated items. | 2235 // Since it is a set, it does not contain duplicated items. |
2384 // For example, if 2 currency plural patterns are the same, only one pattern | 2236 // For example, if 2 currency plural patterns are the same, only one pattern |
2385 // is included in the set. When parsing, we do not check whether the plural | 2237 // is included in the set. When parsing, we do not check whether the plural |
2386 // count match or not. | 2238 // count match or not. |
2387 Hashtable* fAffixPatternsForCurrency; | 2239 Hashtable* fAffixPatternsForCurrency; |
2388 | 2240 |
2389 // Following 2 are affixes for currency. | |
2390 // It is a hash map from plural count to AffixesForCurrency. | |
2391 // AffixesForCurrency saves the negative prefix, | |
2392 // negative suffix, positive prefix, and positive suffix of a pattern. | |
2393 // It is used during currency formatting only when the currency sign count | |
2394 // is 3. In which case, the affixes are getting from here, not | |
2395 // from the fNegativePrefix etc. | |
2396 Hashtable* fAffixesForCurrency; // for current pattern | |
2397 Hashtable* fPluralAffixesForCurrency; // for plural pattern | |
2398 | |
2399 // Information needed for DecimalFormat to format/parse currency plural. | 2241 // Information needed for DecimalFormat to format/parse currency plural. |
2400 CurrencyPluralInfo* fCurrencyPluralInfo; | 2242 CurrencyPluralInfo* fCurrencyPluralInfo; |
2401 | 2243 |
2402 #if UCONFIG_HAVE_PARSEALLINPUT | 2244 #if UCONFIG_HAVE_PARSEALLINPUT |
2403 UNumberFormatAttributeValue fParseAllInput; | 2245 UNumberFormatAttributeValue fParseAllInput; |
2404 #endif | 2246 #endif |
2405 | 2247 |
2406 // Decimal Format Static Sets singleton. | 2248 // Decimal Format Static Sets singleton. |
2407 const DecimalFormatStaticSets *fStaticSets; | 2249 const DecimalFormatStaticSets *fStaticSets; |
2408 | 2250 |
2409 // Currency Usage(STANDARD vs CASH) | |
2410 UCurrencyUsage fCurrencyUsage; | |
2411 | |
2412 protected: | 2251 protected: |
2413 | 2252 |
2414 #ifndef U_HIDE_INTERNAL_API | 2253 #ifndef U_HIDE_INTERNAL_API |
2415 /** | 2254 /** |
2416 * Rounds a value according to the rules of this object. | 2255 * Rounds a value according to the rules of this object. |
2417 * @internal | 2256 * @internal |
2418 */ | 2257 */ |
2419 DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& is
Negative, UErrorCode& status) const; | 2258 DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& is
Negative, UErrorCode& status) const; |
2420 #endif /* U_HIDE_INTERNAL_API */ | 2259 #endif /* U_HIDE_INTERNAL_API */ |
2421 | 2260 |
(...skipping 21 matching lines...) Expand all Loading... |
2443 * number of digits is due to flipping from some other mode that didn't | 2282 * number of digits is due to flipping from some other mode that didn't |
2444 * restrict the maximum, and so we force 1 integer digit. We don't bother | 2283 * restrict the maximum, and so we force 1 integer digit. We don't bother |
2445 * to track and see if someone is using exponential notation with more than | 2284 * to track and see if someone is using exponential notation with more than |
2446 * this number, it wouldn't make sense anyway, and this is just to make sure | 2285 * this number, it wouldn't make sense anyway, and this is just to make sure |
2447 * that someone turning on scientific mode with default settings doesn't | 2286 * that someone turning on scientific mode with default settings doesn't |
2448 * end up with lots of zeroes. | 2287 * end up with lots of zeroes. |
2449 * @stable ICU 2.8 | 2288 * @stable ICU 2.8 |
2450 */ | 2289 */ |
2451 static const int32_t kMaxScientificIntegerDigits; | 2290 static const int32_t kMaxScientificIntegerDigits; |
2452 | 2291 |
2453 #if UCONFIG_FORMAT_FASTPATHS_49 | |
2454 private: | |
2455 /** | |
2456 * Internal state. | |
2457 * @internal | |
2458 */ | |
2459 uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE]; | |
2460 | |
2461 | |
2462 /** | |
2463 * Called whenever any state changes. Recomputes whether fastpath is OK to u
se. | |
2464 */ | |
2465 void handleChanged(); | |
2466 #endif | |
2467 }; | 2292 }; |
2468 | 2293 |
2469 inline const UnicodeString & | |
2470 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol)
const { | |
2471 return fSymbols->getConstSymbol(symbol); | |
2472 } | |
2473 | |
2474 U_NAMESPACE_END | 2294 U_NAMESPACE_END |
2475 | 2295 |
2476 #endif /* #if !UCONFIG_NO_FORMATTING */ | 2296 #endif /* #if !UCONFIG_NO_FORMATTING */ |
2477 | 2297 |
2478 #endif // _DECIMFMT | 2298 #endif // _DECIMFMT |
2479 //eof | 2299 //eof |
OLD | NEW |