]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ******************************************************************************* | |
2ca993e8 | 5 | * Copyright (C) 1997-2015, International Business Machines |
73c04bcf | 6 | * Corporation and others. All Rights Reserved. |
b75a7d8f A |
7 | ******************************************************************************* |
8 | */ | |
9 | ||
10 | #ifndef NFRULE_H | |
11 | #define NFRULE_H | |
12 | ||
13 | #include "unicode/rbnf.h" | |
14 | ||
15 | #if U_HAVE_RBNF | |
16 | ||
17 | #include "unicode/utypes.h" | |
18 | #include "unicode/uobject.h" | |
19 | #include "unicode/unistr.h" | |
20 | ||
21 | U_NAMESPACE_BEGIN | |
22 | ||
23 | class FieldPosition; | |
24 | class Formattable; | |
25 | class NFRuleList; | |
26 | class NFRuleSet; | |
27 | class NFSubstitution; | |
28 | class ParsePosition; | |
b331163b | 29 | class PluralFormat; |
b75a7d8f A |
30 | class RuleBasedNumberFormat; |
31 | class UnicodeString; | |
32 | ||
33 | class NFRule : public UMemory { | |
34 | public: | |
35 | ||
36 | enum ERuleType { | |
37 | kNoBase = 0, | |
38 | kNegativeNumberRule = -1, | |
39 | kImproperFractionRule = -2, | |
40 | kProperFractionRule = -3, | |
41 | kMasterRule = -4, | |
2ca993e8 A |
42 | kInfinityRule = -5, |
43 | kNaNRule = -6, | |
44 | kOtherRule = -7 | |
b75a7d8f A |
45 | }; |
46 | ||
47 | static void makeRules(UnicodeString& definition, | |
2ca993e8 | 48 | NFRuleSet* ruleSet, |
b75a7d8f A |
49 | const NFRule* predecessor, |
50 | const RuleBasedNumberFormat* rbnf, | |
51 | NFRuleList& ruleList, | |
52 | UErrorCode& status); | |
53 | ||
2ca993e8 | 54 | NFRule(const RuleBasedNumberFormat* rbnf, const UnicodeString &ruleText, UErrorCode &status); |
b75a7d8f A |
55 | ~NFRule(); |
56 | ||
57 | UBool operator==(const NFRule& rhs) const; | |
58 | UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); } | |
59 | ||
60 | ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); } | |
61 | void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; } | |
62 | ||
63 | int64_t getBaseValue() const { return baseValue; } | |
374ca955 | 64 | void setBaseValue(int64_t value, UErrorCode& status); |
b75a7d8f | 65 | |
2ca993e8 A |
66 | UChar getDecimalPoint() const { return decimalPoint; } |
67 | ||
f3c0d7a5 | 68 | int64_t getDivisor() const; |
b75a7d8f | 69 | |
2ca993e8 A |
70 | void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; |
71 | void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; | |
b75a7d8f A |
72 | |
73 | UBool doParse(const UnicodeString& text, | |
74 | ParsePosition& pos, | |
75 | UBool isFractional, | |
76 | double upperBound, | |
0f5d89e8 | 77 | uint32_t nonNumericalExecutedRuleMask, |
729e4ab9 A |
78 | Formattable& result, |
79 | UBool isDecimFmtParseable=TRUE) const; | |
b75a7d8f | 80 | |
f3c0d7a5 | 81 | UBool shouldRollBack(int64_t number) const; |
b75a7d8f | 82 | |
73c04bcf | 83 | void _appendRuleText(UnicodeString& result) const; |
b75a7d8f | 84 | |
b331163b A |
85 | int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key, |
86 | int32_t startingAt, int32_t* resultCount) const; | |
87 | ||
2ca993e8 A |
88 | void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status); |
89 | ||
b75a7d8f A |
90 | private: |
91 | void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status); | |
b331163b A |
92 | void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &ruleText, const NFRule* predecessor, UErrorCode& status); |
93 | NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, UErrorCode& status); | |
b75a7d8f A |
94 | |
95 | int16_t expectedExponent() const; | |
2ca993e8 | 96 | int32_t indexOfAnyRulePrefix() const; |
b75a7d8f A |
97 | double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue, |
98 | const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub, | |
0f5d89e8 | 99 | uint32_t nonNumericalExecutedRuleMask, |
b75a7d8f A |
100 | double upperBound) const; |
101 | void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const; | |
102 | ||
46f4442e A |
103 | int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const; |
104 | UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const; | |
b75a7d8f A |
105 | int32_t findText(const UnicodeString& str, const UnicodeString& key, |
106 | int32_t startingAt, int32_t* resultCount) const; | |
107 | ||
108 | private: | |
109 | int64_t baseValue; | |
374ca955 | 110 | int32_t radix; |
b75a7d8f | 111 | int16_t exponent; |
2ca993e8 | 112 | UChar decimalPoint; |
b75a7d8f A |
113 | UnicodeString ruleText; |
114 | NFSubstitution* sub1; | |
115 | NFSubstitution* sub2; | |
116 | const RuleBasedNumberFormat* formatter; | |
b331163b | 117 | const PluralFormat* rulePatternFormat; |
b75a7d8f A |
118 | |
119 | NFRule(const NFRule &other); // forbid copying of this class | |
120 | NFRule &operator=(const NFRule &other); // forbid copying of this class | |
121 | }; | |
122 | ||
123 | U_NAMESPACE_END | |
124 | ||
125 | /* U_HAVE_RBNF */ | |
126 | #endif | |
127 | ||
128 | // NFRULE_H | |
129 | #endif | |
130 |