2 *******************************************************************************
3 * Copyright (C) 1997-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
11 #include "unicode/rbnf.h"
15 #include "unicode/utypes.h"
16 #include "unicode/uobject.h"
17 #include "unicode/unistr.h"
29 class RuleBasedNumberFormat
;
32 class NFRule
: public UMemory
{
37 kNegativeNumberRule
= -1,
38 kImproperFractionRule
= -2,
39 kProperFractionRule
= -3,
44 static void makeRules(UnicodeString
& definition
,
45 const NFRuleSet
* ruleSet
,
46 const NFRule
* predecessor
,
47 const RuleBasedNumberFormat
* rbnf
,
51 NFRule(const RuleBasedNumberFormat
* rbnf
);
54 UBool
operator==(const NFRule
& rhs
) const;
55 UBool
operator!=(const NFRule
& rhs
) const { return !operator==(rhs
); }
57 ERuleType
getType() const { return (ERuleType
)(baseValue
<= kNoBase
? (ERuleType
)baseValue
: kOtherRule
); }
58 void setType(ERuleType ruleType
) { baseValue
= (int32_t)ruleType
; }
60 int64_t getBaseValue() const { return baseValue
; }
61 void setBaseValue(int64_t value
, UErrorCode
& status
);
63 double getDivisor() const { return uprv_pow(radix
, exponent
); }
65 void doFormat(int64_t number
, UnicodeString
& toAppendTo
, int32_t pos
, UErrorCode
& status
) const;
66 void doFormat(double number
, UnicodeString
& toAppendTo
, int32_t pos
, UErrorCode
& status
) const;
68 UBool
doParse(const UnicodeString
& text
,
73 UBool isDecimFmtParseable
=TRUE
) const;
75 UBool
shouldRollBack(double number
) const;
77 void _appendRuleText(UnicodeString
& result
) const;
79 int32_t findTextLenient(const UnicodeString
& str
, const UnicodeString
& key
,
80 int32_t startingAt
, int32_t* resultCount
) const;
83 void parseRuleDescriptor(UnicodeString
& descriptor
, UErrorCode
& status
);
84 void extractSubstitutions(const NFRuleSet
* ruleSet
, const UnicodeString
&ruleText
, const NFRule
* predecessor
, UErrorCode
& status
);
85 NFSubstitution
* extractSubstitution(const NFRuleSet
* ruleSet
, const NFRule
* predecessor
, UErrorCode
& status
);
87 int16_t expectedExponent() const;
88 int32_t indexOfAny(const UChar
* const strings
[]) const;
89 double matchToDelimiter(const UnicodeString
& text
, int32_t startPos
, double baseValue
,
90 const UnicodeString
& delimiter
, ParsePosition
& pp
, const NFSubstitution
* sub
,
91 double upperBound
) const;
92 void stripPrefix(UnicodeString
& text
, const UnicodeString
& prefix
, ParsePosition
& pp
) const;
94 int32_t prefixLength(const UnicodeString
& str
, const UnicodeString
& prefix
, UErrorCode
& status
) const;
95 UBool
allIgnorable(const UnicodeString
& str
, UErrorCode
& status
) const;
96 int32_t findText(const UnicodeString
& str
, const UnicodeString
& key
,
97 int32_t startingAt
, int32_t* resultCount
) const;
103 UnicodeString ruleText
;
104 NFSubstitution
* sub1
;
105 NFSubstitution
* sub2
;
106 const RuleBasedNumberFormat
* formatter
;
107 const PluralFormat
* rulePatternFormat
;
109 NFRule(const NFRule
&other
); // forbid copying of this class
110 NFRule
&operator=(const NFRule
&other
); // forbid copying of this class