]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/plurrule_impl.h
2 *******************************************************************************
3 * Copyright (C) 2007-2008, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
9 *******************************************************************************
13 #ifndef PLURRULE_IMPLE
14 #define PLURRULE_IMPLE
18 * \brief C++ API: Defines rules for mapping positive long values onto a small set of keywords.
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/format.h"
24 #include "unicode/locid.h"
25 #include "unicode/parseerr.h"
26 #include "unicode/utypes.h"
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)
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)
89 #define PLURAL_RANGE_HIGH 0x7fffffff;
94 typedef enum PluralKey
{
104 typedef enum tokenType
{
133 class RuleParser
: public UMemory
{
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
);
141 UnicodeSet
*idStartFilter
;
142 UnicodeSet
*idContinueFilter
;
144 void getKeyType(const UnicodeString
& token
, tokenType
& type
, UErrorCode
&status
);
145 UBool
inRange(UChar ch
, tokenType
& type
);
146 UBool
isValidKeyword(const UnicodeString
& token
);
149 class AndConstraint
: public UMemory
{
151 typedef enum RuleOp
{
164 AndConstraint(const AndConstraint
& other
);
165 virtual ~AndConstraint();
166 AndConstraint
* add();
167 UBool
isFulfilled(double number
);
168 int32_t updateRepeatLimit(int32_t maxLimit
);
171 class OrConstraint
: public UMemory
{
173 AndConstraint
*childNode
;
177 OrConstraint(const OrConstraint
& other
);
178 virtual ~OrConstraint();
179 AndConstraint
* add();
180 UBool
isFulfilled(double number
);
183 class RuleChain
: public UMemory
{
185 OrConstraint
*ruleHeader
;
186 UnicodeString keyword
;
188 RuleChain(const RuleChain
& other
);
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();
202 class PluralKeywordEnumeration
: public StringEnumeration
{
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;
213 UVector fKeywordNames
;
218 #endif /* #if !UCONFIG_NO_FORMATTING */
220 #endif // _PLURRULE_IMPL