ICU 75.1 75.1

ucharstriebuilder.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2010-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: ucharstriebuilder.h
9 * encoding: UTF-8
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2010nov14
14 * created by: Markus W. Scherer
15 */
16
17 #ifndef __UCHARSTRIEBUILDER_H__
18 #define __UCHARSTRIEBUILDER_H__
19
20 #include "unicode/utypes.h"
21
22 #if U_SHOW_CPLUSPLUS_API
23
24 #include "unicode/stringtriebuilder.h"
25 #include "unicode/ucharstrie.h"
26 #include "unicode/unistr.h"
27
33 U_NAMESPACE_BEGIN
34
35 class UCharsTrieElement;
36
43 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
44 public:
50 UCharsTrieBuilder(UErrorCode &errorCode);
51
56 virtual ~UCharsTrieBuilder();
57
72 UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
73
92 UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
93
119 UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
120 UErrorCode &errorCode);
121
128 UCharsTrieBuilder &clear() {
129 strings.remove();
130 elementsLength=0;
131 ucharsLength=0;
132 return *this;
133 }
134
135 private:
136 UCharsTrieBuilder(const UCharsTrieBuilder &other) = delete; // no copy constructor
137 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other) = delete; // no assignment operator
138
139 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
140
141 virtual int32_t getElementStringLength(int32_t i) const override;
142 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const override;
143 virtual int32_t getElementValue(int32_t i) const override;
144
145 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const override;
146
147 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const override;
148 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const override;
149 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const override;
150
151 virtual UBool matchNodesCanHaveValues() const override { return true; }
152
153 virtual int32_t getMaxBranchLinearSubNodeLength() const override { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
154 virtual int32_t getMinLinearMatch() const override { return UCharsTrie::kMinLinearMatch; }
155 virtual int32_t getMaxLinearMatchLength() const override { return UCharsTrie::kMaxLinearMatchLength; }
156
157 class UCTLinearMatchNode : public LinearMatchNode {
158 public:
159 UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
160 virtual bool operator==(const Node &other) const override;
161 virtual void write(StringTrieBuilder &builder) override;
162 private:
163 const char16_t *s;
164 };
165
166 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
167 Node *nextNode) const override;
168
169 UBool ensureCapacity(int32_t length);
170 virtual int32_t write(int32_t unit) override;
171 int32_t write(const char16_t *s, int32_t length);
172 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) override;
173 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
174 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
175 virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
176
177 UnicodeString strings;
178 UCharsTrieElement *elements;
179 int32_t elementsCapacity;
180 int32_t elementsLength;
181
182 // char16_t serialization of the trie.
183 // Grows from the back: ucharsLength measures from the end of the buffer!
184 char16_t *uchars;
185 int32_t ucharsCapacity;
186 int32_t ucharsLength;
187 };
188
189 U_NAMESPACE_END
190
191 #endif /* U_SHOW_CPLUSPLUS_API */
192
193 #endif // __UCHARSTRIEBUILDER_H__
icu::UCharsTrieBuilder
Builder class for UCharsTrie.
Definition: ucharstriebuilder.h:43
icu::UCharsTrieBuilder::build
UCharsTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data.
icu::UCharsTrieBuilder::~UCharsTrieBuilder
virtual ~UCharsTrieBuilder()
Destructor.
icu::UCharsTrieBuilder::buildUnicodeString
UnicodeString & buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data and char16_t-serializes it.
icu::UCharsTrieBuilder::UCharsTrieBuilder
UCharsTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
icu::UCharsTrieBuilder::clear
UCharsTrieBuilder & clear()
Removes all (string, value) pairs.
Definition: ucharstriebuilder.h:128
icu::UCharsTrieBuilder::add
UCharsTrieBuilder & add(const UnicodeString &s, int32_t value, UErrorCode &errorCode)
Adds a (string, value) pair.
icu::UCharsTrie
Light-weight, non-const reader class for a UCharsTrie.
Definition: ucharstrie.h:53
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
stringtriebuilder.h
C++ API: Builder API for trie builders.
UStringTrieBuildOption
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
Definition: stringtriebuilder.h:41
ucharstrie.h
C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences) to integer values.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300