ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 ******************************************************************************* 00003 * Copyright (C) 2010-2011, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************* 00006 * file name: ucharstriebuilder.h 00007 * encoding: US-ASCII 00008 * tab size: 8 (not used) 00009 * indentation:4 00010 * 00011 * created on: 2010nov14 00012 * created by: Markus W. Scherer 00013 */ 00014 00015 #ifndef __UCHARSTRIEBUILDER_H__ 00016 #define __UCHARSTRIEBUILDER_H__ 00017 00018 #include "unicode/utypes.h" 00019 #include "unicode/stringtriebuilder.h" 00020 #include "unicode/ucharstrie.h" 00021 #include "unicode/unistr.h" 00022 00023 U_NAMESPACE_BEGIN 00024 00025 class UCharsTrieElement; 00026 00033 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder { 00034 public: 00040 UCharsTrieBuilder(UErrorCode &errorCode); 00041 00046 virtual ~UCharsTrieBuilder(); 00047 00062 UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode); 00063 00079 UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode); 00080 00102 UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result, 00103 UErrorCode &errorCode); 00104 00111 UCharsTrieBuilder &clear() { 00112 strings.remove(); 00113 elementsLength=0; 00114 ucharsLength=0; 00115 return *this; 00116 } 00117 00118 private: 00119 UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor 00120 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator 00121 00122 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode); 00123 00124 virtual int32_t getElementStringLength(int32_t i) const; 00125 virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const; 00126 virtual int32_t getElementValue(int32_t i) const; 00127 00128 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const; 00129 00130 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const; 00131 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const; 00132 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const; 00133 00134 virtual UBool matchNodesCanHaveValues() const { return TRUE; } 00135 00136 virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; } 00137 virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; } 00138 virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; } 00139 00140 class UCTLinearMatchNode : public LinearMatchNode { 00141 public: 00142 UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode); 00143 virtual UBool operator==(const Node &other) const; 00144 virtual void write(StringTrieBuilder &builder); 00145 private: 00146 const UChar *s; 00147 }; 00148 00149 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, 00150 Node *nextNode) const; 00151 00152 UBool ensureCapacity(int32_t length); 00153 virtual int32_t write(int32_t unit); 00154 int32_t write(const UChar *s, int32_t length); 00155 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length); 00156 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal); 00157 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node); 00158 virtual int32_t writeDeltaTo(int32_t jumpTarget); 00159 00160 UnicodeString strings; 00161 UCharsTrieElement *elements; 00162 int32_t elementsCapacity; 00163 int32_t elementsLength; 00164 00165 // UChar serialization of the trie. 00166 // Grows from the back: ucharsLength measures from the end of the buffer! 00167 UChar *uchars; 00168 int32_t ucharsCapacity; 00169 int32_t ucharsLength; 00170 }; 00171 00172 U_NAMESPACE_END 00173 00174 #endif // __UCHARSTRIEBUILDER_H__