1 // © 2017 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 __NUMBER_COMPACT_H__
8 #define __NUMBER_COMPACT_H__
10 #include "standardplural.h"
11 #include "number_types.h"
12 #include "unicode/unum.h"
15 #include "number_patternmodifier.h"
17 U_NAMESPACE_BEGIN
namespace number
{
20 static const int32_t COMPACT_MAX_DIGITS
= 15;
22 class CompactData
: public MultiplierProducer
{
26 void populate(const Locale
&locale
, const char *nsName
, CompactStyle compactStyle
,
27 CompactType compactType
, UErrorCode
&status
);
29 int32_t getMultiplier(int32_t magnitude
) const U_OVERRIDE
;
31 const UChar
*getPattern(int32_t magnitude
, StandardPlural::Form plural
) const;
33 void getUniquePatterns(UVector
&output
, UErrorCode
&status
) const;
36 const UChar
*patterns
[(COMPACT_MAX_DIGITS
+ 1) * StandardPlural::COUNT
];
37 int8_t multipliers
[COMPACT_MAX_DIGITS
+ 1];
38 int8_t largestMagnitude
;
41 class CompactDataSink
: public ResourceSink
{
43 explicit CompactDataSink(CompactData
&data
) : data(data
) {}
45 void put(const char *key
, ResourceValue
&value
, UBool
/*noFallback*/, UErrorCode
&status
) U_OVERRIDE
;
52 struct CompactModInfo
{
53 const ImmutablePatternModifier
*mod
;
54 const UChar
* patternString
;
57 class CompactHandler
: public MicroPropsGenerator
, public UMemory
{
59 CompactHandler(CompactStyle compactStyle
, const Locale
&locale
, const char *nsName
,
60 CompactType compactType
, const PluralRules
*rules
,
61 MutablePatternModifier
*buildReference
, const MicroPropsGenerator
*parent
,
64 ~CompactHandler() U_OVERRIDE
;
67 processQuantity(DecimalQuantity
&quantity
, MicroProps
µs
, UErrorCode
&status
) const U_OVERRIDE
;
70 const PluralRules
*rules
;
71 const MicroPropsGenerator
*parent
;
72 // Initial capacity of 12 for 0K, 00K, 000K, ...M, ...B, and ...T
73 MaybeStackArray
<CompactModInfo
, 12> precomputedMods
;
74 int32_t precomputedModsLength
= 0;
76 ParsedPatternInfo unsafePatternInfo
;
79 /** Used by the safe code path */
80 void precomputeAllModifiers(MutablePatternModifier
&buildReference
, UErrorCode
&status
);
88 #endif //__NUMBER_COMPACT_H__
90 #endif /* #if !UCONFIG_NO_FORMATTING */