]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/number_compact.h
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / number_compact.h
1 // © 2017 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 __NUMBER_COMPACT_H__
8 #define __NUMBER_COMPACT_H__
9
10 #include "standardplural.h"
11 #include "number_types.h"
12 #include "unicode/unum.h"
13 #include "uvector.h"
14 #include "resource.h"
15 #include "number_patternmodifier.h"
16
17 U_NAMESPACE_BEGIN namespace number {
18 namespace impl {
19
20 static const int32_t COMPACT_MAX_DIGITS = 15;
21
22 class CompactData : public MultiplierProducer {
23 public:
24 CompactData();
25
26 void populate(const Locale &locale, const char *nsName, CompactStyle compactStyle,
27 CompactType compactType, UErrorCode &status);
28
29 int32_t getMultiplier(int32_t magnitude) const U_OVERRIDE;
30
31 const UChar *getPattern(int32_t magnitude, StandardPlural::Form plural) const;
32
33 void getUniquePatterns(UVector &output, UErrorCode &status) const;
34
35 private:
36 const UChar *patterns[(COMPACT_MAX_DIGITS + 1) * StandardPlural::COUNT];
37 int8_t multipliers[COMPACT_MAX_DIGITS + 1];
38 int8_t largestMagnitude;
39 UBool isEmpty;
40
41 class CompactDataSink : public ResourceSink {
42 public:
43 explicit CompactDataSink(CompactData &data) : data(data) {}
44
45 void put(const char *key, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) U_OVERRIDE;
46
47 private:
48 CompactData &data;
49 };
50 };
51
52 struct CompactModInfo {
53 const ImmutablePatternModifier *mod;
54 const UChar* patternString;
55 };
56
57 class CompactHandler : public MicroPropsGenerator, public UMemory {
58 public:
59 CompactHandler(CompactStyle compactStyle, const Locale &locale, const char *nsName,
60 CompactType compactType, const PluralRules *rules,
61 MutablePatternModifier *buildReference, const MicroPropsGenerator *parent,
62 UErrorCode &status);
63
64 ~CompactHandler() U_OVERRIDE;
65
66 void
67 processQuantity(DecimalQuantity &quantity, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
68
69 private:
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;
75 CompactData data;
76 ParsedPatternInfo unsafePatternInfo;
77 UBool safe;
78
79 /** Used by the safe code path */
80 void precomputeAllModifiers(MutablePatternModifier &buildReference, UErrorCode &status);
81 };
82
83
84 } // namespace impl
85 } // namespace number
86 U_NAMESPACE_END
87
88 #endif //__NUMBER_COMPACT_H__
89
90 #endif /* #if !UCONFIG_NO_FORMATTING */