| 1 |
// © 2019 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 "unicode/measunit.h" |
| 9 |
#include "unicode/numberformatter.h" |
| 10 |
#include "number_utypes.h" |
| 11 |
#include "util.h" |
| 12 |
#include "number_decimalquantity.h" |
| 13 |
#include "number_decnum.h" |
| 14 |
#include "numrange_impl.h" |
| 15 |
|
| 16 |
U_NAMESPACE_BEGIN |
| 17 |
namespace number { |
| 18 |
|
| 19 |
|
| 20 |
UPRV_FORMATTED_VALUE_SUBCLASS_AUTO_IMPL(FormattedNumber) |
| 21 |
|
| 22 |
#define UPRV_NOARG |
| 23 |
|
| 24 |
void FormattedNumber::toDecimalNumber(ByteSink& sink, UErrorCode& status) const { |
| 25 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) |
| 26 |
impl::DecNum decnum; |
| 27 |
fData->quantity.toDecNum(decnum, status); |
| 28 |
decnum.toString(sink, status); |
| 29 |
} |
| 30 |
|
| 31 |
void FormattedNumber::getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, |
| 32 |
UErrorCode& status) const { |
| 33 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) |
| 34 |
fData->getAllFieldPositions(fpih, status); |
| 35 |
} |
| 36 |
|
| 37 |
MeasureUnit FormattedNumber::getOutputUnit(UErrorCode& status) const { |
| 38 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(MeasureUnit()) |
| 39 |
return fData->outputUnit; |
| 40 |
} |
| 41 |
|
| 42 |
UDisplayOptionsNounClass FormattedNumber::getNounClass(UErrorCode &status) const { |
| 43 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UDISPOPT_NOUN_CLASS_UNDEFINED); |
| 44 |
const char *nounClass = fData->gender; |
| 45 |
return udispopt_fromNounClassIdentifier(nounClass); |
| 46 |
} |
| 47 |
|
| 48 |
void FormattedNumber::getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const { |
| 49 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) |
| 50 |
output = fData->quantity; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
impl::UFormattedNumberData::~UFormattedNumberData() = default; |
| 55 |
|
| 56 |
|
| 57 |
UPRV_FORMATTED_VALUE_SUBCLASS_AUTO_IMPL(FormattedNumberRange) |
| 58 |
|
| 59 |
#define UPRV_NOARG |
| 60 |
|
| 61 |
void FormattedNumberRange::getDecimalNumbers(ByteSink& sink1, ByteSink& sink2, UErrorCode& status) const { |
| 62 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) |
| 63 |
impl::DecNum decnum1; |
| 64 |
impl::DecNum decnum2; |
| 65 |
fData->quantity1.toDecNum(decnum1, status).toString(sink1, status); |
| 66 |
fData->quantity2.toDecNum(decnum2, status).toString(sink2, status); |
| 67 |
} |
| 68 |
|
| 69 |
UNumberRangeIdentityResult FormattedNumberRange::getIdentityResult(UErrorCode& status) const { |
| 70 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(UNUM_IDENTITY_RESULT_NOT_EQUAL) |
| 71 |
return fData->identityResult; |
| 72 |
} |
| 73 |
|
| 74 |
const impl::UFormattedNumberRangeData* FormattedNumberRange::getData(UErrorCode& status) const { |
| 75 |
UPRV_FORMATTED_VALUE_METHOD_GUARD(nullptr) |
| 76 |
return fData; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
impl::UFormattedNumberRangeData::~UFormattedNumberRangeData() = default; |
| 81 |
|
| 82 |
|
| 83 |
} // namespace number |
| 84 |
U_NAMESPACE_END |
| 85 |
|
| 86 |
#endif /* #if !UCONFIG_NO_FORMATTING */ |