2 *******************************************************************************
3 * Copyright (C) 1997-2015, 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,
46 static void makeRules(UnicodeString
& definition
,
48 const NFRule
* predecessor
,
49 const RuleBasedNumberFormat
* rbnf
,
53 NFRule(const RuleBasedNumberFormat
* rbnf
, const UnicodeString
&ruleText
, UErrorCode
&status
);
56 UBool
operator==(const NFRule
& rhs
) const;
57 UBool
operator!=(const NFRule
& rhs
) const { return !operator==(rhs
); }
59 ERuleType
getType() const { return (ERuleType
)(baseValue
<= kNoBase
? (ERuleType
)baseValue
: kOtherRule
); }
60 void setType(ERuleType ruleType
) { baseValue
= (int32_t)ruleType
; }
62 int64_t getBaseValue() const { return baseValue
; }
63 void setBaseValue(int64_t value
, UErrorCode
& status
);
65 UChar
getDecimalPoint() const { return decimalPoint
; }
67 double getDivisor() const { return uprv_pow(radix
, exponent
); }
69 void doFormat(int64_t number
, UnicodeString
& toAppendTo
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
70 void doFormat(double number
, UnicodeString
& toAppendTo
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
72 UBool
doParse(const UnicodeString
& text
,
77 UBool isDecimFmtParseable
=TRUE
) const;
79 UBool
shouldRollBack(double number
) const;
81 void _appendRuleText(UnicodeString
& result
) const;
83 int32_t findTextLenient(const UnicodeString
& str
, const UnicodeString
& key
,
84 int32_t startingAt
, int32_t* resultCount
) const;
86 void setDecimalFormatSymbols(const DecimalFormatSymbols
&newSymbols
, UErrorCode
& status
);
89 void parseRuleDescriptor(UnicodeString
& descriptor
, UErrorCode
& status
);
90 void extractSubstitutions(const NFRuleSet
* ruleSet
, const UnicodeString
&ruleText
, const NFRule
* predecessor
, UErrorCode
& status
);
91 NFSubstitution
* extractSubstitution(const NFRuleSet
* ruleSet
, const NFRule
* predecessor
, UErrorCode
& status
);
93 int16_t expectedExponent() const;
94 int32_t indexOfAnyRulePrefix() const;
95 double matchToDelimiter(const UnicodeString
& text
, int32_t startPos
, double baseValue
,
96 const UnicodeString
& delimiter
, ParsePosition
& pp
, const NFSubstitution
* sub
,
97 double upperBound
) const;
98 void stripPrefix(UnicodeString
& text
, const UnicodeString
& prefix
, ParsePosition
& pp
) const;
100 int32_t prefixLength(const UnicodeString
& str
, const UnicodeString
& prefix
, UErrorCode
& status
) const;
101 UBool
allIgnorable(const UnicodeString
& str
, UErrorCode
& status
) const;
102 int32_t findText(const UnicodeString
& str
, const UnicodeString
& key
,
103 int32_t startingAt
, int32_t* resultCount
) const;
110 UnicodeString ruleText
;
111 NFSubstitution
* sub1
;
112 NFSubstitution
* sub2
;
113 const RuleBasedNumberFormat
* formatter
;
114 const PluralFormat
* rulePatternFormat
;
116 NFRule(const NFRule
&other
); // forbid copying of this class
117 NFRule
&operator=(const NFRule
&other
); // forbid copying of this class