2017-09-27 00:25:20 +00:00
|
|
|
// © 2017 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
2017-10-04 22:51:06 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2017-09-27 05:31:57 +00:00
|
|
|
|
|
|
|
#include "uassert.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
#include "unicode/numberformatter.h"
|
|
|
|
#include "number_decimalquantity.h"
|
|
|
|
#include "number_formatimpl.h"
|
2017-10-04 01:15:54 +00:00
|
|
|
#include "umutex.h"
|
2018-03-24 05:46:28 +00:00
|
|
|
#include "number_skeletons.h"
|
2018-03-27 01:58:26 +00:00
|
|
|
#include "number_utypes.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
2017-09-27 21:43:09 +00:00
|
|
|
using namespace icu;
|
2017-09-27 00:25:20 +00:00
|
|
|
using namespace icu::number;
|
|
|
|
using namespace icu::number::impl;
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::notation(const Notation& notation) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// NOTE: Slicing is OK.
|
|
|
|
copy.fMacros.notation = notation;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::notation(const Notation& notation)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
// NOTE: Slicing is OK.
|
|
|
|
move.fMacros.notation = notation;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit.
|
|
|
|
// TimeUnit may be affected, but TimeUnit is not as relevant to number formatting.
|
|
|
|
copy.fMacros.unit = unit;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
// See comments above about slicing.
|
|
|
|
move.fMacros.unit = unit;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
2018-03-17 07:24:02 +00:00
|
|
|
// Just move the unit into the MacroProps by value, and delete it since we have ownership.
|
2017-09-27 00:25:20 +00:00
|
|
|
// NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit.
|
|
|
|
// TimeUnit may be affected, but TimeUnit is not as relevant to number formatting.
|
|
|
|
if (unit != nullptr) {
|
2018-03-14 10:41:27 +00:00
|
|
|
// TODO: On nullptr, reset to default value?
|
2018-03-17 07:24:02 +00:00
|
|
|
copy.fMacros.unit = std::move(*unit);
|
|
|
|
delete unit;
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
// See comments above about slicing and ownership.
|
|
|
|
if (unit != nullptr) {
|
|
|
|
// TODO: On nullptr, reset to default value?
|
|
|
|
move.fMacros.unit = std::move(*unit);
|
2017-09-27 00:25:20 +00:00
|
|
|
delete unit;
|
|
|
|
}
|
2018-03-17 07:24:02 +00:00
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit) const& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// See comments above about slicing.
|
|
|
|
copy.fMacros.perUnit = perUnit;
|
2017-09-27 00:25:20 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2017-12-22 00:02:01 +00:00
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit)&& {
|
2017-12-22 00:02:01 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// See comments above about slicing.
|
|
|
|
copy.fMacros.perUnit = perUnit;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit) const& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
// See comments above about slicing and ownership.
|
|
|
|
if (perUnit != nullptr) {
|
|
|
|
// TODO: On nullptr, reset to default value?
|
|
|
|
move.fMacros.perUnit = std::move(*perUnit);
|
|
|
|
delete perUnit;
|
|
|
|
}
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit)&& {
|
2017-12-22 00:02:01 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// See comments above about slicing and ownership.
|
|
|
|
if (perUnit != nullptr) {
|
2018-03-14 10:41:27 +00:00
|
|
|
// TODO: On nullptr, reset to default value?
|
2018-03-17 07:24:02 +00:00
|
|
|
copy.fMacros.perUnit = std::move(*perUnit);
|
2017-12-22 00:02:01 +00:00
|
|
|
delete perUnit;
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::rounding(const Rounder& rounder) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
// NOTE: Slicing is OK.
|
|
|
|
copy.fMacros.rounder = rounder;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::rounding(const Rounder& rounder)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
// NOTE: Slicing is OK.
|
|
|
|
move.fMacros.rounder = rounder;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::grouping(const UGroupingStrategy& strategy) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
2018-02-06 03:08:17 +00:00
|
|
|
// NOTE: This is slightly different than how the setting is stored in Java
|
|
|
|
// because we want to put it on the stack.
|
|
|
|
copy.fMacros.grouper = Grouper::forStrategy(strategy);
|
2017-09-27 00:25:20 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::grouping(const UGroupingStrategy& strategy)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.grouper = Grouper::forStrategy(strategy);
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.integerWidth = style;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.integerWidth = style;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.symbols.setTo(symbols);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.symbols.setTo(symbols);
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.symbols.setTo(ns);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.symbols.setTo(ns);
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::unitWidth(const UNumberUnitWidth& width) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.unitWidth = width;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::unitWidth(const UNumberUnitWidth& width)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.unitWidth = width;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::sign(const UNumberSignDisplay& style) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.sign = style;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::sign(const UNumberSignDisplay& style)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.sign = style;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::decimal(const UNumberDecimalSeparatorDisplay& style) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.decimal = style;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::decimal(const UNumberDecimalSeparatorDisplay& style)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.decimal = style;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
2018-04-03 04:38:16 +00:00
|
|
|
template<typename Derived>
|
2018-04-14 09:45:39 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::scale(const Scale& scale) const& {
|
2018-04-03 04:38:16 +00:00
|
|
|
Derived copy(*this);
|
2018-04-14 09:45:39 +00:00
|
|
|
copy.fMacros.scale = scale;
|
2018-04-03 04:38:16 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-04-14 09:45:39 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::scale(const Scale& scale)&& {
|
2018-04-03 04:38:16 +00:00
|
|
|
Derived move(std::move(*this));
|
2018-04-14 09:45:39 +00:00
|
|
|
move.fMacros.scale = scale;
|
2018-04-03 04:38:16 +00:00
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::padding(const Padder& padder) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.padder = padder;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::padding(const Padder& padder)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.padder = padder;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros.threshold = threshold;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2018-03-13 09:25:41 +00:00
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros.threshold = threshold;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros) const& {
|
2018-03-13 09:25:41 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros = macros;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros = macros;
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros) const& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived copy(*this);
|
|
|
|
copy.fMacros = std::move(macros);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Derived>
|
2018-03-27 01:58:26 +00:00
|
|
|
Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
Derived move(std::move(*this));
|
|
|
|
move.fMacros = std::move(macros);
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
2018-03-24 05:46:28 +00:00
|
|
|
template<typename Derived>
|
|
|
|
UnicodeString NumberFormatterSettings<Derived>::toSkeleton(UErrorCode& status) const {
|
2018-04-05 21:54:04 +00:00
|
|
|
if (fMacros.copyErrorTo(status)) {
|
|
|
|
return {};
|
|
|
|
}
|
2018-03-24 05:46:28 +00:00
|
|
|
return skeleton::generate(fMacros, status);
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
// Declare all classes that implement NumberFormatterSettings
|
|
|
|
// See https://stackoverflow.com/a/495056/1407170
|
|
|
|
template
|
|
|
|
class icu::number::NumberFormatterSettings<icu::number::UnlocalizedNumberFormatter>;
|
|
|
|
template
|
|
|
|
class icu::number::NumberFormatterSettings<icu::number::LocalizedNumberFormatter>;
|
|
|
|
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter NumberFormatter::with() {
|
|
|
|
UnlocalizedNumberFormatter result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
LocalizedNumberFormatter NumberFormatter::withLocale(const Locale& locale) {
|
2017-09-27 00:25:20 +00:00
|
|
|
return with().locale(locale);
|
|
|
|
}
|
|
|
|
|
2018-03-24 05:46:28 +00:00
|
|
|
UnlocalizedNumberFormatter
|
|
|
|
NumberFormatter::fromSkeleton(const UnicodeString& skeleton, UErrorCode& status) {
|
|
|
|
return skeleton::create(skeleton, status);
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
|
2018-03-27 01:58:26 +00:00
|
|
|
template<typename T> using NFS = NumberFormatterSettings<T>;
|
2018-03-17 07:24:02 +00:00
|
|
|
using LNF = LocalizedNumberFormatter;
|
|
|
|
using UNF = UnlocalizedNumberFormatter;
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const UNF& other)
|
|
|
|
: UNF(static_cast<const NFS<UNF>&>(other)) {}
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const NFS<UNF>& other)
|
|
|
|
: NFS<UNF>(other) {
|
|
|
|
// No additional fields to assign
|
|
|
|
}
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(UNF&& src) U_NOEXCEPT
|
|
|
|
: UNF(static_cast<NFS<UNF>&&>(src)) {}
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(NFS<UNF>&& src) U_NOEXCEPT
|
|
|
|
: NFS<UNF>(std::move(src)) {
|
|
|
|
// No additional fields to assign
|
|
|
|
}
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(const UNF& other) {
|
|
|
|
NFS<UNF>::operator=(static_cast<const NFS<UNF>&>(other));
|
|
|
|
// No additional fields to assign
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(UNF&& src) U_NOEXCEPT {
|
|
|
|
NFS<UNF>::operator=(static_cast<NFS<UNF>&&>(src));
|
|
|
|
// No additional fields to assign
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(const LNF& other)
|
|
|
|
: LNF(static_cast<const NFS<LNF>&>(other)) {}
|
|
|
|
|
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(const NFS<LNF>& other)
|
|
|
|
: NFS<LNF>(other) {
|
|
|
|
// No additional fields to assign (let call count and compiled formatter reset to defaults)
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT
|
|
|
|
: LNF(static_cast<NFS<LNF>&&>(src)) {}
|
|
|
|
|
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(NFS<LNF>&& src) U_NOEXCEPT
|
|
|
|
: NFS<LNF>(std::move(src)) {
|
2018-04-26 03:38:17 +00:00
|
|
|
// For the move operators, copy over the compiled formatter.
|
|
|
|
// Note: if the formatter is not compiled, call count information is lost.
|
|
|
|
if (static_cast<LNF&&>(src).fCompiled != nullptr) {
|
|
|
|
lnfMoveHelper(static_cast<LNF&&>(src));
|
|
|
|
}
|
2018-03-17 07:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other) {
|
|
|
|
NFS<LNF>::operator=(static_cast<const NFS<LNF>&>(other));
|
|
|
|
// No additional fields to assign (let call count and compiled formatter reset to defaults)
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(LNF&& src) U_NOEXCEPT {
|
|
|
|
NFS<LNF>::operator=(static_cast<NFS<LNF>&&>(src));
|
2018-04-26 03:38:17 +00:00
|
|
|
// For the move operators, copy over the compiled formatter.
|
|
|
|
// Note: if the formatter is not compiled, call count information is lost.
|
|
|
|
if (static_cast<LNF&&>(src).fCompiled != nullptr) {
|
|
|
|
// Formatter is compiled
|
|
|
|
lnfMoveHelper(static_cast<LNF&&>(src));
|
|
|
|
} else {
|
|
|
|
// Reset to default values.
|
|
|
|
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
|
|
|
|
umtx_storeRelease(*callCount, 0);
|
|
|
|
fCompiled = nullptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalizedNumberFormatter::lnfMoveHelper(LNF&& src) {
|
|
|
|
// Copy over the compiled formatter and set call count to INT32_MIN as in computeCompiled().
|
|
|
|
// Don't copy the call count directly because doing so requires a loadAcquire/storeRelease.
|
|
|
|
// The bits themselves appear to be platform-dependent, so copying them might not be safe.
|
|
|
|
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
|
|
|
|
umtx_storeRelease(*callCount, INT32_MIN);
|
2018-03-17 07:24:02 +00:00
|
|
|
fCompiled = src.fCompiled;
|
|
|
|
// Reset the source object to leave it in a safe state.
|
2018-04-26 03:38:17 +00:00
|
|
|
auto* srcCallCount = reinterpret_cast<u_atomic_int32_t*>(src.fUnsafeCallCount);
|
|
|
|
umtx_storeRelease(*srcCallCount, 0);
|
2018-03-17 07:24:02 +00:00
|
|
|
src.fCompiled = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LocalizedNumberFormatter::~LocalizedNumberFormatter() {
|
|
|
|
delete fCompiled;
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(const MacroProps& macros, const Locale& locale) {
|
2017-09-27 00:25:20 +00:00
|
|
|
fMacros = macros;
|
|
|
|
fMacros.locale = locale;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
LocalizedNumberFormatter::LocalizedNumberFormatter(MacroProps&& macros, const Locale& locale) {
|
|
|
|
fMacros = std::move(macros);
|
|
|
|
fMacros.locale = locale;
|
|
|
|
}
|
|
|
|
|
2018-03-27 01:58:26 +00:00
|
|
|
LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale) const& {
|
2017-09-27 00:25:20 +00:00
|
|
|
return LocalizedNumberFormatter(fMacros, locale);
|
|
|
|
}
|
|
|
|
|
2018-03-27 01:58:26 +00:00
|
|
|
LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale)&& {
|
2018-03-17 07:24:02 +00:00
|
|
|
return LocalizedNumberFormatter(std::move(fMacros), locale);
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
SymbolsWrapper::SymbolsWrapper(const SymbolsWrapper& other) {
|
2017-09-27 00:25:20 +00:00
|
|
|
doCopyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
SymbolsWrapper::SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT {
|
|
|
|
doMoveFrom(std::move(src));
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
SymbolsWrapper& SymbolsWrapper::operator=(const SymbolsWrapper& other) {
|
2017-09-27 00:25:20 +00:00
|
|
|
if (this == &other) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
doCleanup();
|
|
|
|
doCopyFrom(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
SymbolsWrapper& SymbolsWrapper::operator=(SymbolsWrapper&& src) U_NOEXCEPT {
|
|
|
|
if (this == &src) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
doCleanup();
|
|
|
|
doMoveFrom(std::move(src));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
SymbolsWrapper::~SymbolsWrapper() {
|
|
|
|
doCleanup();
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void SymbolsWrapper::setTo(const DecimalFormatSymbols& dfs) {
|
2017-09-27 00:25:20 +00:00
|
|
|
doCleanup();
|
|
|
|
fType = SYMPTR_DFS;
|
|
|
|
fPtr.dfs = new DecimalFormatSymbols(dfs);
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void SymbolsWrapper::setTo(const NumberingSystem* ns) {
|
2017-09-27 00:25:20 +00:00
|
|
|
doCleanup();
|
|
|
|
fType = SYMPTR_NS;
|
|
|
|
fPtr.ns = ns;
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void SymbolsWrapper::doCopyFrom(const SymbolsWrapper& other) {
|
2017-09-27 00:25:20 +00:00
|
|
|
fType = other.fType;
|
|
|
|
switch (fType) {
|
|
|
|
case SYMPTR_NONE:
|
|
|
|
// No action necessary
|
|
|
|
break;
|
|
|
|
case SYMPTR_DFS:
|
|
|
|
// Memory allocation failures are exposed in copyErrorTo()
|
|
|
|
if (other.fPtr.dfs != nullptr) {
|
|
|
|
fPtr.dfs = new DecimalFormatSymbols(*other.fPtr.dfs);
|
|
|
|
} else {
|
|
|
|
fPtr.dfs = nullptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYMPTR_NS:
|
|
|
|
// Memory allocation failures are exposed in copyErrorTo()
|
|
|
|
if (other.fPtr.ns != nullptr) {
|
|
|
|
fPtr.ns = new NumberingSystem(*other.fPtr.ns);
|
|
|
|
} else {
|
|
|
|
fPtr.ns = nullptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
void SymbolsWrapper::doMoveFrom(SymbolsWrapper&& src) {
|
|
|
|
fType = src.fType;
|
|
|
|
switch (fType) {
|
|
|
|
case SYMPTR_NONE:
|
|
|
|
// No action necessary
|
|
|
|
break;
|
|
|
|
case SYMPTR_DFS:
|
|
|
|
fPtr.dfs = src.fPtr.dfs;
|
|
|
|
src.fPtr.dfs = nullptr;
|
|
|
|
break;
|
|
|
|
case SYMPTR_NS:
|
|
|
|
fPtr.ns = src.fPtr.ns;
|
|
|
|
src.fPtr.ns = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
void SymbolsWrapper::doCleanup() {
|
|
|
|
switch (fType) {
|
|
|
|
case SYMPTR_NONE:
|
|
|
|
// No action necessary
|
|
|
|
break;
|
|
|
|
case SYMPTR_DFS:
|
|
|
|
delete fPtr.dfs;
|
|
|
|
break;
|
|
|
|
case SYMPTR_NS:
|
|
|
|
delete fPtr.ns;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolsWrapper::isDecimalFormatSymbols() const {
|
|
|
|
return fType == SYMPTR_DFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolsWrapper::isNumberingSystem() const {
|
|
|
|
return fType == SYMPTR_NS;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DecimalFormatSymbols* SymbolsWrapper::getDecimalFormatSymbols() const {
|
|
|
|
U_ASSERT(fType == SYMPTR_DFS);
|
|
|
|
return fPtr.dfs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NumberingSystem* SymbolsWrapper::getNumberingSystem() const {
|
|
|
|
U_ASSERT(fType == SYMPTR_NS);
|
|
|
|
return fPtr.ns;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
|
|
|
|
FormattedNumber::FormattedNumber(FormattedNumber&& src) U_NOEXCEPT
|
|
|
|
: fResults(src.fResults), fErrorCode(src.fErrorCode) {
|
|
|
|
// Disown src.fResults to prevent double-deletion
|
|
|
|
src.fResults = nullptr;
|
|
|
|
src.fErrorCode = U_INVALID_STATE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FormattedNumber& FormattedNumber::operator=(FormattedNumber&& src) U_NOEXCEPT {
|
|
|
|
delete fResults;
|
|
|
|
fResults = src.fResults;
|
|
|
|
fErrorCode = src.fErrorCode;
|
|
|
|
// Disown src.fResults to prevent double-deletion
|
|
|
|
src.fResults = nullptr;
|
|
|
|
src.fErrorCode = U_INVALID_STATE_ERROR;
|
|
|
|
return *this;
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& status) const {
|
2017-10-25 01:26:48 +00:00
|
|
|
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
|
2018-03-27 01:58:26 +00:00
|
|
|
auto results = new UFormattedNumberData();
|
2017-09-27 00:25:20 +00:00
|
|
|
if (results == nullptr) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2017-10-25 01:26:48 +00:00
|
|
|
return FormattedNumber(status);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
results->quantity.setToLong(value);
|
2018-03-27 01:58:26 +00:00
|
|
|
formatImpl(results, status);
|
|
|
|
|
|
|
|
// Do not save the results object if we encountered a failure.
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return FormattedNumber(results);
|
|
|
|
} else {
|
|
|
|
delete results;
|
|
|
|
return FormattedNumber(status);
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode& status) const {
|
2017-10-25 01:26:48 +00:00
|
|
|
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
|
2018-03-27 01:58:26 +00:00
|
|
|
auto results = new UFormattedNumberData();
|
2017-09-27 00:25:20 +00:00
|
|
|
if (results == nullptr) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2017-10-25 01:26:48 +00:00
|
|
|
return FormattedNumber(status);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
results->quantity.setToDouble(value);
|
2018-03-27 01:58:26 +00:00
|
|
|
formatImpl(results, status);
|
|
|
|
|
|
|
|
// Do not save the results object if we encountered a failure.
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return FormattedNumber(results);
|
|
|
|
} else {
|
|
|
|
delete results;
|
|
|
|
return FormattedNumber(status);
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErrorCode& status) const {
|
2017-10-25 01:26:48 +00:00
|
|
|
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
|
2018-03-27 01:58:26 +00:00
|
|
|
auto results = new UFormattedNumberData();
|
2017-09-27 00:25:20 +00:00
|
|
|
if (results == nullptr) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2017-10-25 01:26:48 +00:00
|
|
|
return FormattedNumber(status);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
2018-03-24 05:46:28 +00:00
|
|
|
results->quantity.setToDecNumber(value, status);
|
2018-03-27 01:58:26 +00:00
|
|
|
formatImpl(results, status);
|
|
|
|
|
|
|
|
// Do not save the results object if we encountered a failure.
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return FormattedNumber(results);
|
|
|
|
} else {
|
|
|
|
delete results;
|
|
|
|
return FormattedNumber(status);
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
FormattedNumber
|
|
|
|
LocalizedNumberFormatter::formatDecimalQuantity(const DecimalQuantity& dq, UErrorCode& status) const {
|
2018-03-13 10:11:36 +00:00
|
|
|
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
|
2018-03-27 01:58:26 +00:00
|
|
|
auto results = new UFormattedNumberData();
|
2018-03-13 10:11:36 +00:00
|
|
|
if (results == nullptr) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return FormattedNumber(status);
|
|
|
|
}
|
|
|
|
results->quantity = dq;
|
2018-03-27 01:58:26 +00:00
|
|
|
formatImpl(results, status);
|
|
|
|
|
|
|
|
// Do not save the results object if we encountered a failure.
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return FormattedNumber(results);
|
|
|
|
} else {
|
|
|
|
delete results;
|
|
|
|
return FormattedNumber(status);
|
|
|
|
}
|
2018-03-13 10:11:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 01:58:26 +00:00
|
|
|
void LocalizedNumberFormatter::formatImpl(impl::UFormattedNumberData* results, UErrorCode& status) const {
|
2018-04-21 08:01:19 +00:00
|
|
|
if (computeCompiled(status)) {
|
|
|
|
fCompiled->apply(results->quantity, results->string, status);
|
|
|
|
} else {
|
|
|
|
NumberFormatterImpl::applyStatic(fMacros, results->quantity, results->string, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalizedNumberFormatter::getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result,
|
|
|
|
UErrorCode& status) const {
|
|
|
|
NumberStringBuilder string;
|
|
|
|
auto signum = static_cast<int8_t>(isNegative ? -1 : 1);
|
|
|
|
// Always return affixes for plural form OTHER.
|
|
|
|
static const StandardPlural::Form plural = StandardPlural::OTHER;
|
|
|
|
int32_t prefixLength;
|
|
|
|
if (computeCompiled(status)) {
|
|
|
|
prefixLength = fCompiled->getPrefixSuffix(signum, plural, string, status);
|
|
|
|
} else {
|
|
|
|
prefixLength = NumberFormatterImpl::getPrefixSuffixStatic(fMacros, signum, plural, string, status);
|
|
|
|
}
|
|
|
|
result.remove();
|
|
|
|
if (isPrefix) {
|
|
|
|
result.append(string.toTempUnicodeString().tempSubStringBetween(0, prefixLength));
|
|
|
|
} else {
|
|
|
|
result.append(string.toTempUnicodeString().tempSubStringBetween(prefixLength, string.length()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalizedNumberFormatter::computeCompiled(UErrorCode& status) const {
|
2017-10-04 01:15:54 +00:00
|
|
|
// fUnsafeCallCount contains memory to be interpreted as an atomic int, most commonly
|
|
|
|
// std::atomic<int32_t>. Since the type of atomic int is platform-dependent, we cast the
|
|
|
|
// bytes in fUnsafeCallCount to u_atomic_int32_t, a typedef for the platform-dependent
|
|
|
|
// atomic int type defined in umutex.h.
|
2018-03-14 10:41:27 +00:00
|
|
|
static_assert(
|
|
|
|
sizeof(u_atomic_int32_t) <= sizeof(fUnsafeCallCount),
|
|
|
|
"Atomic integer size on this platform exceeds the size allocated by fUnsafeCallCount");
|
2018-03-17 07:24:02 +00:00
|
|
|
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(
|
2018-03-14 10:41:27 +00:00
|
|
|
const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount);
|
2017-10-04 01:15:54 +00:00
|
|
|
|
|
|
|
// A positive value in the atomic int indicates that the data structure is not yet ready;
|
|
|
|
// a negative value indicates that it is ready. If, after the increment, the atomic int
|
|
|
|
// is exactly threshold, then it is the current thread's job to build the data structure.
|
|
|
|
// Note: We set the callCount to INT32_MIN so that if another thread proceeds to increment
|
|
|
|
// the atomic int, the value remains below zero.
|
|
|
|
int32_t currentCount = umtx_loadAcquire(*callCount);
|
|
|
|
if (0 <= currentCount && currentCount <= fMacros.threshold && fMacros.threshold > 0) {
|
|
|
|
currentCount = umtx_atomic_inc(callCount);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
2017-10-04 01:15:54 +00:00
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
if (currentCount == fMacros.threshold && fMacros.threshold > 0) {
|
2017-10-04 01:15:54 +00:00
|
|
|
// Build the data structure and then use it (slow to fast path).
|
2018-03-14 10:41:27 +00:00
|
|
|
const NumberFormatterImpl* compiled = NumberFormatterImpl::fromMacros(fMacros, status);
|
2017-10-04 01:15:54 +00:00
|
|
|
U_ASSERT(fCompiled == nullptr);
|
2018-03-14 10:41:27 +00:00
|
|
|
const_cast<LocalizedNumberFormatter*>(this)->fCompiled = compiled;
|
2017-10-04 01:15:54 +00:00
|
|
|
umtx_storeRelease(*callCount, INT32_MIN);
|
2018-04-21 08:01:19 +00:00
|
|
|
return true;
|
2017-10-04 01:15:54 +00:00
|
|
|
} else if (currentCount < 0) {
|
|
|
|
// The data structure is already built; use it (fast path).
|
|
|
|
U_ASSERT(fCompiled != nullptr);
|
2018-04-21 08:01:19 +00:00
|
|
|
return true;
|
2017-09-27 00:25:20 +00:00
|
|
|
} else {
|
2017-10-04 01:15:54 +00:00
|
|
|
// Format the number without building the data structure (slow path).
|
2018-04-21 08:01:19 +00:00
|
|
|
return false;
|
2018-04-11 11:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
const impl::NumberFormatterImpl* LocalizedNumberFormatter::getCompiled() const {
|
|
|
|
return fCompiled;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t LocalizedNumberFormatter::getCallCount() const {
|
|
|
|
auto* callCount = reinterpret_cast<u_atomic_int32_t*>(
|
|
|
|
const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount);
|
|
|
|
return umtx_loadAcquire(*callCount);
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
UnicodeString FormattedNumber::toString() const {
|
2017-10-25 01:26:48 +00:00
|
|
|
if (fResults == nullptr) {
|
2018-04-30 21:07:35 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return fResults->string.toUnicodeString();
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString FormattedNumber::toString(UErrorCode& status) const {
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
if (fResults == nullptr) {
|
|
|
|
status = fErrorCode;
|
2017-10-25 01:26:48 +00:00
|
|
|
return {};
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
return fResults->string.toUnicodeString();
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
Appendable& FormattedNumber::appendTo(Appendable& appendable) {
|
2017-10-25 01:26:48 +00:00
|
|
|
if (fResults == nullptr) {
|
2018-04-30 21:07:35 +00:00
|
|
|
return appendable;
|
|
|
|
}
|
|
|
|
appendable.appendString(fResults->string.chars(), fResults->string.length());
|
|
|
|
return appendable;
|
|
|
|
}
|
|
|
|
|
|
|
|
Appendable& FormattedNumber::appendTo(Appendable& appendable, UErrorCode& status) {
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return appendable;
|
|
|
|
}
|
|
|
|
if (fResults == nullptr) {
|
|
|
|
status = fErrorCode;
|
2017-10-25 01:26:48 +00:00
|
|
|
return appendable;
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
appendable.appendString(fResults->string.chars(), fResults->string.length());
|
|
|
|
return appendable;
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void FormattedNumber::populateFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) {
|
2018-04-30 21:07:35 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-25 01:26:48 +00:00
|
|
|
if (fResults == nullptr) {
|
|
|
|
status = fErrorCode;
|
|
|
|
return;
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
fResults->string.populateFieldPosition(fieldPosition, 0, status);
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void FormattedNumber::populateFieldPositionIterator(FieldPositionIterator& iterator, UErrorCode& status) {
|
2018-04-30 21:07:35 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-25 01:26:48 +00:00
|
|
|
if (fResults == nullptr) {
|
|
|
|
status = fErrorCode;
|
|
|
|
return;
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
fResults->string.populateFieldPositionIterator(iterator, status);
|
|
|
|
}
|
|
|
|
|
2018-03-14 10:41:27 +00:00
|
|
|
void FormattedNumber::getDecimalQuantity(DecimalQuantity& output, UErrorCode& status) const {
|
2018-04-30 21:07:35 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 10:41:27 +00:00
|
|
|
if (fResults == nullptr) {
|
|
|
|
status = fErrorCode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
output = fResults->quantity;
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
FormattedNumber::~FormattedNumber() {
|
|
|
|
delete fResults;
|
|
|
|
}
|
2017-09-27 05:31:57 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|