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
8 #include "number_decimfmtprops.h"
12 using namespace icu::number
;
13 using namespace icu::number::impl
;
18 char kRawDefaultProperties
[sizeof(DecimalFormatProperties
)];
20 icu::UInitOnce gDefaultPropertiesInitOnce
= U_INITONCE_INITIALIZER
;
22 void U_CALLCONV
initDefaultProperties(UErrorCode
&) {
23 new(kRawDefaultProperties
) DecimalFormatProperties(); // set to the default instance
29 DecimalFormatProperties::DecimalFormatProperties() {
33 void DecimalFormatProperties::clear() {
34 compactStyle
.nullify();
36 currencyPluralInfo
.fPtr
.adoptInstead(nullptr);
37 currencyUsage
.nullify();
38 decimalPatternMatchRequired
= false;
39 decimalSeparatorAlwaysShown
= false;
40 exponentSignAlwaysShown
= false;
41 formatFailIfMoreThanMaxDigits
= false;
45 magnitudeMultiplier
= 0;
46 maximumFractionDigits
= -1;
47 maximumIntegerDigits
= -1;
48 maximumSignificantDigits
= -1;
49 minimumExponentDigits
= -1;
50 minimumFractionDigits
= -1;
51 minimumGroupingDigits
= -1;
52 minimumIntegerDigits
= -1;
53 minimumSignificantDigits
= -1;
56 negativePrefix
.setToBogus();
57 negativePrefixPattern
.setToBogus();
58 negativeSuffix
.setToBogus();
59 negativeSuffixPattern
.setToBogus();
60 padPosition
.nullify();
61 padString
.setToBogus();
62 parseCaseSensitive
= false;
63 parseIntegerOnly
= false;
65 parseNoExponent
= false;
66 parseToBigDecimal
= false;
67 parseAllInput
= UNUM_MAYBE
;
68 positivePrefix
.setToBogus();
69 positivePrefixPattern
.setToBogus();
70 positiveSuffix
.setToBogus();
71 positiveSuffixPattern
.setToBogus();
72 roundingIncrement
= 0.0;
73 roundingMode
.nullify();
74 secondaryGroupingSize
= -1;
75 signAlwaysShown
= false;
79 DecimalFormatProperties::_equals(const DecimalFormatProperties
& other
, bool ignoreForFastFormat
) const {
82 // Properties that must be equal both normally and for fast-path formatting
83 eq
= eq
&& compactStyle
== other
.compactStyle
;
84 eq
= eq
&& currency
== other
.currency
;
85 eq
= eq
&& currencyPluralInfo
.fPtr
.getAlias() == other
.currencyPluralInfo
.fPtr
.getAlias();
86 eq
= eq
&& currencyUsage
== other
.currencyUsage
;
87 eq
= eq
&& decimalSeparatorAlwaysShown
== other
.decimalSeparatorAlwaysShown
;
88 eq
= eq
&& exponentSignAlwaysShown
== other
.exponentSignAlwaysShown
;
89 eq
= eq
&& formatFailIfMoreThanMaxDigits
== other
.formatFailIfMoreThanMaxDigits
;
90 eq
= eq
&& formatWidth
== other
.formatWidth
;
91 eq
= eq
&& magnitudeMultiplier
== other
.magnitudeMultiplier
;
92 eq
= eq
&& maximumSignificantDigits
== other
.maximumSignificantDigits
;
93 eq
= eq
&& minimumExponentDigits
== other
.minimumExponentDigits
;
94 eq
= eq
&& minimumGroupingDigits
== other
.minimumGroupingDigits
;
95 eq
= eq
&& minimumSignificantDigits
== other
.minimumSignificantDigits
;
96 eq
= eq
&& multiplier
== other
.multiplier
;
97 eq
= eq
&& multiplierScale
== other
.multiplierScale
;
98 eq
= eq
&& negativePrefix
== other
.negativePrefix
;
99 eq
= eq
&& negativeSuffix
== other
.negativeSuffix
;
100 eq
= eq
&& padPosition
== other
.padPosition
;
101 eq
= eq
&& padString
== other
.padString
;
102 eq
= eq
&& positivePrefix
== other
.positivePrefix
;
103 eq
= eq
&& positiveSuffix
== other
.positiveSuffix
;
104 eq
= eq
&& roundingIncrement
== other
.roundingIncrement
;
105 eq
= eq
&& roundingMode
== other
.roundingMode
;
106 eq
= eq
&& secondaryGroupingSize
== other
.secondaryGroupingSize
;
107 eq
= eq
&& signAlwaysShown
== other
.signAlwaysShown
;
109 if (ignoreForFastFormat
) {
113 // Properties ignored by fast-path formatting
114 // Formatting (special handling required):
115 eq
= eq
&& groupingSize
== other
.groupingSize
;
116 eq
= eq
&& groupingUsed
== other
.groupingUsed
;
117 eq
= eq
&& minimumFractionDigits
== other
.minimumFractionDigits
;
118 eq
= eq
&& maximumFractionDigits
== other
.maximumFractionDigits
;
119 eq
= eq
&& maximumIntegerDigits
== other
.maximumIntegerDigits
;
120 eq
= eq
&& minimumIntegerDigits
== other
.minimumIntegerDigits
;
121 eq
= eq
&& negativePrefixPattern
== other
.negativePrefixPattern
;
122 eq
= eq
&& negativeSuffixPattern
== other
.negativeSuffixPattern
;
123 eq
= eq
&& positivePrefixPattern
== other
.positivePrefixPattern
;
124 eq
= eq
&& positiveSuffixPattern
== other
.positiveSuffixPattern
;
126 // Parsing (always safe to ignore):
127 eq
= eq
&& decimalPatternMatchRequired
== other
.decimalPatternMatchRequired
;
128 eq
= eq
&& parseCaseSensitive
== other
.parseCaseSensitive
;
129 eq
= eq
&& parseIntegerOnly
== other
.parseIntegerOnly
;
130 eq
= eq
&& parseMode
== other
.parseMode
;
131 eq
= eq
&& parseNoExponent
== other
.parseNoExponent
;
132 eq
= eq
&& parseToBigDecimal
== other
.parseToBigDecimal
;
133 eq
= eq
&& parseAllInput
== other
.parseAllInput
;
138 bool DecimalFormatProperties::equalsDefaultExceptFastFormat() const {
139 UErrorCode localStatus
= U_ZERO_ERROR
;
140 umtx_initOnce(gDefaultPropertiesInitOnce
, &initDefaultProperties
, localStatus
);
141 return _equals(*reinterpret_cast<DecimalFormatProperties
*>(kRawDefaultProperties
), true);
144 #endif /* #if !UCONFIG_NO_FORMATTING */