annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/ucharstriebuilder.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // © 2016 and later: Unicode, Inc. and others.
jpayne@69 2 // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69 3 /*
jpayne@69 4 *******************************************************************************
jpayne@69 5 * Copyright (C) 2010-2016, International Business Machines
jpayne@69 6 * Corporation and others. All Rights Reserved.
jpayne@69 7 *******************************************************************************
jpayne@69 8 * file name: ucharstriebuilder.h
jpayne@69 9 * encoding: UTF-8
jpayne@69 10 * tab size: 8 (not used)
jpayne@69 11 * indentation:4
jpayne@69 12 *
jpayne@69 13 * created on: 2010nov14
jpayne@69 14 * created by: Markus W. Scherer
jpayne@69 15 */
jpayne@69 16
jpayne@69 17 #ifndef __UCHARSTRIEBUILDER_H__
jpayne@69 18 #define __UCHARSTRIEBUILDER_H__
jpayne@69 19
jpayne@69 20 #include "unicode/utypes.h"
jpayne@69 21
jpayne@69 22 #if U_SHOW_CPLUSPLUS_API
jpayne@69 23
jpayne@69 24 #include "unicode/stringtriebuilder.h"
jpayne@69 25 #include "unicode/ucharstrie.h"
jpayne@69 26 #include "unicode/unistr.h"
jpayne@69 27
jpayne@69 28 /**
jpayne@69 29 * \file
jpayne@69 30 * \brief C++ API: Builder for icu::UCharsTrie
jpayne@69 31 */
jpayne@69 32
jpayne@69 33 U_NAMESPACE_BEGIN
jpayne@69 34
jpayne@69 35 class UCharsTrieElement;
jpayne@69 36
jpayne@69 37 /**
jpayne@69 38 * Builder class for UCharsTrie.
jpayne@69 39 *
jpayne@69 40 * This class is not intended for public subclassing.
jpayne@69 41 * @stable ICU 4.8
jpayne@69 42 */
jpayne@69 43 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
jpayne@69 44 public:
jpayne@69 45 /**
jpayne@69 46 * Constructs an empty builder.
jpayne@69 47 * @param errorCode Standard ICU error code.
jpayne@69 48 * @stable ICU 4.8
jpayne@69 49 */
jpayne@69 50 UCharsTrieBuilder(UErrorCode &errorCode);
jpayne@69 51
jpayne@69 52 /**
jpayne@69 53 * Destructor.
jpayne@69 54 * @stable ICU 4.8
jpayne@69 55 */
jpayne@69 56 virtual ~UCharsTrieBuilder();
jpayne@69 57
jpayne@69 58 /**
jpayne@69 59 * Adds a (string, value) pair.
jpayne@69 60 * The string must be unique.
jpayne@69 61 * The string contents will be copied; the builder does not keep
jpayne@69 62 * a reference to the input UnicodeString or its buffer.
jpayne@69 63 * @param s The input string.
jpayne@69 64 * @param value The value associated with this string.
jpayne@69 65 * @param errorCode Standard ICU error code. Its input value must
jpayne@69 66 * pass the U_SUCCESS() test, or else the function returns
jpayne@69 67 * immediately. Check for U_FAILURE() on output or use with
jpayne@69 68 * function chaining. (See User Guide for details.)
jpayne@69 69 * @return *this
jpayne@69 70 * @stable ICU 4.8
jpayne@69 71 */
jpayne@69 72 UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
jpayne@69 73
jpayne@69 74 /**
jpayne@69 75 * Builds a UCharsTrie for the add()ed data.
jpayne@69 76 * Once built, no further data can be add()ed until clear() is called.
jpayne@69 77 *
jpayne@69 78 * A UCharsTrie cannot be empty. At least one (string, value) pair
jpayne@69 79 * must have been add()ed.
jpayne@69 80 *
jpayne@69 81 * This method passes ownership of the builder's internal result array to the new trie object.
jpayne@69 82 * Another call to any build() variant will re-serialize the trie.
jpayne@69 83 * After clear() has been called, a new array will be used as well.
jpayne@69 84 * @param buildOption Build option, see UStringTrieBuildOption.
jpayne@69 85 * @param errorCode Standard ICU error code. Its input value must
jpayne@69 86 * pass the U_SUCCESS() test, or else the function returns
jpayne@69 87 * immediately. Check for U_FAILURE() on output or use with
jpayne@69 88 * function chaining. (See User Guide for details.)
jpayne@69 89 * @return A new UCharsTrie for the add()ed data.
jpayne@69 90 * @stable ICU 4.8
jpayne@69 91 */
jpayne@69 92 UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
jpayne@69 93
jpayne@69 94 /**
jpayne@69 95 * Builds a UCharsTrie for the add()ed data and char16_t-serializes it.
jpayne@69 96 * Once built, no further data can be add()ed until clear() is called.
jpayne@69 97 *
jpayne@69 98 * A UCharsTrie cannot be empty. At least one (string, value) pair
jpayne@69 99 * must have been add()ed.
jpayne@69 100 *
jpayne@69 101 * Multiple calls to buildUnicodeString() set the UnicodeStrings to the
jpayne@69 102 * builder's same char16_t array, without rebuilding.
jpayne@69 103 * If buildUnicodeString() is called after build(), the trie will be
jpayne@69 104 * re-serialized into a new array.
jpayne@69 105 * If build() is called after buildUnicodeString(), the trie object will become
jpayne@69 106 * the owner of the previously returned array.
jpayne@69 107 * After clear() has been called, a new array will be used as well.
jpayne@69 108 * @param buildOption Build option, see UStringTrieBuildOption.
jpayne@69 109 * @param result A UnicodeString which will be set to the char16_t-serialized
jpayne@69 110 * UCharsTrie for the add()ed data.
jpayne@69 111 * @param errorCode Standard ICU error code. Its input value must
jpayne@69 112 * pass the U_SUCCESS() test, or else the function returns
jpayne@69 113 * immediately. Check for U_FAILURE() on output or use with
jpayne@69 114 * function chaining. (See User Guide for details.)
jpayne@69 115 * @return result
jpayne@69 116 * @stable ICU 4.8
jpayne@69 117 */
jpayne@69 118 UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
jpayne@69 119 UErrorCode &errorCode);
jpayne@69 120
jpayne@69 121 /**
jpayne@69 122 * Removes all (string, value) pairs.
jpayne@69 123 * New data can then be add()ed and a new trie can be built.
jpayne@69 124 * @return *this
jpayne@69 125 * @stable ICU 4.8
jpayne@69 126 */
jpayne@69 127 UCharsTrieBuilder &clear() {
jpayne@69 128 strings.remove();
jpayne@69 129 elementsLength=0;
jpayne@69 130 ucharsLength=0;
jpayne@69 131 return *this;
jpayne@69 132 }
jpayne@69 133
jpayne@69 134 private:
jpayne@69 135 UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor
jpayne@69 136 UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator
jpayne@69 137
jpayne@69 138 void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
jpayne@69 139
jpayne@69 140 virtual int32_t getElementStringLength(int32_t i) const;
jpayne@69 141 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const;
jpayne@69 142 virtual int32_t getElementValue(int32_t i) const;
jpayne@69 143
jpayne@69 144 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
jpayne@69 145
jpayne@69 146 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
jpayne@69 147 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
jpayne@69 148 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const;
jpayne@69 149
jpayne@69 150 virtual UBool matchNodesCanHaveValues() const { return TRUE; }
jpayne@69 151
jpayne@69 152 virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
jpayne@69 153 virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
jpayne@69 154 virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
jpayne@69 155
jpayne@69 156 class UCTLinearMatchNode : public LinearMatchNode {
jpayne@69 157 public:
jpayne@69 158 UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
jpayne@69 159 virtual UBool operator==(const Node &other) const;
jpayne@69 160 virtual void write(StringTrieBuilder &builder);
jpayne@69 161 private:
jpayne@69 162 const char16_t *s;
jpayne@69 163 };
jpayne@69 164
jpayne@69 165 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
jpayne@69 166 Node *nextNode) const;
jpayne@69 167
jpayne@69 168 UBool ensureCapacity(int32_t length);
jpayne@69 169 virtual int32_t write(int32_t unit);
jpayne@69 170 int32_t write(const char16_t *s, int32_t length);
jpayne@69 171 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
jpayne@69 172 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
jpayne@69 173 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
jpayne@69 174 virtual int32_t writeDeltaTo(int32_t jumpTarget);
jpayne@69 175
jpayne@69 176 UnicodeString strings;
jpayne@69 177 UCharsTrieElement *elements;
jpayne@69 178 int32_t elementsCapacity;
jpayne@69 179 int32_t elementsLength;
jpayne@69 180
jpayne@69 181 // char16_t serialization of the trie.
jpayne@69 182 // Grows from the back: ucharsLength measures from the end of the buffer!
jpayne@69 183 char16_t *uchars;
jpayne@69 184 int32_t ucharsCapacity;
jpayne@69 185 int32_t ucharsLength;
jpayne@69 186 };
jpayne@69 187
jpayne@69 188 U_NAMESPACE_END
jpayne@69 189
jpayne@69 190 #endif /* U_SHOW_CPLUSPLUS_API */
jpayne@69 191
jpayne@69 192 #endif // __UCHARSTRIEBUILDER_H__