]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/plurrule_impl.h
ICU-461.18.tar.gz
[apple/icu.git] / icuSources / i18n / plurrule_impl.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2008, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 *
7 * File PLURRULE_IMPL.H
8 *
9 *******************************************************************************
10 */
11
12
13 #ifndef PLURRULE_IMPLE
14 #define PLURRULE_IMPLE
15
16 /**
17 * \file
18 * \brief C++ API: Defines rules for mapping positive long values onto a small set of keywords.
19 */
20
21 #if !UCONFIG_NO_FORMATTING
22
23 #include "unicode/format.h"
24 #include "unicode/locid.h"
25 #include "unicode/parseerr.h"
26 #include "unicode/utypes.h"
27 #include "uvector.h"
28 #include "hash.h"
29
30 U_NAMESPACE_BEGIN
31
32 #define DOT ((UChar)0x002E)
33 #define SINGLE_QUOTE ((UChar)0x0027)
34 #define SLASH ((UChar)0x002F)
35 #define BACKSLASH ((UChar)0x005C)
36 #define SPACE ((UChar)0x0020)
37 #define QUOTATION_MARK ((UChar)0x0022)
38 #define NUMBER_SIGN ((UChar)0x0023)
39 #define ASTERISK ((UChar)0x002A)
40 #define COMMA ((UChar)0x002C)
41 #define HYPHEN ((UChar)0x002D)
42 #define U_ZERO ((UChar)0x0030)
43 #define U_ONE ((UChar)0x0031)
44 #define U_TWO ((UChar)0x0032)
45 #define U_THREE ((UChar)0x0033)
46 #define U_FOUR ((UChar)0x0034)
47 #define U_FIVE ((UChar)0x0035)
48 #define U_SIX ((UChar)0x0036)
49 #define U_SEVEN ((UChar)0x0037)
50 #define U_EIGHT ((UChar)0x0038)
51 #define U_NINE ((UChar)0x0039)
52 #define COLON ((UChar)0x003A)
53 #define SEMI_COLON ((UChar)0x003B)
54 #define CAP_A ((UChar)0x0041)
55 #define CAP_B ((UChar)0x0042)
56 #define CAP_R ((UChar)0x0052)
57 #define CAP_Z ((UChar)0x005A)
58 #define LOWLINE ((UChar)0x005F)
59 #define LEFTBRACE ((UChar)0x007B)
60 #define RIGHTBRACE ((UChar)0x007D)
61
62 #define LOW_A ((UChar)0x0061)
63 #define LOW_B ((UChar)0x0062)
64 #define LOW_C ((UChar)0x0063)
65 #define LOW_D ((UChar)0x0064)
66 #define LOW_E ((UChar)0x0065)
67 #define LOW_F ((UChar)0x0066)
68 #define LOW_G ((UChar)0x0067)
69 #define LOW_H ((UChar)0x0068)
70 #define LOW_I ((UChar)0x0069)
71 #define LOW_J ((UChar)0x006a)
72 #define LOW_K ((UChar)0x006B)
73 #define LOW_L ((UChar)0x006C)
74 #define LOW_M ((UChar)0x006D)
75 #define LOW_N ((UChar)0x006E)
76 #define LOW_O ((UChar)0x006F)
77 #define LOW_P ((UChar)0x0070)
78 #define LOW_Q ((UChar)0x0071)
79 #define LOW_R ((UChar)0x0072)
80 #define LOW_S ((UChar)0x0073)
81 #define LOW_T ((UChar)0x0074)
82 #define LOW_U ((UChar)0x0075)
83 #define LOW_V ((UChar)0x0076)
84 #define LOW_W ((UChar)0x0077)
85 #define LOW_Y ((UChar)0x0079)
86 #define LOW_Z ((UChar)0x007A)
87
88
89 #define PLURAL_RANGE_HIGH 0x7fffffff;
90
91
92 class UnicodeSet;
93
94 typedef enum PluralKey {
95 pZero,
96 pOne,
97 pTwo,
98 pFew,
99 pMany,
100 pOther,
101 pLast
102 }PluralKey;
103
104 typedef enum tokenType {
105 none,
106 tLetter,
107 tNumber,
108 tComma,
109 tSemiColon,
110 tSpace,
111 tColon,
112 tDot,
113 tKeyword,
114 tZero,
115 tOne,
116 tTwo,
117 tFew,
118 tMany,
119 tOther,
120 tAnd,
121 tOr,
122 tMod,
123 tNot,
124 tIn,
125 tWithin,
126 tNotIn,
127 tVariableN,
128 tIs,
129 tLeftBrace,
130 tRightBrace
131 }tokenType;
132
133 class RuleParser : public UMemory {
134 public:
135 RuleParser();
136 virtual ~RuleParser();
137 void getNextToken(const UnicodeString& ruleData, int32_t *ruleIndex, UnicodeString& token,
138 tokenType& type, UErrorCode &status);
139 void checkSyntax(tokenType prevType, tokenType curType, UErrorCode &status);
140 private:
141 UnicodeSet *idStartFilter;
142 UnicodeSet *idContinueFilter;
143
144 void getKeyType(const UnicodeString& token, tokenType& type, UErrorCode &status);
145 UBool inRange(UChar ch, tokenType& type);
146 UBool isValidKeyword(const UnicodeString& token);
147 };
148
149 class AndConstraint : public UMemory {
150 public:
151 typedef enum RuleOp {
152 NONE,
153 MOD
154 } RuleOp;
155 RuleOp op;
156 int32_t opNum;
157 int32_t rangeLow;
158 int32_t rangeHigh;
159 UBool notIn;
160 UBool integerOnly;
161 AndConstraint *next;
162
163 AndConstraint();
164 AndConstraint(const AndConstraint& other);
165 virtual ~AndConstraint();
166 AndConstraint* add();
167 UBool isFulfilled(double number);
168 int32_t updateRepeatLimit(int32_t maxLimit);
169 };
170
171 class OrConstraint : public UMemory {
172 public:
173 AndConstraint *childNode;
174 OrConstraint *next;
175 OrConstraint();
176
177 OrConstraint(const OrConstraint& other);
178 virtual ~OrConstraint();
179 AndConstraint* add();
180 UBool isFulfilled(double number);
181 };
182
183 class RuleChain : public UMemory {
184 public:
185 OrConstraint *ruleHeader;
186 UnicodeString keyword;
187 RuleChain();
188 RuleChain(const RuleChain& other);
189 RuleChain *next;
190
191 virtual ~RuleChain();
192 UnicodeString select(double number) const;
193 void dumpRules(UnicodeString& result);
194 int32_t getRepeatLimit();
195 UErrorCode getKeywords(int32_t maxArraySize, UnicodeString *keywords, int32_t& arraySize) const;
196 UBool isKeyword(const UnicodeString& keyword) const;
197 void setRepeatLimit();
198 private:
199 int32_t repeatLimit;
200 };
201
202 class PluralKeywordEnumeration : public StringEnumeration {
203 public:
204 PluralKeywordEnumeration(RuleChain *header, UErrorCode& status);
205 virtual ~PluralKeywordEnumeration();
206 static UClassID U_EXPORT2 getStaticClassID(void);
207 virtual UClassID getDynamicClassID(void) const;
208 virtual const UnicodeString* snext(UErrorCode& status);
209 virtual void reset(UErrorCode& status);
210 virtual int32_t count(UErrorCode& status) const;
211 private:
212 int32_t pos;
213 UVector fKeywordNames;
214 };
215
216 U_NAMESPACE_END
217
218 #endif /* #if !UCONFIG_NO_FORMATTING */
219
220 #endif // _PLURRULE_IMPL
221 //eof