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