intl/icu/source/common/unicode/ucharstriebuilder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial