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
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
>;
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
{
38 LocalPointer
<CurrencyPluralInfo
> fPtr
;
40 CurrencyPluralInfoWrapper() = default;
42 CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper
& other
) {
43 if (!other
.fPtr
.isNull()) {
44 fPtr
.adoptInstead(new CurrencyPluralInfo(*other
.fPtr
));
48 CurrencyPluralInfoWrapper
& operator=(const CurrencyPluralInfoWrapper
& other
) {
49 if (!other
.fPtr
.isNull()) {
50 fPtr
.adoptInstead(new CurrencyPluralInfo(*other
.fPtr
));
56 /** Controls the set of rules for parsing a string from the old DecimalFormat API. */
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.
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:
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
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
90 // Exported as U_I18N_API because it is needed for the unit test PatternStringTest
91 struct U_I18N_API DecimalFormatProperties
: public UMemory
{
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
103 int32_t groupingSize
;
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
;
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
;
138 DecimalFormatProperties();
140 inline bool operator==(const DecimalFormatProperties
& other
) const {
141 return _equals(other
, false);
147 * Checks for equality to the default DecimalFormatProperties, but ignores the prescribed set of
148 * options for fast-path formatting.
150 bool equalsDefaultExceptFastFormat() const;
153 bool _equals(const DecimalFormatProperties
& other
, bool ignoreForFastFormat
) const;
157 } // namespace number
161 #endif //__NUMBER_DECIMFMTPROPS_H__
163 #endif /* #if !UCONFIG_NO_FORMATTING */