Coverage Report

Created: 2026-03-31 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/number_decimfmtprops.cpp
Line
Count
Source
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
8
#include "number_decimfmtprops.h"
9
#include "umutex.h"
10
11
using namespace icu;
12
using namespace icu::number;
13
using namespace icu::number::impl;
14
15
16
namespace {
17
18
alignas(DecimalFormatProperties)
19
char kRawDefaultProperties[sizeof(DecimalFormatProperties)];
20
21
icu::UInitOnce gDefaultPropertiesInitOnce {};
22
23
4
void U_CALLCONV initDefaultProperties(UErrorCode&) {
24
    // can't fail, uses placement new into statically allocated space.
25
4
    new(kRawDefaultProperties) DecimalFormatProperties(); // set to the default instance
26
4
}
27
28
}
29
30
31
737k
DecimalFormatProperties::DecimalFormatProperties() {
32
737k
    clear();
33
737k
}
34
35
738k
void DecimalFormatProperties::clear() {
36
738k
    compactStyle.nullify();
37
738k
    currency.nullify();
38
738k
    currencyPluralInfo.fPtr.adoptInstead(nullptr);
39
738k
    currencyUsage.nullify();
40
738k
    decimalPatternMatchRequired = false;
41
738k
    decimalSeparatorAlwaysShown = false;
42
738k
    exponentSignAlwaysShown = false;
43
738k
    currencyAsDecimal = false;
44
738k
    formatFailIfMoreThanMaxDigits = false;
45
738k
    formatWidth = -1;
46
738k
    groupingSize = -1;
47
738k
    groupingUsed = true;
48
738k
    magnitudeMultiplier = 0;
49
738k
    maximumFractionDigits = -1;
50
738k
    maximumIntegerDigits = -1;
51
738k
    maximumSignificantDigits = -1;
52
738k
    minimumExponentDigits = -1;
53
738k
    minimumFractionDigits = -1;
54
738k
    minimumGroupingDigits = -1;
55
738k
    minimumIntegerDigits = -1;
56
738k
    minimumSignificantDigits = -1;
57
738k
    multiplier = 1;
58
738k
    multiplierScale = 0;
59
738k
    negativePrefix.setToBogus();
60
738k
    negativePrefixPattern.setToBogus();
61
738k
    negativeSuffix.setToBogus();
62
738k
    negativeSuffixPattern.setToBogus();
63
738k
    padPosition.nullify();
64
738k
    padString.setToBogus();
65
738k
    parseCaseSensitive = false;
66
738k
    parseIntegerOnly = false;
67
738k
    parseMode.nullify();
68
738k
    parseNoExponent = false;
69
738k
    parseToBigDecimal = false;
70
738k
    parseAllInput = UNUM_MAYBE;
71
738k
    positivePrefix.setToBogus();
72
738k
    positivePrefixPattern.setToBogus();
73
738k
    positiveSuffix.setToBogus();
74
738k
    positiveSuffixPattern.setToBogus();
75
738k
    roundingIncrement = 0.0;
76
738k
    roundingMode.nullify();
77
738k
    secondaryGroupingSize = -1;
78
738k
    signAlwaysShown = false;
79
738k
}
80
81
bool
82
593k
DecimalFormatProperties::_equals(const DecimalFormatProperties& other, bool ignoreForFastFormat) const {
83
593k
    bool eq = true;
84
85
    // Properties that must be equal both normally and for fast-path formatting
86
593k
    eq = eq && compactStyle == other.compactStyle;
87
593k
    eq = eq && currency == other.currency;
88
593k
    eq = eq && currencyPluralInfo.fPtr.getAlias() == other.currencyPluralInfo.fPtr.getAlias();
89
593k
    eq = eq && currencyUsage == other.currencyUsage;
90
593k
    eq = eq && decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown;
91
593k
    eq = eq && exponentSignAlwaysShown == other.exponentSignAlwaysShown;
92
593k
    eq = eq && currencyAsDecimal == other.currencyAsDecimal;
93
593k
    eq = eq && formatFailIfMoreThanMaxDigits == other.formatFailIfMoreThanMaxDigits;
94
593k
    eq = eq && formatWidth == other.formatWidth;
95
593k
    eq = eq && magnitudeMultiplier == other.magnitudeMultiplier;
96
593k
    eq = eq && maximumSignificantDigits == other.maximumSignificantDigits;
97
593k
    eq = eq && minimumExponentDigits == other.minimumExponentDigits;
98
593k
    eq = eq && minimumGroupingDigits == other.minimumGroupingDigits;
99
593k
    eq = eq && minimumSignificantDigits == other.minimumSignificantDigits;
100
593k
    eq = eq && multiplier == other.multiplier;
101
593k
    eq = eq && multiplierScale == other.multiplierScale;
102
593k
    eq = eq && negativePrefix == other.negativePrefix;
103
593k
    eq = eq && negativeSuffix == other.negativeSuffix;
104
593k
    eq = eq && padPosition == other.padPosition;
105
593k
    eq = eq && padString == other.padString;
106
593k
    eq = eq && positivePrefix == other.positivePrefix;
107
593k
    eq = eq && positiveSuffix == other.positiveSuffix;
108
593k
    eq = eq && roundingIncrement == other.roundingIncrement;
109
593k
    eq = eq && roundingMode == other.roundingMode;
110
593k
    eq = eq && secondaryGroupingSize == other.secondaryGroupingSize;
111
593k
    eq = eq && signAlwaysShown == other.signAlwaysShown;
112
113
593k
    if (ignoreForFastFormat) {
114
593k
        return eq;
115
593k
    }
116
117
    // Properties ignored by fast-path formatting
118
    // Formatting (special handling required):
119
0
    eq = eq && groupingSize == other.groupingSize;
120
0
    eq = eq && groupingUsed == other.groupingUsed;
121
0
    eq = eq && minimumFractionDigits == other.minimumFractionDigits;
122
0
    eq = eq && maximumFractionDigits == other.maximumFractionDigits;
123
0
    eq = eq && maximumIntegerDigits == other.maximumIntegerDigits;
124
0
    eq = eq && minimumIntegerDigits == other.minimumIntegerDigits;
125
0
    eq = eq && negativePrefixPattern == other.negativePrefixPattern;
126
0
    eq = eq && negativeSuffixPattern == other.negativeSuffixPattern;
127
0
    eq = eq && positivePrefixPattern == other.positivePrefixPattern;
128
0
    eq = eq && positiveSuffixPattern == other.positiveSuffixPattern;
129
130
    // Parsing (always safe to ignore):
131
0
    eq = eq && decimalPatternMatchRequired == other.decimalPatternMatchRequired;
132
0
    eq = eq && parseCaseSensitive == other.parseCaseSensitive;
133
0
    eq = eq && parseIntegerOnly == other.parseIntegerOnly;
134
0
    eq = eq && parseMode == other.parseMode;
135
0
    eq = eq && parseNoExponent == other.parseNoExponent;
136
0
    eq = eq && parseToBigDecimal == other.parseToBigDecimal;
137
0
    eq = eq && parseAllInput == other.parseAllInput;
138
139
0
    return eq;
140
593k
}
141
142
593k
bool DecimalFormatProperties::equalsDefaultExceptFastFormat() const {
143
593k
    UErrorCode localStatus = U_ZERO_ERROR;
144
593k
    umtx_initOnce(gDefaultPropertiesInitOnce, &initDefaultProperties, localStatus);
145
593k
    return _equals(*reinterpret_cast<DecimalFormatProperties*>(kRawDefaultProperties), true);
146
593k
}
147
148
0
const DecimalFormatProperties& DecimalFormatProperties::getDefault() {
149
0
    UErrorCode localStatus = U_ZERO_ERROR;
150
0
    umtx_initOnce(gDefaultPropertiesInitOnce, &initDefaultProperties, localStatus);
151
0
    return *reinterpret_cast<const DecimalFormatProperties*>(kRawDefaultProperties);
152
0
}
153
154
#endif /* #if !UCONFIG_NO_FORMATTING */