1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/nfrule.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 1997-2008, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +******************************************************************************* 1.9 +*/ 1.10 + 1.11 +#ifndef NFRULE_H 1.12 +#define NFRULE_H 1.13 + 1.14 +#include "unicode/rbnf.h" 1.15 + 1.16 +#if U_HAVE_RBNF 1.17 + 1.18 +#include "unicode/utypes.h" 1.19 +#include "unicode/uobject.h" 1.20 +#include "unicode/unistr.h" 1.21 +#include "putilimp.h" 1.22 + 1.23 +U_NAMESPACE_BEGIN 1.24 + 1.25 +class FieldPosition; 1.26 +class Formattable; 1.27 +class NFRuleList; 1.28 +class NFRuleSet; 1.29 +class NFSubstitution; 1.30 +class ParsePosition; 1.31 +class RuleBasedNumberFormat; 1.32 +class UnicodeString; 1.33 + 1.34 +class NFRule : public UMemory { 1.35 +public: 1.36 + 1.37 + enum ERuleType { 1.38 + kNoBase = 0, 1.39 + kNegativeNumberRule = -1, 1.40 + kImproperFractionRule = -2, 1.41 + kProperFractionRule = -3, 1.42 + kMasterRule = -4, 1.43 + kOtherRule = -5 1.44 + }; 1.45 + 1.46 + static void makeRules(UnicodeString& definition, 1.47 + const NFRuleSet* ruleSet, 1.48 + const NFRule* predecessor, 1.49 + const RuleBasedNumberFormat* rbnf, 1.50 + NFRuleList& ruleList, 1.51 + UErrorCode& status); 1.52 + 1.53 + NFRule(const RuleBasedNumberFormat* rbnf); 1.54 + ~NFRule(); 1.55 + 1.56 + UBool operator==(const NFRule& rhs) const; 1.57 + UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); } 1.58 + 1.59 + ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); } 1.60 + void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; } 1.61 + 1.62 + int64_t getBaseValue() const { return baseValue; } 1.63 + void setBaseValue(int64_t value, UErrorCode& status); 1.64 + 1.65 + double getDivisor() const { return uprv_pow(radix, exponent); } 1.66 + 1.67 + void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos) const; 1.68 + void doFormat(double number, UnicodeString& toAppendTo, int32_t pos) const; 1.69 + 1.70 + UBool doParse(const UnicodeString& text, 1.71 + ParsePosition& pos, 1.72 + UBool isFractional, 1.73 + double upperBound, 1.74 + Formattable& result) const; 1.75 + 1.76 + UBool shouldRollBack(double number) const; 1.77 + 1.78 + void _appendRuleText(UnicodeString& result) const; 1.79 + 1.80 +private: 1.81 + void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status); 1.82 + void extractSubstitutions(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status); 1.83 + NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status); 1.84 + 1.85 + int16_t expectedExponent() const; 1.86 + int32_t indexOfAny(const UChar* const strings[]) const; 1.87 + double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue, 1.88 + const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub, 1.89 + double upperBound) const; 1.90 + void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const; 1.91 + 1.92 + int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const; 1.93 + UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const; 1.94 + int32_t findText(const UnicodeString& str, const UnicodeString& key, 1.95 + int32_t startingAt, int32_t* resultCount) const; 1.96 + 1.97 +private: 1.98 + int64_t baseValue; 1.99 + int32_t radix; 1.100 + int16_t exponent; 1.101 + UnicodeString ruleText; 1.102 + NFSubstitution* sub1; 1.103 + NFSubstitution* sub2; 1.104 + const RuleBasedNumberFormat* formatter; 1.105 + 1.106 + NFRule(const NFRule &other); // forbid copying of this class 1.107 + NFRule &operator=(const NFRule &other); // forbid copying of this class 1.108 +}; 1.109 + 1.110 +U_NAMESPACE_END 1.111 + 1.112 +/* U_HAVE_RBNF */ 1.113 +#endif 1.114 + 1.115 +// NFRULE_H 1.116 +#endif 1.117 +