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