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