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