Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/bytestriebuilder.h
48729 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3*******************************************************************************4* Copyright (C) 2010-2016, International Business Machines5* Corporation and others. All Rights Reserved.6*******************************************************************************7* file name: bytestriebuilder.h8* encoding: UTF-89* tab size: 8 (not used)10* indentation:411*12* created on: 2010sep2513* created by: Markus W. Scherer14*/1516/**17* \file18* \brief C++ API: Builder for icu::BytesTrie19*/2021#ifndef __BYTESTRIEBUILDER_H__22#define __BYTESTRIEBUILDER_H__2324#include "unicode/utypes.h"25#include "unicode/bytestrie.h"26#include "unicode/stringpiece.h"27#include "unicode/stringtriebuilder.h"2829U_NAMESPACE_BEGIN3031class BytesTrieElement;32class CharString;33/**34* Builder class for BytesTrie.35*36* This class is not intended for public subclassing.37* @stable ICU 4.838*/39class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {40public:41/**42* Constructs an empty builder.43* @param errorCode Standard ICU error code.44* @stable ICU 4.845*/46BytesTrieBuilder(UErrorCode &errorCode);4748/**49* Destructor.50* @stable ICU 4.851*/52virtual ~BytesTrieBuilder();5354/**55* Adds a (byte sequence, value) pair.56* The byte sequence must be unique.57* The bytes will be copied; the builder does not keep58* a reference to the input StringPiece or its data().59* @param s The input byte sequence.60* @param value The value associated with this byte sequence.61* @param errorCode Standard ICU error code. Its input value must62* pass the U_SUCCESS() test, or else the function returns63* immediately. Check for U_FAILURE() on output or use with64* function chaining. (See User Guide for details.)65* @return *this66* @stable ICU 4.867*/68BytesTrieBuilder &add(StringPiece s, int32_t value, UErrorCode &errorCode);6970/**71* Builds a BytesTrie for the add()ed data.72* Once built, no further data can be add()ed until clear() is called.73*74* A BytesTrie cannot be empty. At least one (byte sequence, value) pair75* must have been add()ed.76*77* This method passes ownership of the builder's internal result array to the new trie object.78* Another call to any build() variant will re-serialize the trie.79* After clear() has been called, a new array will be used as well.80* @param buildOption Build option, see UStringTrieBuildOption.81* @param errorCode Standard ICU error code. Its input value must82* pass the U_SUCCESS() test, or else the function returns83* immediately. Check for U_FAILURE() on output or use with84* function chaining. (See User Guide for details.)85* @return A new BytesTrie for the add()ed data.86* @stable ICU 4.887*/88BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);8990/**91* Builds a BytesTrie for the add()ed data and byte-serializes it.92* Once built, no further data can be add()ed until clear() is called.93*94* A BytesTrie cannot be empty. At least one (byte sequence, value) pair95* must have been add()ed.96*97* Multiple calls to buildStringPiece() return StringPieces referring to the98* builder's same byte array, without rebuilding.99* If buildStringPiece() is called after build(), the trie will be100* re-serialized into a new array.101* If build() is called after buildStringPiece(), the trie object will become102* the owner of the previously returned array.103* After clear() has been called, a new array will be used as well.104* @param buildOption Build option, see UStringTrieBuildOption.105* @param errorCode Standard ICU error code. Its input value must106* pass the U_SUCCESS() test, or else the function returns107* immediately. Check for U_FAILURE() on output or use with108* function chaining. (See User Guide for details.)109* @return A StringPiece which refers to the byte-serialized BytesTrie for the add()ed data.110* @stable ICU 4.8111*/112StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);113114/**115* Removes all (byte sequence, value) pairs.116* New data can then be add()ed and a new trie can be built.117* @return *this118* @stable ICU 4.8119*/120BytesTrieBuilder &clear();121122private:123BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor124BytesTrieBuilder &operator=(const BytesTrieBuilder &other); // no assignment operator125126void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);127128virtual int32_t getElementStringLength(int32_t i) const;129virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const;130virtual int32_t getElementValue(int32_t i) const;131132virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const;133134virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const;135virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const;136virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const;137138virtual UBool matchNodesCanHaveValues() const { return FALSE; }139140virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; }141virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; }142virtual int32_t getMaxLinearMatchLength() const { return BytesTrie::kMaxLinearMatchLength; }143144/**145* @internal (private)146*/147class BTLinearMatchNode : public LinearMatchNode {148public:149BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);150virtual UBool operator==(const Node &other) const;151virtual void write(StringTrieBuilder &builder);152private:153const char *s;154};155156virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,157Node *nextNode) const;158159UBool ensureCapacity(int32_t length);160virtual int32_t write(int32_t byte);161int32_t write(const char *b, int32_t length);162virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length);163virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);164virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);165virtual int32_t writeDeltaTo(int32_t jumpTarget);166167CharString *strings; // Pointer not object so we need not #include internal charstr.h.168BytesTrieElement *elements;169int32_t elementsCapacity;170int32_t elementsLength;171172// Byte serialization of the trie.173// Grows from the back: bytesLength measures from the end of the buffer!174char *bytes;175int32_t bytesCapacity;176int32_t bytesLength;177};178179U_NAMESPACE_END180181#endif // __BYTESTRIEBUILDER_H__182183184