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
00119 UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
00120 UErrorCode &errorCode);
00121
00128 UCharsTrieBuilder &clear() {
00129 strings.remove();
00130 elementsLength=0;
00131 ucharsLength=0;
00132 return *this;
00133 }
00134
00135 private:
00136 UCharsTrieBuilder(const UCharsTrieBuilder &other);
00137 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other);
00138
00139 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
00140
00141 virtual int32_t getElementStringLength(int32_t i) const override;
00142 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const override;
00143 virtual int32_t getElementValue(int32_t i) const override;
00144
00145 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const override;
00146
00147 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const override;
00148 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const override;
00149 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const override;
00150
00151 virtual UBool matchNodesCanHaveValues() const override { return true; }
00152
00153 virtual int32_t getMaxBranchLinearSubNodeLength() const override { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
00154 virtual int32_t getMinLinearMatch() const override { return UCharsTrie::kMinLinearMatch; }
00155 virtual int32_t getMaxLinearMatchLength() const override { return UCharsTrie::kMaxLinearMatchLength; }
00156
00157 class UCTLinearMatchNode : public LinearMatchNode {
00158 public:
00159 UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
00160 virtual bool operator==(const Node &other) const override;
00161 virtual void write(StringTrieBuilder &builder) override;
00162 private:
00163 const char16_t *s;
00164 };
00165
00166 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
00167 Node *nextNode) const override;
00168
00169 UBool ensureCapacity(int32_t length);
00170 virtual int32_t write(int32_t unit) override;
00171 int32_t write(const char16_t *s, int32_t length);
00172 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) override;
00173 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
00174 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
00175 virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
00176
00177 UnicodeString strings;
00178 UCharsTrieElement *elements;
00179 int32_t elementsCapacity;
00180 int32_t elementsLength;
00181
00182
00183
00184 char16_t *uchars;
00185 int32_t ucharsCapacity;
00186 int32_t ucharsLength;
00187 };
00188
00189 U_NAMESPACE_END
00190
00191 #endif
00192
00193 #endif // __UCHARSTRIEBUILDER_H__