1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 1997-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
13 #include "unicode/rbnf.h"
17 #include "unicode/utypes.h"
18 #include "unicode/uobject.h"
19 #include "unicode/unistr.h"
30 class RuleBasedNumberFormat
;
33 class NFRule
: public UMemory
{
38 kNegativeNumberRule
= -1,
39 kImproperFractionRule
= -2,
40 kProperFractionRule
= -3,
47 static void makeRules(UnicodeString
& definition
,
49 const NFRule
* predecessor
,
50 const RuleBasedNumberFormat
* rbnf
,
54 NFRule(const RuleBasedNumberFormat
* rbnf
, const UnicodeString
&ruleText
, UErrorCode
&status
);
57 UBool
operator==(const NFRule
& rhs
) const;
58 UBool
operator!=(const NFRule
& rhs
) const { return !operator==(rhs
); }
60 ERuleType
getType() const { return (ERuleType
)(baseValue
<= kNoBase
? (ERuleType
)baseValue
: kOtherRule
); }
61 void setType(ERuleType ruleType
) { baseValue
= (int32_t)ruleType
; }
63 int64_t getBaseValue() const { return baseValue
; }
64 void setBaseValue(int64_t value
, UErrorCode
& status
);
66 UChar
getDecimalPoint() const { return decimalPoint
; }
68 int64_t getDivisor() const;
70 void doFormat(int64_t number
, UnicodeString
& toAppendTo
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
71 void doFormat(double number
, UnicodeString
& toAppendTo
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
73 UBool
doParse(const UnicodeString
& text
,
77 uint32_t nonNumericalExecutedRuleMask
,
79 UBool isDecimFmtParseable
=TRUE
) const;
81 UBool
shouldRollBack(int64_t number
) const;
83 void _appendRuleText(UnicodeString
& result
) const;
85 int32_t findTextLenient(const UnicodeString
& str
, const UnicodeString
& key
,
86 int32_t startingAt
, int32_t* resultCount
) const;
88 void setDecimalFormatSymbols(const DecimalFormatSymbols
&newSymbols
, UErrorCode
& status
);
91 void parseRuleDescriptor(UnicodeString
& descriptor
, UErrorCode
& status
);
92 void extractSubstitutions(const NFRuleSet
* ruleSet
, const UnicodeString
&ruleText
, const NFRule
* predecessor
, UErrorCode
& status
);
93 NFSubstitution
* extractSubstitution(const NFRuleSet
* ruleSet
, const NFRule
* predecessor
, UErrorCode
& status
);
95 int16_t expectedExponent() const;
96 int32_t indexOfAnyRulePrefix() const;
97 double matchToDelimiter(const UnicodeString
& text
, int32_t startPos
, double baseValue
,
98 const UnicodeString
& delimiter
, ParsePosition
& pp
, const NFSubstitution
* sub
,
99 uint32_t nonNumericalExecutedRuleMask
,
100 double upperBound
) const;
101 void stripPrefix(UnicodeString
& text
, const UnicodeString
& prefix
, ParsePosition
& pp
) const;
103 int32_t prefixLength(const UnicodeString
& str
, const UnicodeString
& prefix
, UErrorCode
& status
) const;
104 UBool
allIgnorable(const UnicodeString
& str
, UErrorCode
& status
) const;
105 int32_t findText(const UnicodeString
& str
, const UnicodeString
& key
,
106 int32_t startingAt
, int32_t* resultCount
) const;
113 UnicodeString fRuleText
;
114 NFSubstitution
* sub1
;
115 NFSubstitution
* sub2
;
116 const RuleBasedNumberFormat
* formatter
;
117 const PluralFormat
* rulePatternFormat
;
119 NFRule(const NFRule
&other
); // forbid copying of this class
120 NFRule
&operator=(const NFRule
&other
); // forbid copying of this class