00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00020 #ifndef __BYTESTRIEBUILDER_H__
00021 #define __BYTESTRIEBUILDER_H__
00022
00023 #include "unicode/utypes.h"
00024 #include "unicode/bytestrie.h"
00025 #include "unicode/stringpiece.h"
00026 #include "unicode/stringtriebuilder.h"
00027
00028 U_NAMESPACE_BEGIN
00029
00030 class BytesTrieElement;
00031 class CharString;
00032
00039 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
00040 public:
00046 BytesTrieBuilder(UErrorCode &errorCode);
00047
00052 virtual ~BytesTrieBuilder();
00053
00068 BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
00069
00088 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00089
00112 StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00113
00120 BytesTrieBuilder &clear();
00121
00122 private:
00123 BytesTrieBuilder(const BytesTrieBuilder &other);
00124 BytesTrieBuilder &operator=(const BytesTrieBuilder &other);
00125
00126 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00127
00128 virtual int32_t getElementStringLength(int32_t i) const;
00129 virtual UChar getElementUnit(int32_t i, int32_t byteIndex) const;
00130 virtual int32_t getElementValue(int32_t i) const;
00131
00132 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
00133
00134 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
00135 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
00136 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const;
00137
00138 virtual UBool matchNodesCanHaveValues() const { return FALSE; }
00139
00140 virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
00141 virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
00142 virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
00143
00144
00148 class BTLinearMatchNode : public LinearMatchNode {
00149 public:
00150 BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
00151 virtual UBool operator==(const Node &other) const;
00152 virtual void write(StringTrieBuilder &builder);
00153 private:
00154 const char *s;
00155 };
00156
00157
00158 virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
00159 Node *nextNode) const;
00160
00161 UBool ensureCapacity(int32_t length);
00162 virtual int32_t write(int32_t byte);
00163 int32_t write(const char *b, int32_t length);
00164 virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
00165 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
00166 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
00167 virtual int32_t writeDeltaTo(int32_t jumpTarget);
00168
00169 CharString *strings;
00170 BytesTrieElement *elements;
00171 int32_t elementsCapacity;
00172 int32_t elementsLength;
00173
00174
00175
00176 char *bytes;
00177 int32_t bytesCapacity;
00178 int32_t bytesLength;
00179 };
00180
00181 U_NAMESPACE_END
00182
00183 #endif // __BYTESTRIEBUILDER_H__