2018-03-15 10:08:26 +00:00
|
|
|
// © 2018 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2018-03-15 10:08:26 +00:00
|
|
|
#ifndef __SOURCE_NUMBER_MULTIPLIER_H__
|
|
|
|
#define __SOURCE_NUMBER_MULTIPLIER_H__
|
|
|
|
|
|
|
|
#include "numparse_types.h"
|
2018-04-03 04:38:16 +00:00
|
|
|
#include "number_decimfmtprops.h"
|
2018-03-15 10:08:26 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN namespace number {
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
|
2018-04-03 04:38:16 +00:00
|
|
|
/**
|
|
|
|
* Wraps a {@link Multiplier} for use in the number formatting pipeline.
|
|
|
|
*/
|
2018-04-25 00:39:22 +00:00
|
|
|
// Exported as U_I18N_API for tests
|
|
|
|
class U_I18N_API MultiplierFormatHandler : public MicroPropsGenerator, public UMemory {
|
2018-03-15 10:08:26 +00:00
|
|
|
public:
|
2018-05-25 03:01:38 +00:00
|
|
|
MultiplierFormatHandler() = default; // WARNING: Leaves object in an unusable state; call setAndChain()
|
|
|
|
|
2018-04-14 09:45:39 +00:00
|
|
|
void setAndChain(const Scale& multiplier, const MicroPropsGenerator* parent);
|
2018-03-15 10:08:26 +00:00
|
|
|
|
|
|
|
void processQuantity(DecimalQuantity& quantity, MicroProps& micros,
|
|
|
|
UErrorCode& status) const U_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
2018-08-11 01:05:58 +00:00
|
|
|
Scale fMultiplier;
|
|
|
|
const MicroPropsGenerator *fParent;
|
2018-03-15 10:08:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-14 09:45:39 +00:00
|
|
|
/** Gets a Scale from a DecimalFormatProperties. In Java, defined in RoundingUtils.java */
|
|
|
|
static inline Scale scaleFromProperties(const DecimalFormatProperties& properties) {
|
2018-04-18 23:55:55 +00:00
|
|
|
int32_t magnitudeMultiplier = properties.magnitudeMultiplier + properties.multiplierScale;
|
2018-04-14 09:45:39 +00:00
|
|
|
int32_t arbitraryMultiplier = properties.multiplier;
|
|
|
|
if (magnitudeMultiplier != 0 && arbitraryMultiplier != 1) {
|
|
|
|
return Scale::byDoubleAndPowerOfTen(arbitraryMultiplier, magnitudeMultiplier);
|
|
|
|
} else if (magnitudeMultiplier != 0) {
|
|
|
|
return Scale::powerOfTen(magnitudeMultiplier);
|
|
|
|
} else if (arbitraryMultiplier != 1) {
|
|
|
|
return Scale::byDouble(arbitraryMultiplier);
|
2018-04-03 04:38:16 +00:00
|
|
|
} else {
|
2018-04-14 09:45:39 +00:00
|
|
|
return Scale::none();
|
2018-04-03 04:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-15 10:08:26 +00:00
|
|
|
} // namespace impl
|
|
|
|
} // namespace number
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif //__SOURCE_NUMBER_MULTIPLIER_H__
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|