Coverage Report

Created: 2025-06-13 06:38

/src/icu/icu4c/source/i18n/numrange_impl.h
Line
Count
Source (jump to first uncovered line)
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:
34
0
    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
                             DecimalQuantity quantity,
68
                             MicroProps& micros1, MicroProps& micros2,
69
                             UErrorCode& status) const;
70
71
    void formatRange(UFormattedNumberRangeData& data,
72
                     MicroProps& micros1, MicroProps& micros2,
73
                     UErrorCode& status) const;
74
75
    const Modifier& resolveModifierPlurals(const Modifier& first, const Modifier& second) const;
76
};
77
78
79
/** Helper function used in upluralrules.cpp */
80
const UFormattedNumberRangeData* validateUFormattedNumberRange(
81
    const UFormattedNumberRange* uresult, UErrorCode& status);
82
83
} // namespace number::impl
84
U_NAMESPACE_END
85
86
#endif //__SOURCE_NUMRANGE_TYPES_H__
87
#endif /* #if !UCONFIG_NO_FORMATTING */