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