2007-08-03 18:43:04 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2016-02-24 00:49:51 +00:00
|
|
|
* Copyright (C) 2007-2016, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
2007-08-03 18:43:04 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File DTPTNGEN.H
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DTPTNGEN_IMPL_H__
|
|
|
|
#define __DTPTNGEN_IMPL_H__
|
|
|
|
|
2016-02-24 00:49:51 +00:00
|
|
|
#include "unicode/udatpg.h"
|
|
|
|
#include "uvector.h"
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// TODO(claireho): Split off Builder class.
|
|
|
|
// TODO(claireho): If splitting off Builder class: As subclass or independent?
|
|
|
|
|
|
|
|
#define MAX_PATTERN_ENTRIES 52
|
|
|
|
#define MAX_CLDR_FIELD_LEN 60
|
|
|
|
#define MAX_DT_TOKEN 50
|
2007-08-26 20:10:45 +00:00
|
|
|
#define MAX_RESOURCE_FIELD 12
|
2007-08-03 18:43:04 +00:00
|
|
|
#define MAX_AVAILABLE_FORMATS 12
|
|
|
|
#define NONE 0
|
|
|
|
#define EXTRA_FIELD 0x10000
|
|
|
|
#define MISSING_FIELD 0x1000
|
|
|
|
#define MAX_STRING_ENUMERATION 200
|
|
|
|
#define SINGLE_QUOTE ((UChar)0x0027)
|
|
|
|
#define FORWARDSLASH ((UChar)0x002F)
|
|
|
|
#define BACKSLASH ((UChar)0x005C)
|
|
|
|
#define SPACE ((UChar)0x0020)
|
|
|
|
#define QUOTATION_MARK ((UChar)0x0022)
|
|
|
|
#define ASTERISK ((UChar)0x002A)
|
|
|
|
#define PLUSSITN ((UChar)0x002B)
|
|
|
|
#define COMMA ((UChar)0x002C)
|
|
|
|
#define HYPHEN ((UChar)0x002D)
|
|
|
|
#define DOT ((UChar)0x002E)
|
|
|
|
#define COLON ((UChar)0x003A)
|
|
|
|
#define CAP_A ((UChar)0x0041)
|
|
|
|
#define CAP_C ((UChar)0x0043)
|
|
|
|
#define CAP_D ((UChar)0x0044)
|
|
|
|
#define CAP_E ((UChar)0x0045)
|
|
|
|
#define CAP_F ((UChar)0x0046)
|
|
|
|
#define CAP_G ((UChar)0x0047)
|
|
|
|
#define CAP_H ((UChar)0x0048)
|
2013-09-12 22:49:07 +00:00
|
|
|
#define CAP_J ((UChar)0x004A)
|
2009-03-20 00:08:24 +00:00
|
|
|
#define CAP_K ((UChar)0x004B)
|
2007-08-03 18:43:04 +00:00
|
|
|
#define CAP_L ((UChar)0x004C)
|
|
|
|
#define CAP_M ((UChar)0x004D)
|
|
|
|
#define CAP_O ((UChar)0x004F)
|
|
|
|
#define CAP_Q ((UChar)0x0051)
|
|
|
|
#define CAP_S ((UChar)0x0053)
|
|
|
|
#define CAP_T ((UChar)0x0054)
|
2012-01-17 08:06:29 +00:00
|
|
|
#define CAP_U ((UChar)0x0055)
|
2007-08-03 18:43:04 +00:00
|
|
|
#define CAP_V ((UChar)0x0056)
|
|
|
|
#define CAP_W ((UChar)0x0057)
|
2013-09-10 07:51:38 +00:00
|
|
|
#define CAP_X ((UChar)0x0058)
|
2007-08-03 18:43:04 +00:00
|
|
|
#define CAP_Y ((UChar)0x0059)
|
|
|
|
#define CAP_Z ((UChar)0x005A)
|
|
|
|
#define LOWLINE ((UChar)0x005F)
|
|
|
|
#define LOW_A ((UChar)0x0061)
|
|
|
|
#define LOW_C ((UChar)0x0063)
|
|
|
|
#define LOW_D ((UChar)0x0064)
|
|
|
|
#define LOW_E ((UChar)0x0065)
|
|
|
|
#define LOW_F ((UChar)0x0066)
|
|
|
|
#define LOW_G ((UChar)0x0067)
|
|
|
|
#define LOW_H ((UChar)0x0068)
|
|
|
|
#define LOW_I ((UChar)0x0069)
|
2009-03-20 00:08:24 +00:00
|
|
|
#define LOW_J ((UChar)0x006A)
|
2007-08-03 18:43:04 +00:00
|
|
|
#define LOW_K ((UChar)0x006B)
|
|
|
|
#define LOW_L ((UChar)0x006C)
|
|
|
|
#define LOW_M ((UChar)0x006D)
|
|
|
|
#define LOW_N ((UChar)0x006E)
|
|
|
|
#define LOW_O ((UChar)0x006F)
|
|
|
|
#define LOW_P ((UChar)0x0070)
|
|
|
|
#define LOW_Q ((UChar)0x0071)
|
|
|
|
#define LOW_R ((UChar)0x0072)
|
|
|
|
#define LOW_S ((UChar)0x0073)
|
|
|
|
#define LOW_T ((UChar)0x0074)
|
|
|
|
#define LOW_U ((UChar)0x0075)
|
|
|
|
#define LOW_V ((UChar)0x0076)
|
|
|
|
#define LOW_W ((UChar)0x0077)
|
2013-09-10 07:51:38 +00:00
|
|
|
#define LOW_X ((UChar)0x0078)
|
2007-08-03 18:43:04 +00:00
|
|
|
#define LOW_Y ((UChar)0x0079)
|
|
|
|
#define LOW_Z ((UChar)0x007A)
|
2008-06-11 16:31:33 +00:00
|
|
|
#define DT_SHORT -0x102
|
|
|
|
#define DT_LONG -0x103
|
2007-08-03 18:43:04 +00:00
|
|
|
#define DT_NUMERIC 0x100
|
2008-06-11 16:31:33 +00:00
|
|
|
#define DT_NARROW -0x101
|
2007-08-03 18:43:04 +00:00
|
|
|
#define DT_DELTA 0x10
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
const int32_t UDATPG_FRACTIONAL_MASK = 1<<UDATPG_FRACTIONAL_SECOND_FIELD;
|
|
|
|
const int32_t UDATPG_SECOND_AND_FRACTIONAL_MASK = (1<<UDATPG_SECOND_FIELD) | (1<<UDATPG_FRACTIONAL_SECOND_FIELD);
|
|
|
|
|
|
|
|
typedef enum dtStrEnum {
|
|
|
|
DT_BASESKELETON,
|
|
|
|
DT_SKELETON,
|
2007-08-04 02:44:11 +00:00
|
|
|
DT_PATTERN
|
|
|
|
}dtStrEnum;
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
typedef struct dtTypeElem {
|
|
|
|
UChar patternChar;
|
|
|
|
UDateTimePatternField field;
|
2008-01-08 09:45:15 +00:00
|
|
|
int16_t type;
|
|
|
|
int16_t minLen;
|
|
|
|
int16_t weight;
|
2007-08-03 18:43:04 +00:00
|
|
|
}dtTypeElem;
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class PtnSkeleton : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
int32_t type[UDATPG_FIELD_COUNT];
|
|
|
|
UnicodeString original[UDATPG_FIELD_COUNT];
|
|
|
|
UnicodeString baseOriginal[UDATPG_FIELD_COUNT];
|
|
|
|
|
|
|
|
PtnSkeleton();
|
2007-08-04 03:14:19 +00:00
|
|
|
PtnSkeleton(const PtnSkeleton& other);
|
|
|
|
UBool equals(const PtnSkeleton& other);
|
2007-08-03 18:43:04 +00:00
|
|
|
UnicodeString getSkeleton();
|
2007-08-07 03:14:19 +00:00
|
|
|
UnicodeString getBaseSkeleton();
|
2007-08-03 18:43:04 +00:00
|
|
|
virtual ~PtnSkeleton();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class PtnElem : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
2007-08-04 02:44:11 +00:00
|
|
|
UnicodeString basePattern;
|
2007-08-03 18:43:04 +00:00
|
|
|
PtnSkeleton *skeleton;
|
2007-08-04 02:44:11 +00:00
|
|
|
UnicodeString pattern;
|
2008-11-18 18:27:40 +00:00
|
|
|
UBool skeletonWasSpecified; // if specified in availableFormats, not derived
|
2007-08-03 18:43:04 +00:00
|
|
|
PtnElem *next;
|
|
|
|
|
2007-08-04 02:44:11 +00:00
|
|
|
PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
|
2007-08-03 18:43:04 +00:00
|
|
|
virtual ~PtnElem();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class FormatParser : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
UnicodeString items[MAX_DT_TOKEN];
|
|
|
|
int32_t itemNumber;
|
|
|
|
|
|
|
|
FormatParser();
|
|
|
|
virtual ~FormatParser();
|
|
|
|
void set(const UnicodeString& patternString);
|
|
|
|
void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
|
|
|
|
UBool isPatternSeparator(UnicodeString& field);
|
2015-08-13 22:09:13 +00:00
|
|
|
static UBool isQuoteLiteral(const UnicodeString& s);
|
|
|
|
static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); }
|
|
|
|
static int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef enum TokenStatus {
|
|
|
|
START,
|
|
|
|
ADD_TOKEN,
|
|
|
|
SYNTAX_ERROR,
|
|
|
|
DONE
|
|
|
|
} ToeknStatus;
|
|
|
|
|
|
|
|
TokenStatus status;
|
|
|
|
virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
|
|
|
|
};
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class DistanceInfo : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
int32_t missingFieldMask;
|
|
|
|
int32_t extraFieldMask;
|
|
|
|
|
2011-07-06 20:05:38 +00:00
|
|
|
DistanceInfo() {}
|
2011-07-26 05:32:25 +00:00
|
|
|
virtual ~DistanceInfo();
|
2011-07-06 20:05:38 +00:00
|
|
|
void clear() { missingFieldMask = extraFieldMask = 0; }
|
2007-08-03 18:43:04 +00:00
|
|
|
void setTo(DistanceInfo& other);
|
2011-07-06 20:05:38 +00:00
|
|
|
void addMissing(int32_t field) { missingFieldMask |= (1<<field); }
|
|
|
|
void addExtra(int32_t field) { extraFieldMask |= (1<<field); }
|
2007-08-03 18:43:04 +00:00
|
|
|
};
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class DateTimeMatcher: public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
PtnSkeleton skeleton;
|
|
|
|
|
|
|
|
void getBasePattern(UnicodeString &basePattern);
|
|
|
|
UnicodeString getPattern();
|
|
|
|
void set(const UnicodeString& pattern, FormatParser* fp);
|
|
|
|
void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);
|
2007-08-29 05:44:57 +00:00
|
|
|
void copyFrom(const PtnSkeleton& skeleton);
|
2007-08-03 18:43:04 +00:00
|
|
|
void copyFrom();
|
|
|
|
PtnSkeleton* getSkeletonPtr();
|
2007-08-23 05:48:44 +00:00
|
|
|
UBool equals(const DateTimeMatcher* other) const;
|
|
|
|
int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo);
|
2007-08-03 18:43:04 +00:00
|
|
|
DateTimeMatcher();
|
2007-08-29 05:44:57 +00:00
|
|
|
DateTimeMatcher(const DateTimeMatcher& other);
|
2011-07-26 05:32:25 +00:00
|
|
|
virtual ~DateTimeMatcher();
|
2007-08-03 18:43:04 +00:00
|
|
|
int32_t getFieldMask();
|
|
|
|
};
|
|
|
|
|
2007-08-04 02:53:37 +00:00
|
|
|
class PatternMap : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
PtnElem *boot[MAX_PATTERN_ENTRIES];
|
|
|
|
PatternMap();
|
|
|
|
virtual ~PatternMap();
|
2008-11-18 18:27:40 +00:00
|
|
|
void add(const UnicodeString& basePattern, const PtnSkeleton& skeleton, const UnicodeString& value, UBool skeletonWasSpecified, UErrorCode& status);
|
|
|
|
const UnicodeString* getPatternFromBasePattern(UnicodeString& basePattern, UBool& skeletonWasSpecified);
|
|
|
|
const UnicodeString* getPatternFromSkeleton(PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = 0);
|
2007-08-03 18:43:04 +00:00
|
|
|
void copyFrom(const PatternMap& other, UErrorCode& status);
|
2007-08-07 03:14:19 +00:00
|
|
|
PtnElem* getHeader(UChar baseChar);
|
2007-08-03 18:43:04 +00:00
|
|
|
UBool equals(const PatternMap& other);
|
|
|
|
private:
|
|
|
|
UBool isDupAllowed;
|
|
|
|
PtnElem* getDuplicateElem(const UnicodeString &basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
|
|
|
|
}; // end PatternMap
|
|
|
|
|
2014-11-20 01:26:30 +00:00
|
|
|
class PatternMapIterator : public UMemory {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
PatternMapIterator();
|
2014-11-20 01:26:30 +00:00
|
|
|
virtual ~PatternMapIterator();
|
2007-08-03 18:43:04 +00:00
|
|
|
void set(PatternMap& patternMap);
|
|
|
|
PtnSkeleton* getSkeleton();
|
|
|
|
UBool hasNext();
|
|
|
|
DateTimeMatcher& next();
|
|
|
|
private:
|
|
|
|
int32_t bootIndex;
|
|
|
|
PtnElem *nodePtr;
|
2014-11-20 01:26:30 +00:00
|
|
|
DateTimeMatcher *matcher;
|
2007-08-03 18:43:04 +00:00
|
|
|
PatternMap *patternMap;
|
|
|
|
};
|
|
|
|
|
2008-01-02 23:53:26 +00:00
|
|
|
class DTSkeletonEnumeration : public StringEnumeration {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
DTSkeletonEnumeration(PatternMap &patternMap, dtStrEnum type, UErrorCode& status);
|
|
|
|
virtual ~DTSkeletonEnumeration();
|
|
|
|
static UClassID U_EXPORT2 getStaticClassID(void);
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
|
|
|
virtual const UnicodeString* snext(UErrorCode& status);
|
|
|
|
virtual void reset(UErrorCode& status);
|
|
|
|
virtual int32_t count(UErrorCode& status) const;
|
|
|
|
private:
|
|
|
|
int32_t pos;
|
|
|
|
UBool isCanonicalItem(const UnicodeString& item);
|
|
|
|
UVector *fSkeletons;
|
|
|
|
};
|
|
|
|
|
2008-01-02 23:53:26 +00:00
|
|
|
class DTRedundantEnumeration : public StringEnumeration {
|
2007-08-03 18:43:04 +00:00
|
|
|
public:
|
|
|
|
DTRedundantEnumeration();
|
|
|
|
virtual ~DTRedundantEnumeration();
|
|
|
|
static UClassID U_EXPORT2 getStaticClassID(void);
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
|
|
|
virtual const UnicodeString* snext(UErrorCode& status);
|
|
|
|
virtual void reset(UErrorCode& status);
|
|
|
|
virtual int32_t count(UErrorCode& status) const;
|
|
|
|
void add(const UnicodeString &pattern, UErrorCode& status);
|
|
|
|
private:
|
|
|
|
int32_t pos;
|
|
|
|
UBool isCanonicalItem(const UnicodeString& item);
|
|
|
|
UVector *fPatterns;
|
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|