1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBER_DECIMFMTPROPS_H__
8 #define __NUMBER_DECIMFMTPROPS_H__
10 #include "unicode/unistr.h"
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"
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
25 // Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
27 #pragma warning(disable: 4661)
29 template class U_I18N_API LocalPointerBase
<CurrencyPluralInfo
>;
30 template class U_I18N_API LocalPointer
<CurrencyPluralInfo
>;
39 // Exported as U_I18N_API because it is a public member field of exported DecimalFormatProperties
40 // Using this wrapper is rather unfortunate, but is needed on Windows platforms in order to allow
41 // for DLL-exporting an fully specified template instantiation.
42 class U_I18N_API CurrencyPluralInfoWrapper
{
44 LocalPointer
<CurrencyPluralInfo
> fPtr
;
46 CurrencyPluralInfoWrapper() = default;
48 CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper
& other
) {
49 if (!other
.fPtr
.isNull()) {
50 fPtr
.adoptInstead(new CurrencyPluralInfo(*other
.fPtr
));
54 CurrencyPluralInfoWrapper
& operator=(const CurrencyPluralInfoWrapper
& other
) {
55 if (!other
.fPtr
.isNull()) {
56 fPtr
.adoptInstead(new CurrencyPluralInfo(*other
.fPtr
));
62 /** Controls the set of rules for parsing a string from the old DecimalFormat API. */
65 * Lenient mode should be used if you want to accept malformed user input. It will use heuristics
66 * to attempt to parse through typographical errors in the string.
71 * Strict mode should be used if you want to require that the input is well-formed. More
72 * specifically, it differs from lenient mode in the following ways:
75 * <li>Grouping widths must match the grouping settings. For example, "12,3,45" will fail if the
76 * grouping width is 3, as in the pattern "#,##0".
77 * <li>The string must contain a complete prefix and suffix. For example, if the pattern is
78 * "{#};(#)", then "{123}" or "(123)" would match, but "{123", "123}", and "123" would all fail.
79 * (The latter strings would be accepted in lenient mode.)
80 * <li>Whitespace may not appear at arbitrary places in the string. In lenient mode, whitespace
81 * is allowed to occur arbitrarily before and after prefixes and exponent separators.
82 * <li>Leading grouping separators are not allowed, as in ",123".
83 * <li>Minus and plus signs can only appear if specified in the pattern. In lenient mode, a plus
84 * or minus sign can always precede a number.
85 * <li>The set of characters that can be interpreted as a decimal or grouping separator is
87 * <li><strong>If currency parsing is enabled,</strong> currencies must only appear where
88 * specified in either the current pattern string or in a valid pattern string for the current
89 * locale. For example, if the pattern is "¤0.00", then "$1.23" would match, but "1.23$" would
96 // Exported as U_I18N_API because it is needed for the unit test PatternStringTest
97 struct U_I18N_API DecimalFormatProperties
: public UMemory
{
100 NullableValue
<UNumberCompactStyle
> compactStyle
;
101 NullableValue
<CurrencyUnit
> currency
;
102 CurrencyPluralInfoWrapper currencyPluralInfo
;
103 NullableValue
<UCurrencyUsage
> currencyUsage
;
104 bool decimalPatternMatchRequired
;
105 bool decimalSeparatorAlwaysShown
;
106 bool exponentSignAlwaysShown
;
107 bool formatFailIfMoreThanMaxDigits
; // ICU4C-only
109 int32_t groupingSize
;
111 int32_t magnitudeMultiplier
; // internal field like multiplierScale but separate to avoid conflict
112 int32_t maximumFractionDigits
;
113 int32_t maximumIntegerDigits
;
114 int32_t maximumSignificantDigits
;
115 int32_t minimumExponentDigits
;
116 int32_t minimumFractionDigits
;
117 int32_t minimumGroupingDigits
;
118 int32_t minimumIntegerDigits
;
119 int32_t minimumSignificantDigits
;
121 int32_t multiplierScale
; // ICU4C-only
122 UnicodeString negativePrefix
;
123 UnicodeString negativePrefixPattern
;
124 UnicodeString negativeSuffix
;
125 UnicodeString negativeSuffixPattern
;
126 NullableValue
<PadPosition
> padPosition
;
127 UnicodeString padString
;
128 bool parseCaseSensitive
;
129 bool parseIntegerOnly
;
130 NullableValue
<ParseMode
> parseMode
;
131 bool parseNoExponent
;
132 bool parseToBigDecimal
; // TODO: Not needed in ICU4C?
133 UNumberFormatAttributeValue parseAllInput
; // ICU4C-only
134 //PluralRules pluralRules;
135 UnicodeString positivePrefix
;
136 UnicodeString positivePrefixPattern
;
137 UnicodeString positiveSuffix
;
138 UnicodeString positiveSuffixPattern
;
139 double roundingIncrement
;
140 NullableValue
<RoundingMode
> roundingMode
;
141 int32_t secondaryGroupingSize
;
142 bool signAlwaysShown
;
143 bool formatFullPrecision
; // Apple addition for <rdar://problem/39240173>
145 DecimalFormatProperties();
147 inline bool operator==(const DecimalFormatProperties
& other
) const {
148 return _equals(other
, false);
154 * Checks for equality to the default DecimalFormatProperties, but ignores the prescribed set of
155 * options for fast-path formatting.
157 bool equalsDefaultExceptFastFormat() const;
160 * Returns the default DecimalFormatProperties instance.
162 static const DecimalFormatProperties
& getDefault();
165 bool _equals(const DecimalFormatProperties
& other
, bool ignoreForFastFormat
) const;
169 } // namespace number
173 #endif //__NUMBER_DECIMFMTPROPS_H__
175 #endif /* #if !UCONFIG_NO_FORMATTING */