/src/icu/icu4c/source/i18n/number_fluent.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 "uassert.h" |
9 | | #include "unicode/numberformatter.h" |
10 | | #include "number_decimalquantity.h" |
11 | | #include "number_formatimpl.h" |
12 | | #include "umutex.h" |
13 | | #include "number_asformat.h" |
14 | | #include "number_utils.h" |
15 | | #include "number_utypes.h" |
16 | | #include "number_mapper.h" |
17 | | #include "util.h" |
18 | | #include "fphdlimp.h" |
19 | | |
20 | | using namespace icu; |
21 | | using namespace icu::number; |
22 | | using namespace icu::number::impl; |
23 | | |
24 | | #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) |
25 | | // Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method |
26 | | // is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation |
27 | | // inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is |
28 | | // fully defined. However, since each translation unit explicitly instantiates all the necessary template classes, |
29 | | // they will all be passed to the linker, and the linker will still find and export all the class members. |
30 | | #pragma warning(push) |
31 | | #pragma warning(disable: 4661) |
32 | | #endif |
33 | | |
34 | | template<typename Derived> |
35 | 0 | Derived NumberFormatterSettings<Derived>::notation(const Notation& notation) const& { |
36 | 0 | Derived copy(*this); |
37 | | // NOTE: Slicing is OK. |
38 | 0 | copy.fMacros.notation = notation; |
39 | 0 | return copy; |
40 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::notation(icu_79::number::Notation const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::notation(icu_79::number::Notation const&) const & |
41 | | |
42 | | template<typename Derived> |
43 | 0 | Derived NumberFormatterSettings<Derived>::notation(const Notation& notation)&& { |
44 | 0 | Derived move(std::move(*this)); |
45 | | // NOTE: Slicing is OK. |
46 | 0 | move.fMacros.notation = notation; |
47 | 0 | return move; |
48 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::notation(icu_79::number::Notation const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::notation(icu_79::number::Notation const&) && |
49 | | |
50 | | template<typename Derived> |
51 | 0 | Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit) const& { |
52 | 0 | Derived copy(*this); |
53 | | // NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit. |
54 | | // TimeUnit may be affected, but TimeUnit is not as relevant to number formatting. |
55 | 0 | copy.fMacros.unit = unit; |
56 | 0 | return copy; |
57 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unit(icu_79::MeasureUnit const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unit(icu_79::MeasureUnit const&) const & |
58 | | |
59 | | template<typename Derived> |
60 | 0 | Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit)&& { |
61 | 0 | Derived move(std::move(*this)); |
62 | | // See comments above about slicing. |
63 | 0 | move.fMacros.unit = unit; |
64 | 0 | return move; |
65 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unit(icu_79::MeasureUnit const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unit(icu_79::MeasureUnit const&) && |
66 | | |
67 | | template<typename Derived> |
68 | 0 | Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit) const& { |
69 | 0 | Derived copy(*this); |
70 | | // Just move the unit into the MacroProps by value, and delete it since we have ownership. |
71 | | // NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit. |
72 | | // TimeUnit may be affected, but TimeUnit is not as relevant to number formatting. |
73 | 0 | if (unit != nullptr) { |
74 | | // TODO: On nullptr, reset to default value? |
75 | 0 | copy.fMacros.unit = std::move(*unit); |
76 | 0 | delete unit; |
77 | 0 | } |
78 | 0 | return copy; |
79 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptUnit(icu_79::MeasureUnit*) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptUnit(icu_79::MeasureUnit*) const & |
80 | | |
81 | | template<typename Derived> |
82 | 0 | Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit)&& { |
83 | 0 | Derived move(std::move(*this)); |
84 | | // See comments above about slicing and ownership. |
85 | 0 | if (unit != nullptr) { |
86 | | // TODO: On nullptr, reset to default value? |
87 | 0 | move.fMacros.unit = std::move(*unit); |
88 | 0 | delete unit; |
89 | 0 | } |
90 | 0 | return move; |
91 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptUnit(icu_79::MeasureUnit*) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptUnit(icu_79::MeasureUnit*) && |
92 | | |
93 | | template<typename Derived> |
94 | 0 | Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit) const& { |
95 | 0 | Derived copy(*this); |
96 | | // See comments above about slicing. |
97 | 0 | copy.fMacros.perUnit = perUnit; |
98 | 0 | return copy; |
99 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::perUnit(icu_79::MeasureUnit const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::perUnit(icu_79::MeasureUnit const&) const & |
100 | | |
101 | | template<typename Derived> |
102 | 0 | Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit)&& { |
103 | 0 | Derived move(std::move(*this)); |
104 | | // See comments above about slicing. |
105 | 0 | move.fMacros.perUnit = perUnit; |
106 | 0 | return move; |
107 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::perUnit(icu_79::MeasureUnit const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::perUnit(icu_79::MeasureUnit const&) && |
108 | | |
109 | | template<typename Derived> |
110 | 0 | Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit) const& { |
111 | 0 | Derived copy(*this); |
112 | | // See comments above about slicing and ownership. |
113 | 0 | if (perUnit != nullptr) { |
114 | | // TODO: On nullptr, reset to default value? |
115 | 0 | copy.fMacros.perUnit = std::move(*perUnit); |
116 | 0 | delete perUnit; |
117 | 0 | } |
118 | 0 | return copy; |
119 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptPerUnit(icu_79::MeasureUnit*) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptPerUnit(icu_79::MeasureUnit*) const & |
120 | | |
121 | | template<typename Derived> |
122 | 0 | Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit)&& { |
123 | 0 | Derived move(std::move(*this)); |
124 | | // See comments above about slicing and ownership. |
125 | 0 | if (perUnit != nullptr) { |
126 | | // TODO: On nullptr, reset to default value? |
127 | 0 | move.fMacros.perUnit = std::move(*perUnit); |
128 | 0 | delete perUnit; |
129 | 0 | } |
130 | 0 | return move; |
131 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptPerUnit(icu_79::MeasureUnit*) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptPerUnit(icu_79::MeasureUnit*) && |
132 | | |
133 | | template<typename Derived> |
134 | 0 | Derived NumberFormatterSettings<Derived>::precision(const Precision& precision) const& { |
135 | 0 | Derived copy(*this); |
136 | | // NOTE: Slicing is OK. |
137 | 0 | copy.fMacros.precision = precision; |
138 | 0 | return copy; |
139 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::precision(icu_79::number::Precision const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::precision(icu_79::number::Precision const&) const & |
140 | | |
141 | | template<typename Derived> |
142 | 0 | Derived NumberFormatterSettings<Derived>::precision(const Precision& precision)&& { |
143 | 0 | Derived move(std::move(*this)); |
144 | | // NOTE: Slicing is OK. |
145 | 0 | move.fMacros.precision = precision; |
146 | 0 | return move; |
147 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::precision(icu_79::number::Precision const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::precision(icu_79::number::Precision const&) && |
148 | | |
149 | | template<typename Derived> |
150 | 0 | Derived NumberFormatterSettings<Derived>::roundingMode(UNumberFormatRoundingMode roundingMode) const& { |
151 | 0 | Derived copy(*this); |
152 | 0 | copy.fMacros.roundingMode = roundingMode; |
153 | 0 | return copy; |
154 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::roundingMode(UNumberFormatRoundingMode) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::roundingMode(UNumberFormatRoundingMode) const & |
155 | | |
156 | | template<typename Derived> |
157 | 0 | Derived NumberFormatterSettings<Derived>::roundingMode(UNumberFormatRoundingMode roundingMode)&& { |
158 | 0 | Derived move(std::move(*this)); |
159 | 0 | move.fMacros.roundingMode = roundingMode; |
160 | 0 | return move; |
161 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::roundingMode(UNumberFormatRoundingMode) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::roundingMode(UNumberFormatRoundingMode) && |
162 | | |
163 | | template<typename Derived> |
164 | 0 | Derived NumberFormatterSettings<Derived>::grouping(UNumberGroupingStrategy strategy) const& { |
165 | 0 | Derived copy(*this); |
166 | | // NOTE: This is slightly different than how the setting is stored in Java |
167 | | // because we want to put it on the stack. |
168 | 0 | copy.fMacros.grouper = Grouper::forStrategy(strategy); |
169 | 0 | return copy; |
170 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::grouping(UNumberGroupingStrategy) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::grouping(UNumberGroupingStrategy) const & |
171 | | |
172 | | template<typename Derived> |
173 | 0 | Derived NumberFormatterSettings<Derived>::grouping(UNumberGroupingStrategy strategy)&& { |
174 | 0 | Derived move(std::move(*this)); |
175 | 0 | move.fMacros.grouper = Grouper::forStrategy(strategy); |
176 | 0 | return move; |
177 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::grouping(UNumberGroupingStrategy) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::grouping(UNumberGroupingStrategy) && |
178 | | |
179 | | template<typename Derived> |
180 | 0 | Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style) const& { |
181 | 0 | Derived copy(*this); |
182 | 0 | copy.fMacros.integerWidth = style; |
183 | 0 | return copy; |
184 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::integerWidth(icu_79::number::IntegerWidth const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::integerWidth(icu_79::number::IntegerWidth const&) const & |
185 | | |
186 | | template<typename Derived> |
187 | 0 | Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style)&& { |
188 | 0 | Derived move(std::move(*this)); |
189 | 0 | move.fMacros.integerWidth = style; |
190 | 0 | return move; |
191 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::integerWidth(icu_79::number::IntegerWidth const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::integerWidth(icu_79::number::IntegerWidth const&) && |
192 | | |
193 | | template<typename Derived> |
194 | 0 | Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols) const& { |
195 | 0 | Derived copy(*this); |
196 | 0 | copy.fMacros.symbols.setTo(symbols); |
197 | 0 | return copy; |
198 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::symbols(icu_79::DecimalFormatSymbols const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::symbols(icu_79::DecimalFormatSymbols const&) const & |
199 | | |
200 | | template<typename Derived> |
201 | 0 | Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols)&& { |
202 | 0 | Derived move(std::move(*this)); |
203 | 0 | move.fMacros.symbols.setTo(symbols); |
204 | 0 | return move; |
205 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::symbols(icu_79::DecimalFormatSymbols const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::symbols(icu_79::DecimalFormatSymbols const&) && |
206 | | |
207 | | template<typename Derived> |
208 | 0 | Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns) const& { |
209 | 0 | Derived copy(*this); |
210 | 0 | copy.fMacros.symbols.setTo(ns); |
211 | 0 | return copy; |
212 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptSymbols(icu_79::NumberingSystem*) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptSymbols(icu_79::NumberingSystem*) const & |
213 | | |
214 | | template<typename Derived> |
215 | 0 | Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns)&& { |
216 | 0 | Derived move(std::move(*this)); |
217 | 0 | move.fMacros.symbols.setTo(ns); |
218 | 0 | return move; |
219 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::adoptSymbols(icu_79::NumberingSystem*) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::adoptSymbols(icu_79::NumberingSystem*) && |
220 | | |
221 | | template<typename Derived> |
222 | 0 | Derived NumberFormatterSettings<Derived>::unitWidth(UNumberUnitWidth width) const& { |
223 | 0 | Derived copy(*this); |
224 | 0 | copy.fMacros.unitWidth = width; |
225 | 0 | return copy; |
226 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unitWidth(UNumberUnitWidth) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unitWidth(UNumberUnitWidth) const & |
227 | | |
228 | | template<typename Derived> |
229 | 0 | Derived NumberFormatterSettings<Derived>::unitWidth(UNumberUnitWidth width)&& { |
230 | 0 | Derived move(std::move(*this)); |
231 | 0 | move.fMacros.unitWidth = width; |
232 | 0 | return move; |
233 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unitWidth(UNumberUnitWidth) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unitWidth(UNumberUnitWidth) && |
234 | | |
235 | | template<typename Derived> |
236 | 0 | Derived NumberFormatterSettings<Derived>::sign(UNumberSignDisplay style) const& { |
237 | 0 | Derived copy(*this); |
238 | 0 | copy.fMacros.sign = style; |
239 | 0 | return copy; |
240 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::sign(UNumberSignDisplay) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::sign(UNumberSignDisplay) const & |
241 | | |
242 | | template<typename Derived> |
243 | 0 | Derived NumberFormatterSettings<Derived>::sign(UNumberSignDisplay style)&& { |
244 | 0 | Derived move(std::move(*this)); |
245 | 0 | move.fMacros.sign = style; |
246 | 0 | return move; |
247 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::sign(UNumberSignDisplay) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::sign(UNumberSignDisplay) && |
248 | | |
249 | | template<typename Derived> |
250 | 0 | Derived NumberFormatterSettings<Derived>::decimal(UNumberDecimalSeparatorDisplay style) const& { |
251 | 0 | Derived copy(*this); |
252 | 0 | copy.fMacros.decimal = style; |
253 | 0 | return copy; |
254 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::decimal(UNumberDecimalSeparatorDisplay) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::decimal(UNumberDecimalSeparatorDisplay) const & |
255 | | |
256 | | template<typename Derived> |
257 | 0 | Derived NumberFormatterSettings<Derived>::decimal(UNumberDecimalSeparatorDisplay style)&& { |
258 | 0 | Derived move(std::move(*this)); |
259 | 0 | move.fMacros.decimal = style; |
260 | 0 | return move; |
261 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::decimal(UNumberDecimalSeparatorDisplay) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::decimal(UNumberDecimalSeparatorDisplay) && |
262 | | |
263 | | template<typename Derived> |
264 | 0 | Derived NumberFormatterSettings<Derived>::scale(const Scale& scale) const& { |
265 | 0 | Derived copy(*this); |
266 | 0 | copy.fMacros.scale = scale; |
267 | 0 | return copy; |
268 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::scale(icu_79::number::Scale const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::scale(icu_79::number::Scale const&) const & |
269 | | |
270 | | template<typename Derived> |
271 | 0 | Derived NumberFormatterSettings<Derived>::scale(const Scale& scale)&& { |
272 | 0 | Derived move(std::move(*this)); |
273 | 0 | move.fMacros.scale = scale; |
274 | 0 | return move; |
275 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::scale(icu_79::number::Scale const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::scale(icu_79::number::Scale const&) && |
276 | | |
277 | | template<typename Derived> |
278 | 0 | Derived NumberFormatterSettings<Derived>::usage(const StringPiece usage) const& { |
279 | 0 | Derived copy(*this); |
280 | 0 | copy.fMacros.usage.set(usage); |
281 | 0 | return copy; |
282 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::usage(icu_79::StringPiece) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::usage(icu_79::StringPiece) const & |
283 | | |
284 | | template<typename Derived> |
285 | 0 | Derived NumberFormatterSettings<Derived>::usage(const StringPiece usage)&& { |
286 | 0 | Derived move(std::move(*this)); |
287 | 0 | move.fMacros.usage.set(usage); |
288 | 0 | return move; |
289 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::usage(icu_79::StringPiece) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::usage(icu_79::StringPiece) && |
290 | | |
291 | | template <typename Derived> |
292 | 0 | Derived NumberFormatterSettings<Derived>::displayOptions(const DisplayOptions &displayOptions) const & { |
293 | 0 | Derived copy(*this); |
294 | | // `displayCase` does not recognise the `undefined` |
295 | 0 | if (displayOptions.getGrammaticalCase() == UDISPOPT_GRAMMATICAL_CASE_UNDEFINED) { |
296 | 0 | copy.fMacros.unitDisplayCase.set(nullptr); |
297 | 0 | return copy; |
298 | 0 | } |
299 | | |
300 | 0 | copy.fMacros.unitDisplayCase.set( |
301 | 0 | udispopt_getGrammaticalCaseIdentifier(displayOptions.getGrammaticalCase())); |
302 | 0 | return copy; |
303 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::displayOptions(icu_79::DisplayOptions const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::displayOptions(icu_79::DisplayOptions const&) const & |
304 | | |
305 | | template <typename Derived> |
306 | 0 | Derived NumberFormatterSettings<Derived>::displayOptions(const DisplayOptions &displayOptions) && { |
307 | 0 | Derived move(std::move(*this)); |
308 | | // `displayCase` does not recognise the `undefined` |
309 | 0 | if (displayOptions.getGrammaticalCase() == UDISPOPT_GRAMMATICAL_CASE_UNDEFINED) { |
310 | 0 | move.fMacros.unitDisplayCase.set(nullptr); |
311 | 0 | return move; |
312 | 0 | } |
313 | | |
314 | 0 | move.fMacros.unitDisplayCase.set( |
315 | 0 | udispopt_getGrammaticalCaseIdentifier(displayOptions.getGrammaticalCase())); |
316 | 0 | return move; |
317 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::displayOptions(icu_79::DisplayOptions const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::displayOptions(icu_79::DisplayOptions const&) && |
318 | | |
319 | | template<typename Derived> |
320 | 0 | Derived NumberFormatterSettings<Derived>::unitDisplayCase(const StringPiece unitDisplayCase) const& { |
321 | 0 | Derived copy(*this); |
322 | 0 | copy.fMacros.unitDisplayCase.set(unitDisplayCase); |
323 | 0 | return copy; |
324 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unitDisplayCase(icu_79::StringPiece) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unitDisplayCase(icu_79::StringPiece) const & |
325 | | |
326 | | template<typename Derived> |
327 | 0 | Derived NumberFormatterSettings<Derived>::unitDisplayCase(const StringPiece unitDisplayCase)&& { |
328 | 0 | Derived move(std::move(*this)); |
329 | 0 | move.fMacros.unitDisplayCase.set(unitDisplayCase); |
330 | 0 | return move; |
331 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::unitDisplayCase(icu_79::StringPiece) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::unitDisplayCase(icu_79::StringPiece) && |
332 | | |
333 | | template<typename Derived> |
334 | 0 | Derived NumberFormatterSettings<Derived>::padding(const Padder& padder) const& { |
335 | 0 | Derived copy(*this); |
336 | 0 | copy.fMacros.padder = padder; |
337 | 0 | return copy; |
338 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::padding(icu_79::number::impl::Padder const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::padding(icu_79::number::impl::Padder const&) const & |
339 | | |
340 | | template<typename Derived> |
341 | 0 | Derived NumberFormatterSettings<Derived>::padding(const Padder& padder)&& { |
342 | 0 | Derived move(std::move(*this)); |
343 | 0 | move.fMacros.padder = padder; |
344 | 0 | return move; |
345 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::padding(icu_79::number::impl::Padder const&) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::padding(icu_79::number::impl::Padder const&) && |
346 | | |
347 | | template<typename Derived> |
348 | 0 | Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold) const& { |
349 | 0 | Derived copy(*this); |
350 | 0 | copy.fMacros.threshold = threshold; |
351 | 0 | return copy; |
352 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::threshold(int) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::threshold(int) const & |
353 | | |
354 | | template<typename Derived> |
355 | 0 | Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold)&& { |
356 | 0 | Derived move(std::move(*this)); |
357 | 0 | move.fMacros.threshold = threshold; |
358 | 0 | return move; |
359 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::threshold(int) && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::threshold(int) && |
360 | | |
361 | | template<typename Derived> |
362 | 0 | Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros) const& { |
363 | 0 | Derived copy(*this); |
364 | 0 | copy.fMacros = macros; |
365 | 0 | return copy; |
366 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps const&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps const&) const & |
367 | | |
368 | | template<typename Derived> |
369 | 3.71k | Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros)&& { |
370 | 3.71k | Derived move(std::move(*this)); |
371 | 3.71k | move.fMacros = macros; |
372 | 3.71k | return move; |
373 | 3.71k | } icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps const&) && Line | Count | Source | 369 | 3.71k | Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros)&& { | 370 | 3.71k | Derived move(std::move(*this)); | 371 | 3.71k | move.fMacros = macros; | 372 | 3.71k | return move; | 373 | 3.71k | } |
Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps const&) && |
374 | | |
375 | | template<typename Derived> |
376 | 0 | Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros) const& { |
377 | 0 | Derived copy(*this); |
378 | 0 | copy.fMacros = std::move(macros); |
379 | 0 | return copy; |
380 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps&&) const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps&&) const & |
381 | | |
382 | | template<typename Derived> |
383 | 633k | Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros)&& { |
384 | 633k | Derived move(std::move(*this)); |
385 | 633k | move.fMacros = std::move(macros); |
386 | 633k | return move; |
387 | 633k | } icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps&&) && Line | Count | Source | 383 | 633k | Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros)&& { | 384 | 633k | Derived move(std::move(*this)); | 385 | 633k | move.fMacros = std::move(macros); | 386 | 633k | return move; | 387 | 633k | } |
Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::macros(icu_79::number::impl::MacroProps&&) && |
388 | | |
389 | | // Note: toSkeleton defined in number_skeletons.cpp |
390 | | |
391 | | template<typename Derived> |
392 | 0 | LocalPointer<Derived> NumberFormatterSettings<Derived>::clone() const & { |
393 | 0 | return LocalPointer<Derived>(new Derived(*this)); |
394 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::clone() const & Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::clone() const & |
395 | | |
396 | | template<typename Derived> |
397 | 0 | LocalPointer<Derived> NumberFormatterSettings<Derived>::clone() && { |
398 | 0 | return LocalPointer<Derived>(new Derived(std::move(*this))); |
399 | 0 | } Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::UnlocalizedNumberFormatter>::clone() && Unexecuted instantiation: icu_79::number::NumberFormatterSettings<icu_79::number::LocalizedNumberFormatter>::clone() && |
400 | | |
401 | | // Declare all classes that implement NumberFormatterSettings |
402 | | // See https://stackoverflow.com/a/495056/1407170 |
403 | | template |
404 | | class icu::number::NumberFormatterSettings<icu::number::UnlocalizedNumberFormatter>; |
405 | | template |
406 | | class icu::number::NumberFormatterSettings<icu::number::LocalizedNumberFormatter>; |
407 | | |
408 | | |
409 | 637k | UnlocalizedNumberFormatter NumberFormatter::with() { |
410 | 637k | UnlocalizedNumberFormatter result; |
411 | 637k | return result; |
412 | 637k | } |
413 | | |
414 | 0 | LocalizedNumberFormatter NumberFormatter::withLocale(const Locale& locale) { |
415 | 0 | return with().locale(locale); |
416 | 0 | } |
417 | | |
418 | | // Note: forSkeleton defined in number_skeletons.cpp |
419 | | |
420 | | |
421 | | template<typename T> using NFS = NumberFormatterSettings<T>; |
422 | | using LNF = LocalizedNumberFormatter; |
423 | | using UNF = UnlocalizedNumberFormatter; |
424 | | |
425 | | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const UNF& other) |
426 | 0 | : UNF(static_cast<const NFS<UNF>&>(other)) {} |
427 | | |
428 | | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const NFS<UNF>& other) |
429 | 0 | : NFS<UNF>(other) { |
430 | | // No additional fields to assign |
431 | 0 | } |
432 | | |
433 | 0 | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const impl::MacroProps ¯os) { |
434 | 0 | fMacros = macros; |
435 | 0 | } |
436 | | |
437 | 0 | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(impl::MacroProps &¯os) { |
438 | 0 | fMacros = macros; |
439 | 0 | } |
440 | | |
441 | | // Make default copy constructor call the NumberFormatterSettings copy constructor. |
442 | | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(UNF&& src) noexcept |
443 | 0 | : UNF(static_cast<NFS<UNF>&&>(src)) {} |
444 | | |
445 | | UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(NFS<UNF>&& src) noexcept |
446 | 637k | : NFS<UNF>(std::move(src)) { |
447 | | // No additional fields to assign |
448 | 637k | } |
449 | | |
450 | 0 | UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(const UNF& other) { |
451 | 0 | NFS<UNF>::operator=(static_cast<const NFS<UNF>&>(other)); |
452 | | // No additional fields to assign |
453 | 0 | return *this; |
454 | 0 | } |
455 | | |
456 | 0 | UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(UNF&& src) noexcept { |
457 | 0 | NFS<UNF>::operator=(static_cast<NFS<UNF>&&>(src)); |
458 | | // No additional fields to assign |
459 | 0 | return *this; |
460 | 0 | } |
461 | | |
462 | | // Make default copy constructor call the NumberFormatterSettings copy constructor. |
463 | | LocalizedNumberFormatter::LocalizedNumberFormatter(const LNF& other) |
464 | 0 | : LNF(static_cast<const NFS<LNF>&>(other)) {} |
465 | | |
466 | | LocalizedNumberFormatter::LocalizedNumberFormatter(const NFS<LNF>& other) |
467 | 0 | : NFS<LNF>(other) { |
468 | 0 | UErrorCode localStatus = U_ZERO_ERROR; // Can't bubble up the error |
469 | 0 | lnfCopyHelper(static_cast<const LNF&>(other), localStatus); |
470 | 0 | } |
471 | | |
472 | | LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& src) noexcept |
473 | 0 | : LNF(static_cast<NFS<LNF>&&>(src)) {} |
474 | | |
475 | | LocalizedNumberFormatter::LocalizedNumberFormatter(NFS<LNF>&& src) noexcept |
476 | 0 | : NFS<LNF>(std::move(src)) { |
477 | 0 | lnfMoveHelper(std::move(static_cast<LNF&&>(src))); |
478 | 0 | } |
479 | | |
480 | 0 | LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other) { |
481 | 0 | if (this == &other) { return *this; } // self-assignment: no-op |
482 | 0 | NFS<LNF>::operator=(static_cast<const NFS<LNF>&>(other)); |
483 | 0 | UErrorCode localStatus = U_ZERO_ERROR; // Can't bubble up the error |
484 | 0 | lnfCopyHelper(other, localStatus); |
485 | 0 | return *this; |
486 | 0 | } |
487 | | |
488 | 633k | LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(LNF&& src) noexcept { |
489 | 633k | NFS<LNF>::operator=(static_cast<NFS<LNF>&&>(src)); |
490 | 633k | lnfMoveHelper(std::move(src)); |
491 | 633k | return *this; |
492 | 633k | } |
493 | | |
494 | 633k | void LocalizedNumberFormatter::resetCompiled() { |
495 | 633k | auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount); |
496 | 633k | umtx_storeRelease(*callCount, 0); |
497 | 633k | fCompiled = nullptr; |
498 | 633k | } |
499 | | |
500 | 633k | void LocalizedNumberFormatter::lnfMoveHelper(LNF&& src) { |
501 | | // Copy over the compiled formatter and set call count to INT32_MIN as in computeCompiled(). |
502 | | // Don't copy the call count directly because doing so requires a loadAcquire/storeRelease. |
503 | | // The bits themselves appear to be platform-dependent, so copying them might not be safe. |
504 | 633k | delete fCompiled; |
505 | 633k | if (src.fCompiled != nullptr) { |
506 | 0 | auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount); |
507 | 0 | umtx_storeRelease(*callCount, INT32_MIN); |
508 | 0 | fCompiled = src.fCompiled; |
509 | | // Reset the source object to leave it in a safe state. |
510 | 0 | src.resetCompiled(); |
511 | 633k | } else { |
512 | 633k | resetCompiled(); |
513 | 633k | } |
514 | | |
515 | | // Unconditionally move the warehouse |
516 | 633k | delete fWarehouse; |
517 | 633k | fWarehouse = src.fWarehouse; |
518 | 633k | src.fWarehouse = nullptr; |
519 | 633k | } |
520 | | |
521 | 0 | void LocalizedNumberFormatter::lnfCopyHelper(const LNF&, UErrorCode& status) { |
522 | | // When copying, always reset the compiled formatter. |
523 | 0 | delete fCompiled; |
524 | 0 | resetCompiled(); |
525 | | |
526 | | // If MacroProps has a reference to AffixPatternProvider, we need to copy it. |
527 | | // If MacroProps has a reference to PluralRules, copy that one, too. |
528 | 0 | delete fWarehouse; |
529 | 0 | if (fMacros.affixProvider || fMacros.rules) { |
530 | 0 | LocalPointer<DecimalFormatWarehouse> warehouse(new DecimalFormatWarehouse(), status); |
531 | 0 | if (U_FAILURE(status)) { |
532 | 0 | fWarehouse = nullptr; |
533 | 0 | return; |
534 | 0 | } |
535 | 0 | if (fMacros.affixProvider) { |
536 | 0 | warehouse->affixProvider.setTo(fMacros.affixProvider, status); |
537 | 0 | fMacros.affixProvider = &warehouse->affixProvider.get(); |
538 | 0 | } |
539 | 0 | if (fMacros.rules) { |
540 | 0 | warehouse->rules.adoptInsteadAndCheckErrorCode( |
541 | 0 | new PluralRules(*fMacros.rules), status); |
542 | 0 | fMacros.rules = warehouse->rules.getAlias(); |
543 | 0 | } |
544 | 0 | fWarehouse = warehouse.orphan(); |
545 | 0 | } else { |
546 | 0 | fWarehouse = nullptr; |
547 | 0 | } |
548 | 0 | } |
549 | | |
550 | | |
551 | 1.11M | LocalizedNumberFormatter::~LocalizedNumberFormatter() { |
552 | 1.11M | delete fCompiled; |
553 | 1.11M | delete fWarehouse; |
554 | 1.11M | } |
555 | | |
556 | 4.65k | LocalizedNumberFormatter::LocalizedNumberFormatter(const MacroProps& macros, const Locale& locale) { |
557 | 4.65k | fMacros = macros; |
558 | 4.65k | fMacros.locale = locale; |
559 | 4.65k | } |
560 | | |
561 | 633k | LocalizedNumberFormatter::LocalizedNumberFormatter(MacroProps&& macros, const Locale& locale) { |
562 | 633k | fMacros = std::move(macros); |
563 | 633k | fMacros.locale = locale; |
564 | 633k | } |
565 | | |
566 | 4.65k | LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale) const& { |
567 | 4.65k | return LocalizedNumberFormatter(fMacros, locale); |
568 | 4.65k | } |
569 | | |
570 | 633k | LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale)&& { |
571 | 633k | return LocalizedNumberFormatter(std::move(fMacros), locale); |
572 | 633k | } |
573 | | |
574 | 4.65k | FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& status) const { |
575 | 4.65k | if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } |
576 | 4.65k | auto* results = new UFormattedNumberData(); |
577 | 4.65k | if (results == nullptr) { |
578 | 0 | status = U_MEMORY_ALLOCATION_ERROR; |
579 | 0 | return FormattedNumber(status); |
580 | 0 | } |
581 | 4.65k | results->quantity.setToLong(value); |
582 | 4.65k | formatImpl(results, status); |
583 | | |
584 | | // Do not save the results object if we encountered a failure. |
585 | 4.65k | if (U_SUCCESS(status)) { |
586 | 4.52k | return FormattedNumber(results); |
587 | 4.52k | } else { |
588 | 121 | delete results; |
589 | 121 | return FormattedNumber(status); |
590 | 121 | } |
591 | 4.65k | } |
592 | | |
593 | 4.65k | FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode& status) const { |
594 | 4.65k | if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } |
595 | 4.65k | auto* results = new UFormattedNumberData(); |
596 | 4.65k | if (results == nullptr) { |
597 | 0 | status = U_MEMORY_ALLOCATION_ERROR; |
598 | 0 | return FormattedNumber(status); |
599 | 0 | } |
600 | 4.65k | results->quantity.setToDouble(value); |
601 | 4.65k | formatImpl(results, status); |
602 | | |
603 | | // Do not save the results object if we encountered a failure. |
604 | 4.65k | if (U_SUCCESS(status)) { |
605 | 4.52k | return FormattedNumber(results); |
606 | 4.52k | } else { |
607 | 121 | delete results; |
608 | 121 | return FormattedNumber(status); |
609 | 121 | } |
610 | 4.65k | } |
611 | | |
612 | 0 | FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErrorCode& status) const { |
613 | 0 | if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } |
614 | 0 | auto* results = new UFormattedNumberData(); |
615 | 0 | if (results == nullptr) { |
616 | 0 | status = U_MEMORY_ALLOCATION_ERROR; |
617 | 0 | return FormattedNumber(status); |
618 | 0 | } |
619 | 0 | results->quantity.setToDecNumber(value, status); |
620 | 0 | formatImpl(results, status); |
621 | | |
622 | | // Do not save the results object if we encountered a failure. |
623 | 0 | if (U_SUCCESS(status)) { |
624 | 0 | return FormattedNumber(results); |
625 | 0 | } else { |
626 | 0 | delete results; |
627 | 0 | return FormattedNumber(status); |
628 | 0 | } |
629 | 0 | } |
630 | | |
631 | | FormattedNumber |
632 | 0 | LocalizedNumberFormatter::formatDecimalQuantity(const DecimalQuantity& dq, UErrorCode& status) const { |
633 | 0 | if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } |
634 | 0 | auto* results = new UFormattedNumberData(); |
635 | 0 | if (results == nullptr) { |
636 | 0 | status = U_MEMORY_ALLOCATION_ERROR; |
637 | 0 | return FormattedNumber(status); |
638 | 0 | } |
639 | 0 | results->quantity = dq; |
640 | 0 | formatImpl(results, status); |
641 | | |
642 | | // Do not save the results object if we encountered a failure. |
643 | 0 | if (U_SUCCESS(status)) { |
644 | 0 | return FormattedNumber(results); |
645 | 0 | } else { |
646 | 0 | delete results; |
647 | 0 | return FormattedNumber(status); |
648 | 0 | } |
649 | 0 | } |
650 | | |
651 | 2.05M | void LocalizedNumberFormatter::formatImpl(impl::UFormattedNumberData* results, UErrorCode& status) const { |
652 | 2.05M | if (computeCompiled(status)) { |
653 | 2.03M | fCompiled->format(results, status); |
654 | 2.03M | } else { |
655 | 11.0k | NumberFormatterImpl::formatStatic(fMacros, results, status); |
656 | 11.0k | } |
657 | 2.05M | if (U_FAILURE(status)) { |
658 | 242 | return; |
659 | 242 | } |
660 | 2.05M | results->getStringRef().writeTerminator(status); |
661 | 2.05M | } |
662 | | |
663 | | void LocalizedNumberFormatter::getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, |
664 | 0 | UErrorCode& status) const { |
665 | 0 | FormattedStringBuilder string; |
666 | 0 | auto signum = static_cast<Signum>(isNegative ? SIGNUM_NEG : SIGNUM_POS); |
667 | | // Always return affixes for plural form OTHER. |
668 | 0 | static const StandardPlural::Form plural = StandardPlural::OTHER; |
669 | 0 | int32_t prefixLength; |
670 | 0 | if (computeCompiled(status)) { |
671 | 0 | prefixLength = fCompiled->getPrefixSuffix(signum, plural, string, status); |
672 | 0 | } else { |
673 | 0 | prefixLength = NumberFormatterImpl::getPrefixSuffixStatic(fMacros, signum, plural, string, status); |
674 | 0 | } |
675 | 0 | result.remove(); |
676 | 0 | if (isPrefix) { |
677 | 0 | result.append(string.toTempUnicodeString().tempSubStringBetween(0, prefixLength)); |
678 | 0 | } else { |
679 | 0 | result.append(string.toTempUnicodeString().tempSubStringBetween(prefixLength, string.length())); |
680 | 0 | } |
681 | 0 | } |
682 | | |
683 | 2.05M | bool LocalizedNumberFormatter::computeCompiled(UErrorCode& status) const { |
684 | | // fUnsafeCallCount contains memory to be interpreted as an atomic int, most commonly |
685 | | // std::atomic<int32_t>. Since the type of atomic int is platform-dependent, we cast the |
686 | | // bytes in fUnsafeCallCount to u_atomic_int32_t, a typedef for the platform-dependent |
687 | | // atomic int type defined in umutex.h. |
688 | 2.05M | static_assert( |
689 | 2.05M | sizeof(u_atomic_int32_t) <= sizeof(fUnsafeCallCount), |
690 | 2.05M | "Atomic integer size on this platform exceeds the size allocated by fUnsafeCallCount"); |
691 | 2.05M | auto* callCount = reinterpret_cast<u_atomic_int32_t*>( |
692 | 2.05M | const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount); |
693 | | |
694 | | // A positive value in the atomic int indicates that the data structure is not yet ready; |
695 | | // a negative value indicates that it is ready. If, after the increment, the atomic int |
696 | | // is exactly threshold, then it is the current thread's job to build the data structure. |
697 | | // Note: We set the callCount to INT32_MIN so that if another thread proceeds to increment |
698 | | // the atomic int, the value remains below zero. |
699 | 2.05M | int32_t currentCount = umtx_loadAcquire(*callCount); |
700 | 2.05M | if (0 <= currentCount && currentCount <= fMacros.threshold && fMacros.threshold > 0) { |
701 | 11.5k | currentCount = umtx_atomic_inc(callCount); |
702 | 11.5k | } |
703 | | |
704 | 2.05M | if (currentCount == fMacros.threshold && fMacros.threshold > 0) { |
705 | | // Build the data structure and then use it (slow to fast path). |
706 | 565 | const NumberFormatterImpl* compiled = new NumberFormatterImpl(fMacros, status); |
707 | 565 | if (compiled == nullptr) { |
708 | 0 | status = U_MEMORY_ALLOCATION_ERROR; |
709 | 0 | return false; |
710 | 0 | } |
711 | 565 | U_ASSERT(fCompiled == nullptr); |
712 | 565 | const_cast<LocalizedNumberFormatter*>(this)->fCompiled = compiled; |
713 | 565 | umtx_storeRelease(*callCount, INT32_MIN); |
714 | 565 | return true; |
715 | 2.04M | } else if (currentCount < 0) { |
716 | | // The data structure is already built; use it (fast path). |
717 | 2.03M | U_ASSERT(fCompiled != nullptr); |
718 | 2.03M | return true; |
719 | 2.03M | } else { |
720 | | // Format the number without building the data structure (slow path). |
721 | 11.0k | return false; |
722 | 11.0k | } |
723 | 2.05M | } |
724 | | |
725 | 0 | const impl::NumberFormatterImpl* LocalizedNumberFormatter::getCompiled() const { |
726 | 0 | return fCompiled; |
727 | 0 | } |
728 | | |
729 | 0 | int32_t LocalizedNumberFormatter::getCallCount() const { |
730 | 0 | auto* callCount = reinterpret_cast<u_atomic_int32_t*>( |
731 | 0 | const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount); |
732 | 0 | return umtx_loadAcquire(*callCount); |
733 | 0 | } |
734 | | |
735 | | // Note: toFormat defined in number_asformat.cpp |
736 | | |
737 | 0 | UnlocalizedNumberFormatter LocalizedNumberFormatter::withoutLocale() const & { |
738 | 0 | MacroProps macros(fMacros); |
739 | 0 | macros.locale = Locale(); |
740 | 0 | return UnlocalizedNumberFormatter(macros); |
741 | 0 | } |
742 | | |
743 | 0 | UnlocalizedNumberFormatter LocalizedNumberFormatter::withoutLocale() && { |
744 | 0 | MacroProps macros(std::move(fMacros)); |
745 | 0 | macros.locale = Locale(); |
746 | 0 | return UnlocalizedNumberFormatter(std::move(macros)); |
747 | 0 | } |
748 | | |
749 | 1.09M | const DecimalFormatSymbols* LocalizedNumberFormatter::getDecimalFormatSymbols() const { |
750 | 1.09M | return fMacros.symbols.getDecimalFormatSymbols(); |
751 | 1.09M | } |
752 | | |
753 | | #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER) |
754 | | // Warning 4661. |
755 | | #pragma warning(pop) |
756 | | #endif |
757 | | |
758 | | #endif /* #if !UCONFIG_NO_FORMATTING */ |