1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __SOURCE_NUMRANGE_TYPES_H__
8 #define __SOURCE_NUMRANGE_TYPES_H__
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 "number_stringbuilder.h"
17 #include "formattedval_impl.h"
19 U_NAMESPACE_BEGIN
namespace number
{
24 * Class similar to UFormattedNumberData.
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.
29 * Possible magic number: 0x46445200
30 * Reads in ASCII as "FDR" (FormatteDnumberRange with room at the end)
32 class UFormattedNumberRangeData
: public FormattedValueNumberStringBuilderImpl
{
34 UFormattedNumberRangeData() : FormattedValueNumberStringBuilderImpl(0) {}
35 virtual ~UFormattedNumberRangeData();
37 DecimalQuantity quantity1
;
38 DecimalQuantity quantity2
;
39 UNumberRangeIdentityResult identityResult
= UNUM_IDENTITY_RESULT_COUNT
;
43 class StandardPluralRanges
: public UMemory
{
45 void initialize(const Locale
& locale
, UErrorCode
& status
);
46 StandardPlural::Form
resolve(StandardPlural::Form first
, StandardPlural::Form second
) const;
48 /** Used for data loading. */
50 StandardPlural::Form first
,
51 StandardPlural::Form second
,
52 StandardPlural::Form result
);
54 /** Used for data loading. */
55 void setCapacity(int32_t length
);
58 struct StandardPluralRangeTriple
{
59 StandardPlural::Form first
;
60 StandardPlural::Form second
;
61 StandardPlural::Form result
;
64 // TODO: An array is simple here, but it results in linear lookup time.
65 // Certain locales have 20-30 entries in this list.
66 // Consider changing to a smarter data structure.
67 typedef MaybeStackArray
<StandardPluralRangeTriple
, 3> PluralRangeTriples
;
68 PluralRangeTriples fTriples
;
69 int32_t fTriplesLen
= 0;
73 class NumberRangeFormatterImpl
: public UMemory
{
75 NumberRangeFormatterImpl(const RangeMacroProps
& macros
, UErrorCode
& status
);
77 void format(UFormattedNumberRangeData
& data
, bool equalBeforeRounding
, UErrorCode
& status
) const;
80 NumberFormatterImpl formatterImpl1
;
81 NumberFormatterImpl formatterImpl2
;
84 UNumberRangeCollapse fCollapse
;
85 UNumberRangeIdentityFallback fIdentityFallback
;
87 SimpleFormatter fRangeFormatter
;
88 SimpleModifier fApproximatelyModifier
;
90 StandardPluralRanges fPluralRanges
;
92 void formatSingleValue(UFormattedNumberRangeData
& data
,
93 MicroProps
& micros1
, MicroProps
& micros2
,
94 UErrorCode
& status
) const;
96 void formatApproximately(UFormattedNumberRangeData
& data
,
97 MicroProps
& micros1
, MicroProps
& micros2
,
98 UErrorCode
& status
) const;
100 void formatRange(UFormattedNumberRangeData
& data
,
101 MicroProps
& micros1
, MicroProps
& micros2
,
102 UErrorCode
& status
) const;
104 const Modifier
& resolveModifierPlurals(const Modifier
& first
, const Modifier
& second
) const;
109 } // namespace number
112 #endif //__SOURCE_NUMRANGE_TYPES_H__
113 #endif /* #if !UCONFIG_NO_FORMATTING */