Coverage Report

Created: 2018-09-25 14:53

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