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_NUMRANGE_TYPES_H__ 8 #define __SOURCE_NUMRANGE_TYPES_H__ 9 10 #include "unicode/numberformatter.h" 11 #include "unicode/numberrangeformatter.h" 12 #include "unicode/simpleformatter.h" 13 #include "number_types.h" 14 #include "number_decimalquantity.h" 15 #include "number_formatimpl.h" 16 #include "formatted_string_builder.h" 17 #include "formattedval_impl.h" 18 #include "pluralranges.h" 19 20 U_NAMESPACE_BEGIN 21 namespace number::impl { 22 23 /** 24 * Class similar to UFormattedNumberData. 25 * 26 * Has incomplete magic number logic that will need to be finished 27 * if this is to be exposed as C API in the future. 28 * 29 * Possible magic number: 0x46445200 30 * Reads in ASCII as "FDR" (FormatteDnumberRange with room at the end) 31 */ 32 class UFormattedNumberRangeData : public FormattedValueStringBuilderImpl { 33 public: UFormattedNumberRangeData()34 UFormattedNumberRangeData() : FormattedValueStringBuilderImpl(kUndefinedField) {} 35 virtual ~UFormattedNumberRangeData(); 36 37 DecimalQuantity quantity1; 38 DecimalQuantity quantity2; 39 UNumberRangeIdentityResult identityResult = UNUM_IDENTITY_RESULT_COUNT; 40 }; 41 42 43 class NumberRangeFormatterImpl : public UMemory { 44 public: 45 NumberRangeFormatterImpl(const RangeMacroProps& macros, UErrorCode& status); 46 47 void format(UFormattedNumberRangeData& data, bool equalBeforeRounding, UErrorCode& status) const; 48 49 private: 50 NumberFormatterImpl formatterImpl1; 51 NumberFormatterImpl formatterImpl2; 52 bool fSameFormatters; 53 54 UNumberRangeCollapse fCollapse; 55 UNumberRangeIdentityFallback fIdentityFallback; 56 57 SimpleFormatter fRangeFormatter; 58 NumberFormatterImpl fApproximatelyFormatter; 59 60 StandardPluralRanges fPluralRanges; 61 62 void formatSingleValue(UFormattedNumberRangeData& data, 63 MicroProps& micros1, MicroProps& micros2, 64 UErrorCode& status) const; 65 66 void formatApproximately(UFormattedNumberRangeData& data, 67 MicroProps& micros1, MicroProps& micros2, 68 UErrorCode& status) const; 69 70 void formatRange(UFormattedNumberRangeData& data, 71 MicroProps& micros1, MicroProps& micros2, 72 UErrorCode& status) const; 73 74 const Modifier& resolveModifierPlurals(const Modifier& first, const Modifier& second) const; 75 }; 76 77 78 /** Helper function used in upluralrules.cpp */ 79 const UFormattedNumberRangeData* validateUFormattedNumberRange( 80 const UFormattedNumberRange* uresult, UErrorCode& status); 81 82 } // namespace number::impl 83 U_NAMESPACE_END 84 85 #endif //__SOURCE_NUMRANGE_TYPES_H__ 86 #endif /* #if !UCONFIG_NO_FORMATTING */ 87