ICU4C 79
Loading...
Searching...
No Matches
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
25#include "unicode/ucharstrie.h"
26#include "unicode/unistr.h"
27
32
33U_NAMESPACE_BEGIN
34
35class UCharsTrieElement;
36
43class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
44public:
51
57
73 int32_t value,
74 UErrorCode& errorCode) U_LIFETIME_BOUND;
75
95
122 UnicodeString& result U_LIFETIME_BOUND,
123 UErrorCode& errorCode) U_LIFETIME_BOUND;
124
131 UCharsTrieBuilder& clear() U_LIFETIME_BOUND {
132 strings.remove();
133 elementsLength=0;
134 ucharsLength=0;
135 return *this;
136 }
137
138private:
139 UCharsTrieBuilder(const UCharsTrieBuilder &other) = delete; // no copy constructor
140 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other) = delete; // no assignment operator
141
142 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
143
144 virtual int32_t getElementStringLength(int32_t i) const override;
145 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const override;
146 virtual int32_t getElementValue(int32_t i) const override;
147
148 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const override;
149
150 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const override;
151 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const override;
152 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const override;
153
154 virtual UBool matchNodesCanHaveValues() const override { return true; }
155
156 virtual int32_t getMaxBranchLinearSubNodeLength() const override { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
157 virtual int32_t getMinLinearMatch() const override { return UCharsTrie::kMinLinearMatch; }
158 virtual int32_t getMaxLinearMatchLength() const override { return UCharsTrie::kMaxLinearMatchLength; }
159
160 class UCTLinearMatchNode : public LinearMatchNode {
161 public:
162 UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
163 virtual bool operator==(const Node &other) const override;
164 virtual void write(StringTrieBuilder &builder) override;
165 private:
166 const char16_t *s;
167 };
168
169 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
170 Node *nextNode) const override;
171
172 UBool ensureCapacity(int32_t length);
173 virtual int32_t write(int32_t unit) override;
174 int32_t write(const char16_t *s, int32_t length);
175 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) override;
176 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
177 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
178 virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
179
180 UnicodeString strings;
181 UCharsTrieElement *elements;
182 int32_t elementsCapacity;
183 int32_t elementsLength;
184
185 // char16_t serialization of the trie.
186 // Grows from the back: ucharsLength measures from the end of the buffer!
187 char16_t *uchars;
188 int32_t ucharsCapacity;
189 int32_t ucharsLength;
190};
191
192U_NAMESPACE_END
193
194#endif /* U_SHOW_CPLUSPLUS_API */
195
196#endif // __UCHARSTRIEBUILDER_H__
Builder class for UCharsTrie.
UCharsTrieBuilder & add(const UnicodeString &s, int32_t value, UErrorCode &errorCode)
Adds a (string, value) pair.
UCharsTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data.
UnicodeString & buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data and char16_t-serializes it.
virtual ~UCharsTrieBuilder()
Destructor.
UCharsTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
UCharsTrieBuilder & clear()
Removes all (string, value) pairs.
Light-weight, non-const reader class for a UCharsTrie.
Definition ucharstrie.h:53
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: Builder API for trie builders.
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences) to integer values.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
C++ API: Unicode String.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315