michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 1997-2008, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef NFRULE_H michael@0: #define NFRULE_H michael@0: michael@0: #include "unicode/rbnf.h" michael@0: michael@0: #if U_HAVE_RBNF michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/unistr.h" michael@0: #include "putilimp.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class FieldPosition; michael@0: class Formattable; michael@0: class NFRuleList; michael@0: class NFRuleSet; michael@0: class NFSubstitution; michael@0: class ParsePosition; michael@0: class RuleBasedNumberFormat; michael@0: class UnicodeString; michael@0: michael@0: class NFRule : public UMemory { michael@0: public: michael@0: michael@0: enum ERuleType { michael@0: kNoBase = 0, michael@0: kNegativeNumberRule = -1, michael@0: kImproperFractionRule = -2, michael@0: kProperFractionRule = -3, michael@0: kMasterRule = -4, michael@0: kOtherRule = -5 michael@0: }; michael@0: michael@0: static void makeRules(UnicodeString& definition, michael@0: const NFRuleSet* ruleSet, michael@0: const NFRule* predecessor, michael@0: const RuleBasedNumberFormat* rbnf, michael@0: NFRuleList& ruleList, michael@0: UErrorCode& status); michael@0: michael@0: NFRule(const RuleBasedNumberFormat* rbnf); michael@0: ~NFRule(); michael@0: michael@0: UBool operator==(const NFRule& rhs) const; michael@0: UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); } michael@0: michael@0: ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); } michael@0: void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; } michael@0: michael@0: int64_t getBaseValue() const { return baseValue; } michael@0: void setBaseValue(int64_t value, UErrorCode& status); michael@0: michael@0: double getDivisor() const { return uprv_pow(radix, exponent); } michael@0: michael@0: void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos) const; michael@0: void doFormat(double number, UnicodeString& toAppendTo, int32_t pos) const; michael@0: michael@0: UBool doParse(const UnicodeString& text, michael@0: ParsePosition& pos, michael@0: UBool isFractional, michael@0: double upperBound, michael@0: Formattable& result) const; michael@0: michael@0: UBool shouldRollBack(double number) const; michael@0: michael@0: void _appendRuleText(UnicodeString& result) const; michael@0: michael@0: private: michael@0: void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status); michael@0: void extractSubstitutions(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status); michael@0: NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status); michael@0: michael@0: int16_t expectedExponent() const; michael@0: int32_t indexOfAny(const UChar* const strings[]) const; michael@0: double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue, michael@0: const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub, michael@0: double upperBound) const; michael@0: void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const; michael@0: michael@0: int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const; michael@0: UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const; michael@0: int32_t findText(const UnicodeString& str, const UnicodeString& key, michael@0: int32_t startingAt, int32_t* resultCount) const; michael@0: michael@0: private: michael@0: int64_t baseValue; michael@0: int32_t radix; michael@0: int16_t exponent; michael@0: UnicodeString ruleText; michael@0: NFSubstitution* sub1; michael@0: NFSubstitution* sub2; michael@0: const RuleBasedNumberFormat* formatter; michael@0: michael@0: NFRule(const NFRule &other); // forbid copying of this class michael@0: NFRule &operator=(const NFRule &other); // forbid copying of this class michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: /* U_HAVE_RBNF */ michael@0: #endif michael@0: michael@0: // NFRULE_H michael@0: #endif michael@0: