File indexing completed on 2025-01-18 10:13:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef __BYTESTRIEBUILDER_H__
0023 #define __BYTESTRIEBUILDER_H__
0024
0025 #include "unicode/utypes.h"
0026
0027 #if U_SHOW_CPLUSPLUS_API
0028
0029 #include "unicode/bytestrie.h"
0030 #include "unicode/stringpiece.h"
0031 #include "unicode/stringtriebuilder.h"
0032
0033 class BytesTrieTest;
0034
0035 U_NAMESPACE_BEGIN
0036
0037 class BytesTrieElement;
0038 class CharString;
0039
0040
0041
0042
0043
0044
0045 class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
0046 public:
0047
0048
0049
0050
0051
0052 BytesTrieBuilder(UErrorCode &errorCode);
0053
0054
0055
0056
0057
0058 virtual ~BytesTrieBuilder();
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
0120
0121
0122
0123
0124
0125
0126
0127 BytesTrieBuilder &clear();
0128
0129 private:
0130 friend class ::BytesTrieTest;
0131
0132 BytesTrieBuilder(const BytesTrieBuilder &other) = delete;
0133 BytesTrieBuilder &operator=(const BytesTrieBuilder &other) = delete;
0134
0135 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
0136
0137 virtual int32_t getElementStringLength(int32_t i) const override;
0138 virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const override;
0139 virtual int32_t getElementValue(int32_t i) const override;
0140
0141 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const override;
0142
0143 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const override;
0144 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const override;
0145 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const override;
0146
0147 virtual UBool matchNodesCanHaveValues() const override { return false; }
0148
0149 virtual int32_t getMaxBranchLinearSubNodeLength() const override { return BytesTrie::kMaxBranchLinearSubNodeLength; }
0150 virtual int32_t getMinLinearMatch() const override { return BytesTrie::kMinLinearMatch; }
0151 virtual int32_t getMaxLinearMatchLength() const override { return BytesTrie::kMaxLinearMatchLength; }
0152
0153
0154
0155
0156 class BTLinearMatchNode : public LinearMatchNode {
0157 public:
0158 BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
0159 virtual bool operator==(const Node &other) const override;
0160 virtual void write(StringTrieBuilder &builder) override;
0161 private:
0162 const char *s;
0163 };
0164
0165 virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
0166 Node *nextNode) const override;
0167
0168 UBool ensureCapacity(int32_t length);
0169 virtual int32_t write(int32_t byte) override;
0170 int32_t write(const char *b, int32_t length);
0171 virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length) override;
0172 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
0173 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
0174 virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
0175 static int32_t internalEncodeDelta(int32_t i, char intBytes[]);
0176
0177 CharString *strings;
0178 BytesTrieElement *elements;
0179 int32_t elementsCapacity;
0180 int32_t elementsLength;
0181
0182
0183
0184 char *bytes;
0185 int32_t bytesCapacity;
0186 int32_t bytesLength;
0187 };
0188
0189 U_NAMESPACE_END
0190
0191 #endif
0192
0193 #endif