tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

number_multiplier.h (1826B)


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