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
00027 #if U_SHOW_CPLUSPLUS_API
00028
00029 #include "unicode/bytestrie.h"
00030 #include "unicode/stringpiece.h"
00031 #include "unicode/stringtriebuilder.h"
00032
00033 U_NAMESPACE_BEGIN
00034
00035 class BytesTrieElement;
00036 class CharString;
00043 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
00044 public:
00050 BytesTrieBuilder(UErrorCode &errorCode);
00051
00056 virtual ~BytesTrieBuilder();
00057
00072 BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
00073
00092 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00093
00116 StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00117
00124 BytesTrieBuilder &clear();
00125
00126 private:
00127 BytesTrieBuilder(const BytesTrieBuilder &other);
00128 BytesTrieBuilder &operator=(const BytesTrieBuilder &other);
00129
00130 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00131
00132 virtual int32_t getElementStringLength(int32_t i) const;
00133 virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const;
00134 virtual int32_t getElementValue(int32_t i) const;
00135
00136 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;
00137
00138 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;
00139 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;
00140 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const;
00141
00142 virtual UBool matchNodesCanHaveValues() const { return FALSE; }
00143
00144 virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }
00145 virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }
00146 virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }
00147
00151 class BTLinearMatchNode : public LinearMatchNode {
00152 public:
00153 BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
00154 virtual UBool operator==(const Node &other) const;
00155 virtual void write(StringTrieBuilder &builder);
00156 private:
00157 const char *s;
00158 };
00159
00160 virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
00161 Node *nextNode) const;
00162
00163 UBool ensureCapacity(int32_t length);
00164 virtual int32_t write(int32_t byte);
00165 int32_t write(const char *b, int32_t length);
00166 virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);
00167 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
00168 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
00169 virtual int32_t writeDeltaTo(int32_t jumpTarget);
00170
00171 CharString *strings;
00172 BytesTrieElement *elements;
00173 int32_t elementsCapacity;
00174 int32_t elementsLength;
00175
00176
00177
00178 char *bytes;
00179 int32_t bytesCapacity;
00180 int32_t bytesLength;
00181 };
00182
00183 U_NAMESPACE_END
00184
00185 #endif
00186
00187 #endif // __BYTESTRIEBUILDER_H__