ICU-13778 DataTimePatternGenerator code refactor. Handle Out-of-Memory (OOM) errors, use LocalPointer to prevent memory leaks when OOM occurs, use an internal error code to better report errors during clone and copy construction, mark helper methods and parameters as const, use nullptr instead of NULL, minor spelling and formatting changes. (Note: All tests pass on Windows and Linux).
X-SVN-Rev: 41552
This commit is contained in:
parent
3b0a30d6e7
commit
b12a927c93
File diff suppressed because it is too large
Load Diff
@ -116,7 +116,7 @@ typedef struct dtTypeElem {
|
||||
int16_t type;
|
||||
int16_t minLen;
|
||||
int16_t weight;
|
||||
}dtTypeElem;
|
||||
} dtTypeElem;
|
||||
|
||||
// A compact storage mechanism for skeleton field strings. Several dozen of these will be created
|
||||
// for a typical DateTimePatternGenerator instance.
|
||||
@ -172,30 +172,28 @@ public:
|
||||
virtual ~PtnSkeleton();
|
||||
};
|
||||
|
||||
|
||||
class PtnElem : public UMemory {
|
||||
public:
|
||||
UnicodeString basePattern;
|
||||
PtnSkeleton *skeleton;
|
||||
LocalPointer<PtnSkeleton> skeleton;
|
||||
UnicodeString pattern;
|
||||
UBool skeletonWasSpecified; // if specified in availableFormats, not derived
|
||||
PtnElem *next;
|
||||
LocalPointer<PtnElem> next;
|
||||
|
||||
PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
|
||||
virtual ~PtnElem();
|
||||
|
||||
};
|
||||
|
||||
class FormatParser : public UMemory {
|
||||
public:
|
||||
UnicodeString items[MAX_DT_TOKEN];
|
||||
int32_t itemNumber;
|
||||
int32_t itemNumber;
|
||||
|
||||
FormatParser();
|
||||
virtual ~FormatParser();
|
||||
void set(const UnicodeString& patternString);
|
||||
void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
|
||||
UBool isPatternSeparator(UnicodeString& field);
|
||||
UBool isPatternSeparator(const UnicodeString& field) const;
|
||||
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);
|
||||
@ -206,7 +204,7 @@ private:
|
||||
ADD_TOKEN,
|
||||
SYNTAX_ERROR,
|
||||
DONE
|
||||
} ToeknStatus;
|
||||
} TokenStatus;
|
||||
|
||||
TokenStatus status;
|
||||
virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
|
||||
@ -220,7 +218,7 @@ public:
|
||||
DistanceInfo() {}
|
||||
virtual ~DistanceInfo();
|
||||
void clear() { missingFieldMask = extraFieldMask = 0; }
|
||||
void setTo(DistanceInfo& other);
|
||||
void setTo(const DistanceInfo& other);
|
||||
void addMissing(int32_t field) { missingFieldMask |= (1<<field); }
|
||||
void addExtra(int32_t field) { extraFieldMask |= (1<<field); }
|
||||
};
|
||||
@ -237,11 +235,11 @@ public:
|
||||
void copyFrom();
|
||||
PtnSkeleton* getSkeletonPtr();
|
||||
UBool equals(const DateTimeMatcher* other) const;
|
||||
int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo);
|
||||
int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const;
|
||||
DateTimeMatcher();
|
||||
DateTimeMatcher(const DateTimeMatcher& other);
|
||||
virtual ~DateTimeMatcher();
|
||||
int32_t getFieldMask();
|
||||
int32_t getFieldMask() const;
|
||||
};
|
||||
|
||||
class PatternMap : public UMemory {
|
||||
@ -250,34 +248,34 @@ public:
|
||||
PatternMap();
|
||||
virtual ~PatternMap();
|
||||
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);
|
||||
const UnicodeString* getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const;
|
||||
const UnicodeString* getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = 0) const;
|
||||
void copyFrom(const PatternMap& other, UErrorCode& status);
|
||||
PtnElem* getHeader(UChar baseChar);
|
||||
UBool equals(const PatternMap& other);
|
||||
PtnElem* getHeader(UChar baseChar) const;
|
||||
UBool equals(const PatternMap& other) const;
|
||||
private:
|
||||
UBool isDupAllowed;
|
||||
PtnElem* getDuplicateElem(const UnicodeString &basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
|
||||
PtnElem* getDuplicateElem(const UnicodeString& basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
|
||||
}; // end PatternMap
|
||||
|
||||
class PatternMapIterator : public UMemory {
|
||||
public:
|
||||
PatternMapIterator();
|
||||
PatternMapIterator(UErrorCode &status);
|
||||
virtual ~PatternMapIterator();
|
||||
void set(PatternMap& patternMap);
|
||||
PtnSkeleton* getSkeleton();
|
||||
UBool hasNext();
|
||||
PtnSkeleton* getSkeleton() const;
|
||||
UBool hasNext() const;
|
||||
DateTimeMatcher& next();
|
||||
private:
|
||||
int32_t bootIndex;
|
||||
PtnElem *nodePtr;
|
||||
DateTimeMatcher *matcher;
|
||||
LocalPointer<DateTimeMatcher> matcher;
|
||||
PatternMap *patternMap;
|
||||
};
|
||||
|
||||
class DTSkeletonEnumeration : public StringEnumeration {
|
||||
public:
|
||||
DTSkeletonEnumeration(PatternMap &patternMap, dtStrEnum type, UErrorCode& status);
|
||||
DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status);
|
||||
virtual ~DTSkeletonEnumeration();
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
@ -287,7 +285,7 @@ public:
|
||||
private:
|
||||
int32_t pos;
|
||||
UBool isCanonicalItem(const UnicodeString& item);
|
||||
UVector *fSkeletons;
|
||||
LocalPointer<UVector> fSkeletons;
|
||||
};
|
||||
|
||||
class DTRedundantEnumeration : public StringEnumeration {
|
||||
@ -302,8 +300,8 @@ public:
|
||||
void add(const UnicodeString &pattern, UErrorCode& status);
|
||||
private:
|
||||
int32_t pos;
|
||||
UBool isCanonicalItem(const UnicodeString& item);
|
||||
UVector *fPatterns;
|
||||
UBool isCanonicalItem(const UnicodeString& item) const;
|
||||
LocalPointer<UVector> fPatterns;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
@ -542,6 +542,11 @@ private:
|
||||
|
||||
int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
|
||||
|
||||
// Internal error code used for recording/reporting errors that occur during methods that do not
|
||||
// have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
|
||||
// When this is set to an error the object is in an invalid state.
|
||||
UErrorCode internalErrorCode;
|
||||
|
||||
/* internal flags masks for adjustFieldTypes etc. */
|
||||
enum {
|
||||
kDTPGNoFlags = 0,
|
||||
@ -569,11 +574,10 @@ private:
|
||||
#endif // U_HIDE_DRAFT_API
|
||||
void getAppendName(UDateTimePatternField field, UnicodeString& value);
|
||||
UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
|
||||
int32_t getCanonicalIndex(const UnicodeString& field);
|
||||
const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, const PtnSkeleton** specifiedSkeletonPtr = 0);
|
||||
const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
|
||||
UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
|
||||
UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
|
||||
int32_t getTopBitNumber(int32_t foundMask);
|
||||
UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
|
||||
int32_t getTopBitNumber(int32_t foundMask) const;
|
||||
void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
|
||||
UBool isAvailableFormatSet(const UnicodeString &key) const;
|
||||
void copyHashtable(Hashtable *other, UErrorCode &status);
|
||||
|
Loading…
Reference in New Issue
Block a user