ICU 52.1  52.1
ucharstriebuilder.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2010-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: ucharstriebuilder.h
7 * encoding: US-ASCII
8 * tab size: 8 (not used)
9 * indentation:4
10 *
11 * created on: 2010nov14
12 * created by: Markus W. Scherer
13 */
14 
15 #ifndef __UCHARSTRIEBUILDER_H__
16 #define __UCHARSTRIEBUILDER_H__
17 
18 #include "unicode/utypes.h"
20 #include "unicode/ucharstrie.h"
21 #include "unicode/unistr.h"
22 
29 
30 class UCharsTrieElement;
31 
39 public:
45  UCharsTrieBuilder(UErrorCode &errorCode);
46 
51  virtual ~UCharsTrieBuilder();
52 
67  UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
68 
87  UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
88 
113  UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
114  UErrorCode &errorCode);
115 
123  strings.remove();
124  elementsLength=0;
125  ucharsLength=0;
126  return *this;
127  }
128 
129 private:
130  UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor
131  UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator
132 
133  void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
134 
135  virtual int32_t getElementStringLength(int32_t i) const;
136  virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
137  virtual int32_t getElementValue(int32_t i) const;
138 
139  virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
140 
141  virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
142  virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
143  virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
144 
145  virtual UBool matchNodesCanHaveValues() const { return TRUE; }
146 
147  virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
148  virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
149  virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
150 
151 #ifndef U_HIDE_INTERNAL_API
152  class UCTLinearMatchNode : public LinearMatchNode {
153  public:
154  UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
155  virtual UBool operator==(const Node &other) const;
156  virtual void write(StringTrieBuilder &builder);
157  private:
158  const UChar *s;
159  };
160 #endif
161 
162  virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
163  Node *nextNode) const;
164 
165  UBool ensureCapacity(int32_t length);
166  virtual int32_t write(int32_t unit);
167  int32_t write(const UChar *s, int32_t length);
168  virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
169  virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
170  virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
171  virtual int32_t writeDeltaTo(int32_t jumpTarget);
172 
173  UnicodeString strings;
174  UCharsTrieElement *elements;
175  int32_t elementsCapacity;
176  int32_t elementsLength;
177 
178  // UChar serialization of the trie.
179  // Grows from the back: ucharsLength measures from the end of the buffer!
180  UChar *uchars;
181  int32_t ucharsCapacity;
182  int32_t ucharsLength;
183 };
184 
186 
187 #endif // __UCHARSTRIEBUILDER_H__