numrange_impl.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // © 2018 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. #include "unicode/utypes.h"
  4. #if !UCONFIG_NO_FORMATTING
  5. #ifndef __SOURCE_NUMRANGE_TYPES_H__
  6. #define __SOURCE_NUMRANGE_TYPES_H__
  7. #include "unicode/numberformatter.h"
  8. #include "unicode/numberrangeformatter.h"
  9. #include "unicode/simpleformatter.h"
  10. #include "number_types.h"
  11. #include "number_decimalquantity.h"
  12. #include "number_formatimpl.h"
  13. #include "formatted_string_builder.h"
  14. #include "formattedval_impl.h"
  15. #include "pluralranges.h"
  16. U_NAMESPACE_BEGIN namespace number {
  17. namespace impl {
  18. /**
  19. * Class similar to UFormattedNumberData.
  20. *
  21. * Has incomplete magic number logic that will need to be finished
  22. * if this is to be exposed as C API in the future.
  23. *
  24. * Possible magic number: 0x46445200
  25. * Reads in ASCII as "FDR" (FormatteDnumberRange with room at the end)
  26. */
  27. class UFormattedNumberRangeData : public FormattedValueStringBuilderImpl {
  28. public:
  29. UFormattedNumberRangeData() : FormattedValueStringBuilderImpl(kUndefinedField) {}
  30. virtual ~UFormattedNumberRangeData();
  31. DecimalQuantity quantity1;
  32. DecimalQuantity quantity2;
  33. UNumberRangeIdentityResult identityResult = UNUM_IDENTITY_RESULT_COUNT;
  34. };
  35. class NumberRangeFormatterImpl : public UMemory {
  36. public:
  37. NumberRangeFormatterImpl(const RangeMacroProps& macros, UErrorCode& status);
  38. void format(UFormattedNumberRangeData& data, bool equalBeforeRounding, UErrorCode& status) const;
  39. private:
  40. NumberFormatterImpl formatterImpl1;
  41. NumberFormatterImpl formatterImpl2;
  42. bool fSameFormatters;
  43. UNumberRangeCollapse fCollapse;
  44. UNumberRangeIdentityFallback fIdentityFallback;
  45. SimpleFormatter fRangeFormatter;
  46. NumberFormatterImpl fApproximatelyFormatter;
  47. StandardPluralRanges fPluralRanges;
  48. void formatSingleValue(UFormattedNumberRangeData& data,
  49. MicroProps& micros1, MicroProps& micros2,
  50. UErrorCode& status) const;
  51. void formatApproximately(UFormattedNumberRangeData& data,
  52. MicroProps& micros1, MicroProps& micros2,
  53. UErrorCode& status) const;
  54. void formatRange(UFormattedNumberRangeData& data,
  55. MicroProps& micros1, MicroProps& micros2,
  56. UErrorCode& status) const;
  57. const Modifier& resolveModifierPlurals(const Modifier& first, const Modifier& second) const;
  58. };
  59. /** Helper function used in upluralrules.cpp */
  60. const UFormattedNumberRangeData* validateUFormattedNumberRange(
  61. const UFormattedNumberRange* uresult, UErrorCode& status);
  62. } // namespace impl
  63. } // namespace number
  64. U_NAMESPACE_END
  65. #endif //__SOURCE_NUMRANGE_TYPES_H__
  66. #endif /* #if !UCONFIG_NO_FORMATTING */