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