intl/icu/source/i18n/dtptngen_impl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/dtptngen_impl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,263 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +* Copyright (C) 2007-2013, International Business Machines Corporation and
     1.7 +* others. All Rights Reserved.                                                *
     1.8 +*******************************************************************************
     1.9 +*
    1.10 +* File DTPTNGEN.H
    1.11 +*
    1.12 +*******************************************************************************
    1.13 +*/
    1.14 +
    1.15 +#include "uvector.h"
    1.16 +
    1.17 +#ifndef __DTPTNGEN_IMPL_H__
    1.18 +#define __DTPTNGEN_IMPL_H__
    1.19 +
    1.20 +// TODO(claireho): Split off Builder class.
    1.21 +// TODO(claireho): If splitting off Builder class: As subclass or independent?
    1.22 +
    1.23 +#define MAX_PATTERN_ENTRIES 52
    1.24 +#define MAX_CLDR_FIELD_LEN  60
    1.25 +#define MAX_DT_TOKEN        50
    1.26 +#define MAX_RESOURCE_FIELD  12
    1.27 +#define MAX_AVAILABLE_FORMATS  12
    1.28 +#define NONE          0
    1.29 +#define EXTRA_FIELD   0x10000
    1.30 +#define MISSING_FIELD  0x1000
    1.31 +#define MAX_STRING_ENUMERATION  200
    1.32 +#define SINGLE_QUOTE      ((UChar)0x0027)
    1.33 +#define FORWARDSLASH      ((UChar)0x002F)
    1.34 +#define BACKSLASH         ((UChar)0x005C)
    1.35 +#define SPACE             ((UChar)0x0020)
    1.36 +#define QUOTATION_MARK    ((UChar)0x0022)
    1.37 +#define ASTERISK          ((UChar)0x002A)
    1.38 +#define PLUSSITN          ((UChar)0x002B)
    1.39 +#define COMMA             ((UChar)0x002C)
    1.40 +#define HYPHEN            ((UChar)0x002D)
    1.41 +#define DOT               ((UChar)0x002E)
    1.42 +#define COLON             ((UChar)0x003A)
    1.43 +#define CAP_A             ((UChar)0x0041)
    1.44 +#define CAP_C             ((UChar)0x0043)
    1.45 +#define CAP_D             ((UChar)0x0044)
    1.46 +#define CAP_E             ((UChar)0x0045)
    1.47 +#define CAP_F             ((UChar)0x0046)
    1.48 +#define CAP_G             ((UChar)0x0047)
    1.49 +#define CAP_H             ((UChar)0x0048)
    1.50 +#define CAP_J             ((UChar)0x004A)
    1.51 +#define CAP_K             ((UChar)0x004B)
    1.52 +#define CAP_L             ((UChar)0x004C)
    1.53 +#define CAP_M             ((UChar)0x004D)
    1.54 +#define CAP_O             ((UChar)0x004F)
    1.55 +#define CAP_Q             ((UChar)0x0051)
    1.56 +#define CAP_S             ((UChar)0x0053)
    1.57 +#define CAP_T             ((UChar)0x0054)
    1.58 +#define CAP_U             ((UChar)0x0055)
    1.59 +#define CAP_V             ((UChar)0x0056)
    1.60 +#define CAP_W             ((UChar)0x0057)
    1.61 +#define CAP_X             ((UChar)0x0058)
    1.62 +#define CAP_Y             ((UChar)0x0059)
    1.63 +#define CAP_Z             ((UChar)0x005A)
    1.64 +#define LOWLINE           ((UChar)0x005F)
    1.65 +#define LOW_A             ((UChar)0x0061)
    1.66 +#define LOW_C             ((UChar)0x0063)
    1.67 +#define LOW_D             ((UChar)0x0064)
    1.68 +#define LOW_E             ((UChar)0x0065)
    1.69 +#define LOW_F             ((UChar)0x0066)
    1.70 +#define LOW_G             ((UChar)0x0067)
    1.71 +#define LOW_H             ((UChar)0x0068)
    1.72 +#define LOW_I             ((UChar)0x0069)
    1.73 +#define LOW_J             ((UChar)0x006A)
    1.74 +#define LOW_K             ((UChar)0x006B)
    1.75 +#define LOW_L             ((UChar)0x006C)
    1.76 +#define LOW_M             ((UChar)0x006D)
    1.77 +#define LOW_N             ((UChar)0x006E)
    1.78 +#define LOW_O             ((UChar)0x006F)
    1.79 +#define LOW_P             ((UChar)0x0070)
    1.80 +#define LOW_Q             ((UChar)0x0071)
    1.81 +#define LOW_R             ((UChar)0x0072)
    1.82 +#define LOW_S             ((UChar)0x0073)
    1.83 +#define LOW_T             ((UChar)0x0074)
    1.84 +#define LOW_U             ((UChar)0x0075)
    1.85 +#define LOW_V             ((UChar)0x0076)
    1.86 +#define LOW_W             ((UChar)0x0077)
    1.87 +#define LOW_X             ((UChar)0x0078)
    1.88 +#define LOW_Y             ((UChar)0x0079)
    1.89 +#define LOW_Z             ((UChar)0x007A)
    1.90 +#define DT_SHORT          -0x102
    1.91 +#define DT_LONG           -0x103
    1.92 +#define DT_NUMERIC         0x100
    1.93 +#define DT_NARROW         -0x101
    1.94 +#define DT_DELTA           0x10
    1.95 +
    1.96 +U_NAMESPACE_BEGIN
    1.97 +
    1.98 +const int32_t UDATPG_FRACTIONAL_MASK = 1<<UDATPG_FRACTIONAL_SECOND_FIELD;
    1.99 +const int32_t UDATPG_SECOND_AND_FRACTIONAL_MASK = (1<<UDATPG_SECOND_FIELD) | (1<<UDATPG_FRACTIONAL_SECOND_FIELD);
   1.100 +
   1.101 +typedef enum dtStrEnum {
   1.102 +    DT_BASESKELETON,
   1.103 +    DT_SKELETON,
   1.104 +    DT_PATTERN
   1.105 +}dtStrEnum;
   1.106 +
   1.107 +typedef struct dtTypeElem {
   1.108 +    UChar                  patternChar;
   1.109 +    UDateTimePatternField  field;
   1.110 +    int16_t                type;
   1.111 +    int16_t                minLen;
   1.112 +    int16_t                weight;
   1.113 +}dtTypeElem;
   1.114 +
   1.115 +class PtnSkeleton : public UMemory {
   1.116 +public:
   1.117 +    int32_t type[UDATPG_FIELD_COUNT];
   1.118 +    UnicodeString original[UDATPG_FIELD_COUNT];
   1.119 +    UnicodeString baseOriginal[UDATPG_FIELD_COUNT];
   1.120 +
   1.121 +    PtnSkeleton();
   1.122 +    PtnSkeleton(const PtnSkeleton& other);
   1.123 +    UBool equals(const PtnSkeleton& other);
   1.124 +    UnicodeString getSkeleton();
   1.125 +    UnicodeString getBaseSkeleton();
   1.126 +    virtual ~PtnSkeleton();
   1.127 +};
   1.128 +
   1.129 +
   1.130 +class PtnElem : public UMemory {
   1.131 +public:
   1.132 +    UnicodeString basePattern;
   1.133 +    PtnSkeleton   *skeleton;
   1.134 +    UnicodeString pattern;
   1.135 +    UBool         skeletonWasSpecified; // if specified in availableFormats, not derived
   1.136 +    PtnElem       *next;
   1.137 +
   1.138 +    PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
   1.139 +    virtual ~PtnElem();
   1.140 +
   1.141 +};
   1.142 +
   1.143 +class FormatParser : public UMemory {
   1.144 +public:
   1.145 +    UnicodeString items[MAX_DT_TOKEN];
   1.146 +    int32_t  itemNumber;
   1.147 +
   1.148 +    FormatParser();
   1.149 +    virtual ~FormatParser();
   1.150 +    void set(const UnicodeString& patternString);
   1.151 +    UBool isQuoteLiteral(const UnicodeString& s) const;
   1.152 +    void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
   1.153 +    int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); }
   1.154 +    int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
   1.155 +    UBool isPatternSeparator(UnicodeString& field);
   1.156 +    void setFilter(UErrorCode &status);
   1.157 +
   1.158 +private:
   1.159 +   typedef enum TokenStatus {
   1.160 +       START,
   1.161 +       ADD_TOKEN,
   1.162 +       SYNTAX_ERROR,
   1.163 +       DONE
   1.164 +   } ToeknStatus;
   1.165 +
   1.166 +   TokenStatus status;
   1.167 +   virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
   1.168 +};
   1.169 +
   1.170 +class DistanceInfo : public UMemory {
   1.171 +public:
   1.172 +    int32_t missingFieldMask;
   1.173 +    int32_t extraFieldMask;
   1.174 +
   1.175 +    DistanceInfo() {}
   1.176 +    virtual ~DistanceInfo();
   1.177 +    void clear() { missingFieldMask = extraFieldMask = 0; }
   1.178 +    void setTo(DistanceInfo& other);
   1.179 +    void addMissing(int32_t field) { missingFieldMask |= (1<<field); }
   1.180 +    void addExtra(int32_t field) { extraFieldMask |= (1<<field); }
   1.181 +};
   1.182 +
   1.183 +class DateTimeMatcher: public UMemory {
   1.184 +public:
   1.185 +    PtnSkeleton skeleton;
   1.186 +
   1.187 +    void getBasePattern(UnicodeString &basePattern);
   1.188 +    UnicodeString getPattern();
   1.189 +    void set(const UnicodeString& pattern, FormatParser* fp);
   1.190 +    void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);
   1.191 +    void copyFrom(const PtnSkeleton& skeleton);
   1.192 +    void copyFrom();
   1.193 +    PtnSkeleton* getSkeletonPtr();
   1.194 +    UBool equals(const DateTimeMatcher* other) const;
   1.195 +    int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo);
   1.196 +    DateTimeMatcher();
   1.197 +    DateTimeMatcher(const DateTimeMatcher& other);
   1.198 +    virtual ~DateTimeMatcher();
   1.199 +    int32_t getFieldMask();
   1.200 +};
   1.201 +
   1.202 +class PatternMap : public UMemory {
   1.203 +public:
   1.204 +    PtnElem *boot[MAX_PATTERN_ENTRIES];
   1.205 +    PatternMap();
   1.206 +    virtual  ~PatternMap();
   1.207 +    void  add(const UnicodeString& basePattern, const PtnSkeleton& skeleton, const UnicodeString& value, UBool skeletonWasSpecified, UErrorCode& status);
   1.208 +    const UnicodeString* getPatternFromBasePattern(UnicodeString& basePattern, UBool& skeletonWasSpecified);
   1.209 +    const UnicodeString* getPatternFromSkeleton(PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = 0);
   1.210 +    void copyFrom(const PatternMap& other, UErrorCode& status);
   1.211 +    PtnElem* getHeader(UChar baseChar);
   1.212 +    UBool equals(const PatternMap& other);
   1.213 +private:
   1.214 +    UBool isDupAllowed;
   1.215 +    PtnElem*  getDuplicateElem(const UnicodeString &basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
   1.216 +}; // end  PatternMap
   1.217 +
   1.218 +class PatternMapIterator : public UMemory {
   1.219 +public:
   1.220 +    PatternMapIterator();
   1.221 +    virtual ~PatternMapIterator();
   1.222 +    void set(PatternMap& patternMap);
   1.223 +    PtnSkeleton* getSkeleton();
   1.224 +    UBool hasNext();
   1.225 +    DateTimeMatcher& next();
   1.226 +private:
   1.227 +    int32_t bootIndex;
   1.228 +    PtnElem *nodePtr;
   1.229 +    DateTimeMatcher *matcher;
   1.230 +    PatternMap *patternMap;
   1.231 +};
   1.232 +
   1.233 +class DTSkeletonEnumeration : public StringEnumeration {
   1.234 +public:
   1.235 +    DTSkeletonEnumeration(PatternMap &patternMap, dtStrEnum type, UErrorCode& status);
   1.236 +    virtual ~DTSkeletonEnumeration();
   1.237 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.238 +    virtual UClassID getDynamicClassID(void) const;
   1.239 +    virtual const UnicodeString* snext(UErrorCode& status);
   1.240 +    virtual void reset(UErrorCode& status);
   1.241 +    virtual int32_t count(UErrorCode& status) const;
   1.242 +private:
   1.243 +    int32_t pos;
   1.244 +    UBool isCanonicalItem(const UnicodeString& item);
   1.245 +    UVector *fSkeletons;
   1.246 +};
   1.247 +
   1.248 +class DTRedundantEnumeration : public StringEnumeration {
   1.249 +public:
   1.250 +    DTRedundantEnumeration();
   1.251 +    virtual ~DTRedundantEnumeration();
   1.252 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.253 +    virtual UClassID getDynamicClassID(void) const;
   1.254 +    virtual const UnicodeString* snext(UErrorCode& status);
   1.255 +    virtual void reset(UErrorCode& status);
   1.256 +    virtual int32_t count(UErrorCode& status) const;
   1.257 +    void add(const UnicodeString &pattern, UErrorCode& status);
   1.258 +private:
   1.259 +    int32_t pos;
   1.260 +    UBool isCanonicalItem(const UnicodeString& item);
   1.261 +    UVector *fPatterns;
   1.262 +};
   1.263 +
   1.264 +U_NAMESPACE_END
   1.265 +
   1.266 +#endif

mercurial