ICU 49.1.1
49.1.1
|
00001 /* 00002 ******************************************************************************* 00003 * Copyright (C) 2010-2012, 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 #ifndef U_HIDE_INTERNAL_API 00141 class UCTLinearMatchNode : public LinearMatchNode { 00142 public: 00143 UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode); 00144 virtual UBool operator==(const Node &other) const; 00145 virtual void write(StringTrieBuilder &builder); 00146 private: 00147 const UChar *s; 00148 }; 00149 #endif 00150 00151 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, 00152 Node *nextNode) const; 00153 00154 UBool ensureCapacity(int32_t length); 00155 virtual int32_t write(int32_t unit); 00156 int32_t write(const UChar *s, int32_t length); 00157 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length); 00158 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal); 00159 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node); 00160 virtual int32_t writeDeltaTo(int32_t jumpTarget); 00161 00162 UnicodeString strings; 00163 UCharsTrieElement *elements; 00164 int32_t elementsCapacity; 00165 int32_t elementsLength; 00166 00167 // UChar serialization of the trie. 00168 // Grows from the back: ucharsLength measures from the end of the buffer! 00169 UChar *uchars; 00170 int32_t ucharsCapacity; 00171 int32_t ucharsLength; 00172 }; 00173 00174 U_NAMESPACE_END 00175 00176 #endif // __UCHARSTRIEBUILDER_H__