2 *******************************************************************************
3 * Copyright (C) 2007-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
9 *******************************************************************************
12 #ifndef __DTPTNGEN_IMPL_H__
13 #define __DTPTNGEN_IMPL_H__
15 #include "unicode/udatpg.h"
18 // TODO(claireho): Split off Builder class.
19 // TODO(claireho): If splitting off Builder class: As subclass or independent?
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
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
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
);
101 typedef enum dtStrEnum
{
107 typedef struct dtTypeElem
{
109 UDateTimePatternField field
;
115 class PtnSkeleton
: public UMemory
{
117 int32_t type
[UDATPG_FIELD_COUNT
];
118 UnicodeString original
[UDATPG_FIELD_COUNT
];
119 UnicodeString baseOriginal
[UDATPG_FIELD_COUNT
];
122 PtnSkeleton(const PtnSkeleton
& other
);
123 UBool
equals(const PtnSkeleton
& other
);
124 UnicodeString
getSkeleton();
125 UnicodeString
getBaseSkeleton();
126 virtual ~PtnSkeleton();
130 class PtnElem
: public UMemory
{
132 UnicodeString basePattern
;
133 PtnSkeleton
*skeleton
;
134 UnicodeString pattern
;
135 UBool skeletonWasSpecified
; // if specified in availableFormats, not derived
138 PtnElem(const UnicodeString
&basePattern
, const UnicodeString
&pattern
);
143 class FormatParser
: public UMemory
{
145 UnicodeString items
[MAX_DT_TOKEN
];
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
);
158 typedef enum TokenStatus
{
166 virtual TokenStatus
setTokens(const UnicodeString
& pattern
, int32_t startPos
, int32_t *len
);
169 class DistanceInfo
: public UMemory
{
171 int32_t missingFieldMask
;
172 int32_t extraFieldMask
;
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
); }
182 class DateTimeMatcher
: public UMemory
{
184 PtnSkeleton skeleton
;
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
);
192 PtnSkeleton
* getSkeletonPtr();
193 UBool
equals(const DateTimeMatcher
* other
) const;
194 int32_t getDistance(const DateTimeMatcher
& other
, int32_t includeMask
, DistanceInfo
& distanceInfo
);
196 DateTimeMatcher(const DateTimeMatcher
& other
);
197 virtual ~DateTimeMatcher();
198 int32_t getFieldMask();
201 class PatternMap
: public UMemory
{
203 PtnElem
*boot
[MAX_PATTERN_ENTRIES
];
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
);
214 PtnElem
* getDuplicateElem(const UnicodeString
&basePattern
, const PtnSkeleton
& skeleton
, PtnElem
*baseElem
);
217 class PatternMapIterator
: public UMemory
{
219 PatternMapIterator();
220 virtual ~PatternMapIterator();
221 void set(PatternMap
& patternMap
);
222 PtnSkeleton
* getSkeleton();
224 DateTimeMatcher
& next();
228 DateTimeMatcher
*matcher
;
229 PatternMap
*patternMap
;
232 class DTSkeletonEnumeration
: public StringEnumeration
{
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;
243 UBool
isCanonicalItem(const UnicodeString
& item
);
247 class DTRedundantEnumeration
: public StringEnumeration
{
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
);
259 UBool
isCanonicalItem(const UnicodeString
& item
);