]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/number_decimfmtprops.h
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / number_decimfmtprops.h
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBER_DECIMFMTPROPS_H__
8 #define __NUMBER_DECIMFMTPROPS_H__
9
10 #include "unicode/unistr.h"
11 #include <cstdint>
12 #include "unicode/plurrule.h"
13 #include "unicode/currpinf.h"
14 #include "unicode/unum.h"
15 #include "unicode/localpointer.h"
16 #include "number_types.h"
17
18 U_NAMESPACE_BEGIN
19
20 // Export an explicit template instantiation of the LocalPointer that is used as a
21 // data member of CurrencyPluralInfoWrapper.
22 // (When building DLLs for Windows this is required.)
23 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
24 // Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
25 #pragma warning(suppress: 4661)
26 template class U_I18N_API LocalPointerBase<CurrencyPluralInfo>;
27 template class U_I18N_API LocalPointer<CurrencyPluralInfo>;
28 #endif
29
30 namespace number {
31 namespace impl {
32
33 // Exported as U_I18N_API because it is a public member field of exported DecimalFormatProperties
34 // Using this wrapper is rather unfortunate, but is needed on Windows platforms in order to allow
35 // for DLL-exporting an fully specified template instantiation.
36 class U_I18N_API CurrencyPluralInfoWrapper {
37 public:
38 LocalPointer<CurrencyPluralInfo> fPtr;
39
40 CurrencyPluralInfoWrapper() = default;
41
42 CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper& other) {
43 if (!other.fPtr.isNull()) {
44 fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr));
45 }
46 }
47
48 CurrencyPluralInfoWrapper& operator=(const CurrencyPluralInfoWrapper& other) {
49 if (!other.fPtr.isNull()) {
50 fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr));
51 }
52 return *this;
53 }
54 };
55
56 /** Controls the set of rules for parsing a string from the old DecimalFormat API. */
57 enum ParseMode {
58 /**
59 * Lenient mode should be used if you want to accept malformed user input. It will use heuristics
60 * to attempt to parse through typographical errors in the string.
61 */
62 PARSE_MODE_LENIENT,
63
64 /**
65 * Strict mode should be used if you want to require that the input is well-formed. More
66 * specifically, it differs from lenient mode in the following ways:
67 *
68 * <ul>
69 * <li>Grouping widths must match the grouping settings. For example, "12,3,45" will fail if the
70 * grouping width is 3, as in the pattern "#,##0".
71 * <li>The string must contain a complete prefix and suffix. For example, if the pattern is
72 * "{#};(#)", then "{123}" or "(123)" would match, but "{123", "123}", and "123" would all fail.
73 * (The latter strings would be accepted in lenient mode.)
74 * <li>Whitespace may not appear at arbitrary places in the string. In lenient mode, whitespace
75 * is allowed to occur arbitrarily before and after prefixes and exponent separators.
76 * <li>Leading grouping separators are not allowed, as in ",123".
77 * <li>Minus and plus signs can only appear if specified in the pattern. In lenient mode, a plus
78 * or minus sign can always precede a number.
79 * <li>The set of characters that can be interpreted as a decimal or grouping separator is
80 * smaller.
81 * <li><strong>If currency parsing is enabled,</strong> currencies must only appear where
82 * specified in either the current pattern string or in a valid pattern string for the current
83 * locale. For example, if the pattern is "¤0.00", then "$1.23" would match, but "1.23$" would
84 * fail to match.
85 * </ul>
86 */
87 PARSE_MODE_STRICT,
88 };
89
90 // Exported as U_I18N_API because it is needed for the unit test PatternStringTest
91 struct U_I18N_API DecimalFormatProperties : public UMemory {
92
93 public:
94 NullableValue<UNumberCompactStyle> compactStyle;
95 NullableValue<CurrencyUnit> currency;
96 CurrencyPluralInfoWrapper currencyPluralInfo;
97 NullableValue<UCurrencyUsage> currencyUsage;
98 bool decimalPatternMatchRequired;
99 bool decimalSeparatorAlwaysShown;
100 bool exponentSignAlwaysShown;
101 bool formatFailIfMoreThanMaxDigits; // ICU4C-only
102 int32_t formatWidth;
103 int32_t groupingSize;
104 bool groupingUsed;
105 int32_t magnitudeMultiplier; // internal field like multiplierScale but separate to avoid conflict
106 int32_t maximumFractionDigits;
107 int32_t maximumIntegerDigits;
108 int32_t maximumSignificantDigits;
109 int32_t minimumExponentDigits;
110 int32_t minimumFractionDigits;
111 int32_t minimumGroupingDigits;
112 int32_t minimumIntegerDigits;
113 int32_t minimumSignificantDigits;
114 int32_t multiplier;
115 int32_t multiplierScale; // ICU4C-only
116 UnicodeString negativePrefix;
117 UnicodeString negativePrefixPattern;
118 UnicodeString negativeSuffix;
119 UnicodeString negativeSuffixPattern;
120 NullableValue<PadPosition> padPosition;
121 UnicodeString padString;
122 bool parseCaseSensitive;
123 bool parseIntegerOnly;
124 NullableValue<ParseMode> parseMode;
125 bool parseNoExponent;
126 bool parseToBigDecimal; // TODO: Not needed in ICU4C?
127 UNumberFormatAttributeValue parseAllInput; // ICU4C-only
128 //PluralRules pluralRules;
129 UnicodeString positivePrefix;
130 UnicodeString positivePrefixPattern;
131 UnicodeString positiveSuffix;
132 UnicodeString positiveSuffixPattern;
133 double roundingIncrement;
134 NullableValue<RoundingMode> roundingMode;
135 int32_t secondaryGroupingSize;
136 bool signAlwaysShown;
137
138 DecimalFormatProperties();
139
140 inline bool operator==(const DecimalFormatProperties& other) const {
141 return _equals(other, false);
142 }
143
144 void clear();
145
146 /**
147 * Checks for equality to the default DecimalFormatProperties, but ignores the prescribed set of
148 * options for fast-path formatting.
149 */
150 bool equalsDefaultExceptFastFormat() const;
151
152 private:
153 bool _equals(const DecimalFormatProperties& other, bool ignoreForFastFormat) const;
154 };
155
156 } // namespace impl
157 } // namespace number
158 U_NAMESPACE_END
159
160
161 #endif //__NUMBER_DECIMFMTPROPS_H__
162
163 #endif /* #if !UCONFIG_NO_FORMATTING */