00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00022 #ifndef __BYTESTRIEBUILDER_H__
00023 #define __BYTESTRIEBUILDER_H__
00024
00025 #include "unicode/utypes.h"
00026 #include "unicode/bytestrie.h"
00027 #include "unicode/stringpiece.h"
00028 #include "unicode/stringtriebuilder.h"
00029
00030 U_NAMESPACE_BEGIN
00031
00032 class BytesTrieElement;
00033 class CharString;
00040 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
00041 public:
00047 BytesTrieBuilder(UErrorCode &errorCode);
00048
00053 virtual ~BytesTrieBuilder();
00054
00069 BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
00070
00089 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00090
00113 StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00114
00121 BytesTrieBuilder &clear();
00122
00123 private:
00124 BytesTrieBuilder(const BytesTrieBuilder &other);
00125 BytesTrieBuilder &operator=(const BytesTrieBuilder &other);
00126
00127 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00128
00129 virtual int32_t getElementStringLength(int32_t i) const;
00130 virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const;
00131 virtual int32_t getElementValue(int32_t i) const;
00132
00133 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
00134
00135 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
00136 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
00137 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const;
00138
00139 virtual UBool matchNodesCanHaveValues() const { return FALSE; }
00140
00141 virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
00142 virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
00143 virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
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__