OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 1997-2014, International Business Machines | 3 * Copyright (C) 1997-2015, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 | 7 |
8 #ifndef NFRULE_H | 8 #ifndef NFRULE_H |
9 #define NFRULE_H | 9 #define NFRULE_H |
10 | 10 |
11 #include "unicode/rbnf.h" | 11 #include "unicode/rbnf.h" |
12 | 12 |
13 #if U_HAVE_RBNF | 13 #if U_HAVE_RBNF |
(...skipping 17 matching lines...) Expand all Loading... |
31 | 31 |
32 class NFRule : public UMemory { | 32 class NFRule : public UMemory { |
33 public: | 33 public: |
34 | 34 |
35 enum ERuleType { | 35 enum ERuleType { |
36 kNoBase = 0, | 36 kNoBase = 0, |
37 kNegativeNumberRule = -1, | 37 kNegativeNumberRule = -1, |
38 kImproperFractionRule = -2, | 38 kImproperFractionRule = -2, |
39 kProperFractionRule = -3, | 39 kProperFractionRule = -3, |
40 kMasterRule = -4, | 40 kMasterRule = -4, |
41 kOtherRule = -5 | 41 kInfinityRule = -5, |
| 42 kNaNRule = -6, |
| 43 kOtherRule = -7 |
42 }; | 44 }; |
43 | 45 |
44 static void makeRules(UnicodeString& definition, | 46 static void makeRules(UnicodeString& definition, |
45 const NFRuleSet* ruleSet, | 47 NFRuleSet* ruleSet, |
46 const NFRule* predecessor, | 48 const NFRule* predecessor, |
47 const RuleBasedNumberFormat* rbnf, | 49 const RuleBasedNumberFormat* rbnf, |
48 NFRuleList& ruleList, | 50 NFRuleList& ruleList, |
49 UErrorCode& status); | 51 UErrorCode& status); |
50 | 52 |
51 NFRule(const RuleBasedNumberFormat* rbnf); | 53 NFRule(const RuleBasedNumberFormat* rbnf, const UnicodeString &ruleText, UEr
rorCode &status); |
52 ~NFRule(); | 54 ~NFRule(); |
53 | 55 |
54 UBool operator==(const NFRule& rhs) const; | 56 UBool operator==(const NFRule& rhs) const; |
55 UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); } | 57 UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); } |
56 | 58 |
57 ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERule
Type)baseValue : kOtherRule); } | 59 ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERule
Type)baseValue : kOtherRule); } |
58 void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; } | 60 void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; } |
59 | 61 |
60 int64_t getBaseValue() const { return baseValue; } | 62 int64_t getBaseValue() const { return baseValue; } |
61 void setBaseValue(int64_t value, UErrorCode& status); | 63 void setBaseValue(int64_t value, UErrorCode& status); |
62 | 64 |
| 65 UChar getDecimalPoint() const { return decimalPoint; } |
| 66 |
63 double getDivisor() const { return uprv_pow(radix, exponent); } | 67 double getDivisor() const { return uprv_pow(radix, exponent); } |
64 | 68 |
65 void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, UError
Code& status) const; | 69 void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_
t recursionCount, UErrorCode& status) const; |
66 void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, UError
Code& status) const; | 70 void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, int32_
t recursionCount, UErrorCode& status) const; |
67 | 71 |
68 UBool doParse(const UnicodeString& text, | 72 UBool doParse(const UnicodeString& text, |
69 ParsePosition& pos, | 73 ParsePosition& pos, |
70 UBool isFractional, | 74 UBool isFractional, |
71 double upperBound, | 75 double upperBound, |
72 Formattable& result) const; | 76 Formattable& result) const; |
73 | 77 |
74 UBool shouldRollBack(double number) const; | 78 UBool shouldRollBack(double number) const; |
75 | 79 |
76 void _appendRuleText(UnicodeString& result) const; | 80 void _appendRuleText(UnicodeString& result) const; |
77 | 81 |
78 int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key, | 82 int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key, |
79 int32_t startingAt, int32_t* resultCount) const; | 83 int32_t startingAt, int32_t* resultCount) const; |
80 | 84 |
| 85 void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorC
ode& status); |
| 86 |
81 private: | 87 private: |
82 void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status); | 88 void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status); |
83 void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &rul
eText, const NFRule* predecessor, UErrorCode& status); | 89 void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &rul
eText, const NFRule* predecessor, UErrorCode& status); |
84 NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule*
predecessor, UErrorCode& status); | 90 NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule*
predecessor, UErrorCode& status); |
85 | 91 |
86 int16_t expectedExponent() const; | 92 int16_t expectedExponent() const; |
87 int32_t indexOfAny(const UChar* const strings[]) const; | 93 int32_t indexOfAnyRulePrefix() const; |
88 double matchToDelimiter(const UnicodeString& text, int32_t startPos, double
baseValue, | 94 double matchToDelimiter(const UnicodeString& text, int32_t startPos, double
baseValue, |
89 const UnicodeString& delimiter, ParsePosition& pp, c
onst NFSubstitution* sub, | 95 const UnicodeString& delimiter, ParsePosition& pp, c
onst NFSubstitution* sub, |
90 double upperBound) const; | 96 double upperBound) const; |
91 void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosi
tion& pp) const; | 97 void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosi
tion& pp) const; |
92 | 98 |
93 int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix,
UErrorCode& status) const; | 99 int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix,
UErrorCode& status) const; |
94 UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const; | 100 UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const; |
95 int32_t findText(const UnicodeString& str, const UnicodeString& key, | 101 int32_t findText(const UnicodeString& str, const UnicodeString& key, |
96 int32_t startingAt, int32_t* resultCount) const; | 102 int32_t startingAt, int32_t* resultCount) const; |
97 | 103 |
98 private: | 104 private: |
99 int64_t baseValue; | 105 int64_t baseValue; |
100 int32_t radix; | 106 int32_t radix; |
101 int16_t exponent; | 107 int16_t exponent; |
| 108 UChar decimalPoint; |
102 UnicodeString ruleText; | 109 UnicodeString ruleText; |
103 NFSubstitution* sub1; | 110 NFSubstitution* sub1; |
104 NFSubstitution* sub2; | 111 NFSubstitution* sub2; |
105 const RuleBasedNumberFormat* formatter; | 112 const RuleBasedNumberFormat* formatter; |
106 const PluralFormat* rulePatternFormat; | 113 const PluralFormat* rulePatternFormat; |
107 | 114 |
108 NFRule(const NFRule &other); // forbid copying of this class | 115 NFRule(const NFRule &other); // forbid copying of this class |
109 NFRule &operator=(const NFRule &other); // forbid copying of this class | 116 NFRule &operator=(const NFRule &other); // forbid copying of this class |
110 }; | 117 }; |
111 | 118 |
112 U_NAMESPACE_END | 119 U_NAMESPACE_END |
113 | 120 |
114 /* U_HAVE_RBNF */ | 121 /* U_HAVE_RBNF */ |
115 #endif | 122 #endif |
116 | 123 |
117 // NFRULE_H | 124 // NFRULE_H |
118 #endif | 125 #endif |
119 | 126 |
OLD | NEW |