1 // © 2018 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 #ifndef __SOURCE_NUMBER_MULTIPLIER_H__ 8 #define __SOURCE_NUMBER_MULTIPLIER_H__ 9 10 #include "numparse_types.h" 11 #include "number_decimfmtprops.h" 12 13 U_NAMESPACE_BEGIN namespace number { 14 namespace impl { 15 16 17 /** 18 * Wraps a {@link Multiplier} for use in the number formatting pipeline. 19 */ 20 // Exported as U_I18N_API for tests 21 class U_I18N_API MultiplierFormatHandler : public MicroPropsGenerator, public UMemory { 22 public: 23 MultiplierFormatHandler() = default; // WARNING: Leaves object in an unusable state; call setAndChain() 24 25 void setAndChain(const Scale& multiplier, const MicroPropsGenerator* parent); 26 27 void processQuantity(DecimalQuantity& quantity, MicroProps& micros, 28 UErrorCode& status) const U_OVERRIDE; 29 30 private: 31 Scale fMultiplier; 32 const MicroPropsGenerator *fParent; 33 }; 34 35 36 /** Gets a Scale from a DecimalFormatProperties. In Java, defined in RoundingUtils.java */ scaleFromProperties(const DecimalFormatProperties & properties)37static inline Scale scaleFromProperties(const DecimalFormatProperties& properties) { 38 int32_t magnitudeMultiplier = properties.magnitudeMultiplier + properties.multiplierScale; 39 int32_t arbitraryMultiplier = properties.multiplier; 40 if (magnitudeMultiplier != 0 && arbitraryMultiplier != 1) { 41 return Scale::byDoubleAndPowerOfTen(arbitraryMultiplier, magnitudeMultiplier); 42 } else if (magnitudeMultiplier != 0) { 43 return Scale::powerOfTen(magnitudeMultiplier); 44 } else if (arbitraryMultiplier != 1) { 45 return Scale::byDouble(arbitraryMultiplier); 46 } else { 47 return Scale::none(); 48 } 49 } 50 51 52 } // namespace impl 53 } // namespace number 54 U_NAMESPACE_END 55 56 #endif //__SOURCE_NUMBER_MULTIPLIER_H__ 57 #endif /* #if !UCONFIG_NO_FORMATTING */ 58