00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __UCHARSTRIEBUILDER_H__
00018 #define __UCHARSTRIEBUILDER_H__
00019
00020 #include "unicode/utypes.h"
00021
00022 #if U_SHOW_CPLUSPLUS_API
00023
00024 #include "unicode/stringtriebuilder.h"
00025 #include "unicode/ucharstrie.h"
00026 #include "unicode/unistr.h"
00027
00033 U_NAMESPACE_BEGIN
00034
00035 class UCharsTrieElement;
00036
00043 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
00044 public:
00050 UCharsTrieBuilder(UErrorCode &errorCode);
00051
00056 virtual ~UCharsTrieBuilder();
00057
00072 UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
00073
00092 UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00093
00118 UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
00119 UErrorCode &errorCode);
00120
00127 UCharsTrieBuilder &clear() {
00128 strings.remove();
00129 elementsLength=0;
00130 ucharsLength=0;
00131 return *this;
00132 }
00133
00134 private:
00135 UCharsTrieBuilder(const UCharsTrieBuilder &other);
00136 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other);
00137
00138 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00139
00140 virtual int32_t getElementStringLength(int32_t i) const;
00141 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const;
00142 virtual int32_t getElementValue(int32_t i) const;
00143
00144 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
00145
00146 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
00147 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
00148 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const;
00149
00150 virtual UBool matchNodesCanHaveValues() const { return TRUE; }
00151
00152 virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
00153 virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
00154 virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
00155
00156 class UCTLinearMatchNode : public LinearMatchNode {
00157 public:
00158 UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
00159 virtual UBool operator==(const Node &other) const;
00160 virtual void write(StringTrieBuilder &builder);
00161 private:
00162 const char16_t *s;
00163 };
00164
00165 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
00166 Node *nextNode) const;
00167
00168 UBool ensureCapacity(int32_t length);
00169 virtual int32_t write(int32_t unit);
00170 int32_t write(const char16_t *s, int32_t length);
00171 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
00172 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
00173 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
00174 virtual int32_t writeDeltaTo(int32_t jumpTarget);
00175
00176 UnicodeString strings;
00177 UCharsTrieElement *elements;
00178 int32_t elementsCapacity;
00179 int32_t elementsLength;
00180
00181
00182
00183 char16_t *uchars;
00184 int32_t ucharsCapacity;
00185 int32_t ucharsLength;
00186 };
00187
00188 U_NAMESPACE_END
00189
00190 #endif
00191
00192 #endif // __UCHARSTRIEBUILDER_H__