]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/dtptngen_impl.h
ICU-400.40.tar.gz
[apple/icu.git] / icuSources / i18n / dtptngen_impl.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2009, International Business Machines Corporation and
4 * others. All Rights Reserved. *
5 *******************************************************************************
6 *
7 * File DTPTNGEN.H
8 *
9 *******************************************************************************
10 */
11
12 #include "uvector.h"
13
14 #ifndef __DTPTNGEN_IMPL_H__
15 #define __DTPTNGEN_IMPL_H__
16
17 // TODO(claireho): Split off Builder class.
18 // TODO(claireho): If splitting off Builder class: As subclass or independent?
19
20 #define MAX_PATTERN_ENTRIES 52
21 #define MAX_CLDR_FIELD_LEN 60
22 #define MAX_DT_TOKEN 50
23 #define MAX_RESOURCE_FIELD 12
24 #define MAX_AVAILABLE_FORMATS 12
25 #define NONE 0
26 #define EXTRA_FIELD 0x10000
27 #define MISSING_FIELD 0x1000
28 #define MAX_STRING_ENUMERATION 200
29 #define SINGLE_QUOTE ((UChar)0x0027)
30 #define FORWARDSLASH ((UChar)0x002F)
31 #define BACKSLASH ((UChar)0x005C)
32 #define SPACE ((UChar)0x0020)
33 #define QUOTATION_MARK ((UChar)0x0022)
34 #define ASTERISK ((UChar)0x002A)
35 #define PLUSSITN ((UChar)0x002B)
36 #define COMMA ((UChar)0x002C)
37 #define HYPHEN ((UChar)0x002D)
38 #define DOT ((UChar)0x002E)
39 #define COLON ((UChar)0x003A)
40 #define CAP_A ((UChar)0x0041)
41 #define CAP_C ((UChar)0x0043)
42 #define CAP_D ((UChar)0x0044)
43 #define CAP_E ((UChar)0x0045)
44 #define CAP_F ((UChar)0x0046)
45 #define CAP_G ((UChar)0x0047)
46 #define CAP_H ((UChar)0x0048)
47 #define CAP_K ((UChar)0x004B)
48 #define CAP_L ((UChar)0x004C)
49 #define CAP_M ((UChar)0x004D)
50 #define CAP_O ((UChar)0x004F)
51 #define CAP_Q ((UChar)0x0051)
52 #define CAP_S ((UChar)0x0053)
53 #define CAP_T ((UChar)0x0054)
54 #define CAP_V ((UChar)0x0056)
55 #define CAP_W ((UChar)0x0057)
56 #define CAP_Y ((UChar)0x0059)
57 #define CAP_Z ((UChar)0x005A)
58 #define LOWLINE ((UChar)0x005F)
59 #define LOW_A ((UChar)0x0061)
60 #define LOW_C ((UChar)0x0063)
61 #define LOW_D ((UChar)0x0064)
62 #define LOW_E ((UChar)0x0065)
63 #define LOW_F ((UChar)0x0066)
64 #define LOW_G ((UChar)0x0067)
65 #define LOW_H ((UChar)0x0068)
66 #define LOW_I ((UChar)0x0069)
67 #define LOW_J ((UChar)0x006A)
68 #define LOW_K ((UChar)0x006B)
69 #define LOW_L ((UChar)0x006C)
70 #define LOW_M ((UChar)0x006D)
71 #define LOW_N ((UChar)0x006E)
72 #define LOW_O ((UChar)0x006F)
73 #define LOW_P ((UChar)0x0070)
74 #define LOW_Q ((UChar)0x0071)
75 #define LOW_R ((UChar)0x0072)
76 #define LOW_S ((UChar)0x0073)
77 #define LOW_T ((UChar)0x0074)
78 #define LOW_U ((UChar)0x0075)
79 #define LOW_V ((UChar)0x0076)
80 #define LOW_W ((UChar)0x0077)
81 #define LOW_Y ((UChar)0x0079)
82 #define LOW_Z ((UChar)0x007A)
83 #define DT_SHORT -0x102
84 #define DT_LONG -0x103
85 #define DT_NUMERIC 0x100
86 #define DT_NARROW -0x101
87 #define DT_DELTA 0x10
88
89 U_NAMESPACE_BEGIN
90
91 const int32_t UDATPG_FRACTIONAL_MASK = 1<<UDATPG_FRACTIONAL_SECOND_FIELD;
92 const int32_t UDATPG_SECOND_AND_FRACTIONAL_MASK = (1<<UDATPG_SECOND_FIELD) | (1<<UDATPG_FRACTIONAL_SECOND_FIELD);
93
94 typedef enum dtStrEnum {
95 DT_BASESKELETON,
96 DT_SKELETON,
97 DT_PATTERN
98 }dtStrEnum;
99
100 typedef struct dtTypeElem {
101 UChar patternChar;
102 UDateTimePatternField field;
103 int16_t type;
104 int16_t minLen;
105 int16_t weight;
106 }dtTypeElem;
107
108 class PtnSkeleton : public UMemory {
109 public:
110 int32_t type[UDATPG_FIELD_COUNT];
111 UnicodeString original[UDATPG_FIELD_COUNT];
112 UnicodeString baseOriginal[UDATPG_FIELD_COUNT];
113
114 PtnSkeleton();
115 PtnSkeleton(const PtnSkeleton& other);
116 UBool equals(const PtnSkeleton& other);
117 UnicodeString getSkeleton();
118 UnicodeString getBaseSkeleton();
119 virtual ~PtnSkeleton();
120 };
121
122
123 class PtnElem : public UMemory {
124 public:
125 UnicodeString basePattern;
126 PtnSkeleton *skeleton;
127 UnicodeString pattern;
128 UBool skeletonWasSpecified; // if specified in availableFormats, not derived
129 PtnElem *next;
130
131 PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
132 virtual ~PtnElem();
133
134 };
135
136 class FormatParser : public UMemory {
137 public:
138 UnicodeString items[MAX_DT_TOKEN];
139 int32_t itemNumber;
140
141 FormatParser();
142 virtual ~FormatParser();
143 void set(const UnicodeString& patternString);
144 UBool isQuoteLiteral(const UnicodeString& s) const;
145 void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
146 int32_t getCanonicalIndex(const UnicodeString& s);
147 UBool isPatternSeparator(UnicodeString& field);
148 void setFilter(UErrorCode &status);
149
150 private:
151 typedef enum TokenStatus {
152 START,
153 ADD_TOKEN,
154 SYNTAX_ERROR,
155 DONE
156 } ToeknStatus;
157
158 TokenStatus status;
159 virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
160 };
161
162 class DistanceInfo : public UMemory {
163 public:
164 int32_t missingFieldMask;
165 int32_t extraFieldMask;
166
167 DistanceInfo() {};
168 virtual ~DistanceInfo() {};
169 void clear() { missingFieldMask = extraFieldMask = 0; };
170 void setTo(DistanceInfo& other);
171 void addMissing(int32_t field) { missingFieldMask |= (1<<field); };
172 void addExtra(int32_t field) { extraFieldMask |= (1<<field); };
173 };
174
175 class DateTimeMatcher: public UMemory {
176 public:
177 PtnSkeleton skeleton;
178
179 void getBasePattern(UnicodeString &basePattern);
180 UnicodeString getPattern();
181 void set(const UnicodeString& pattern, FormatParser* fp);
182 void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);
183 void copyFrom(const PtnSkeleton& skeleton);
184 void copyFrom();
185 PtnSkeleton* getSkeletonPtr();
186 UBool equals(const DateTimeMatcher* other) const;
187 int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo);
188 DateTimeMatcher();
189 DateTimeMatcher(const DateTimeMatcher& other);
190 virtual ~DateTimeMatcher() {};
191 int32_t getFieldMask();
192 };
193
194 class PatternMap : public UMemory {
195 public:
196 PtnElem *boot[MAX_PATTERN_ENTRIES];
197 PatternMap();
198 virtual ~PatternMap();
199 void add(const UnicodeString& basePattern, const PtnSkeleton& skeleton, const UnicodeString& value, UBool skeletonWasSpecified, UErrorCode& status);
200 const UnicodeString* getPatternFromBasePattern(UnicodeString& basePattern, UBool& skeletonWasSpecified);
201 const UnicodeString* getPatternFromSkeleton(PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = 0);
202 void copyFrom(const PatternMap& other, UErrorCode& status);
203 PtnElem* getHeader(UChar baseChar);
204 UBool equals(const PatternMap& other);
205 private:
206 UBool isDupAllowed;
207 PtnElem* getDuplicateElem(const UnicodeString &basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
208 }; // end PatternMap
209
210 class PatternMapIterator : public UMemory {
211 public:
212 PatternMapIterator();
213 virtual ~PatternMapIterator();
214 void set(PatternMap& patternMap);
215 PtnSkeleton* getSkeleton();
216 UBool hasNext();
217 DateTimeMatcher& next();
218 private:
219 int32_t bootIndex;
220 PtnElem *nodePtr;
221 DateTimeMatcher *matcher;
222 PatternMap *patternMap;
223 };
224
225 class DTSkeletonEnumeration : public StringEnumeration {
226 public:
227 DTSkeletonEnumeration(PatternMap &patternMap, dtStrEnum type, UErrorCode& status);
228 virtual ~DTSkeletonEnumeration();
229 static UClassID U_EXPORT2 getStaticClassID(void);
230 virtual UClassID getDynamicClassID(void) const;
231 virtual const UnicodeString* snext(UErrorCode& status);
232 virtual void reset(UErrorCode& status);
233 virtual int32_t count(UErrorCode& status) const;
234 private:
235 int32_t pos;
236 UBool isCanonicalItem(const UnicodeString& item);
237 UVector *fSkeletons;
238 };
239
240 class DTRedundantEnumeration : public StringEnumeration {
241 public:
242 DTRedundantEnumeration();
243 virtual ~DTRedundantEnumeration();
244 static UClassID U_EXPORT2 getStaticClassID(void);
245 virtual UClassID getDynamicClassID(void) const;
246 virtual const UnicodeString* snext(UErrorCode& status);
247 virtual void reset(UErrorCode& status);
248 virtual int32_t count(UErrorCode& status) const;
249 void add(const UnicodeString &pattern, UErrorCode& status);
250 private:
251 int32_t pos;
252 UBool isCanonicalItem(const UnicodeString& item);
253 UVector *fPatterns;
254 };
255
256 U_NAMESPACE_END
257
258 #endif