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