Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/ucharstriebuilder.h
48776 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: ucharstriebuilder.h8* encoding: UTF-89* tab size: 8 (not used)10* indentation:411*12* created on: 2010nov1413* created by: Markus W. Scherer14*/1516#ifndef __UCHARSTRIEBUILDER_H__17#define __UCHARSTRIEBUILDER_H__1819#include "unicode/utypes.h"20#include "unicode/stringtriebuilder.h"21#include "unicode/ucharstrie.h"22#include "unicode/unistr.h"2324/**25* \file26* \brief C++ API: Builder for icu::UCharsTrie27*/2829U_NAMESPACE_BEGIN3031class UCharsTrieElement;3233/**34* Builder class for UCharsTrie.35*36* This class is not intended for public subclassing.37* @stable ICU 4.838*/39class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {40public:41/**42* Constructs an empty builder.43* @param errorCode Standard ICU error code.44* @stable ICU 4.845*/46UCharsTrieBuilder(UErrorCode &errorCode);4748/**49* Destructor.50* @stable ICU 4.851*/52virtual ~UCharsTrieBuilder();5354/**55* Adds a (string, value) pair.56* The string must be unique.57* The string contents will be copied; the builder does not keep58* a reference to the input UnicodeString or its buffer.59* @param s The input string.60* @param value The value associated with this string.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*/68UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);6970/**71* Builds a UCharsTrie for the add()ed data.72* Once built, no further data can be add()ed until clear() is called.73*74* A UCharsTrie cannot be empty. At least one (string, 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 UCharsTrie for the add()ed data.86* @stable ICU 4.887*/88UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);8990/**91* Builds a UCharsTrie for the add()ed data and char16_t-serializes it.92* Once built, no further data can be add()ed until clear() is called.93*94* A UCharsTrie cannot be empty. At least one (string, value) pair95* must have been add()ed.96*97* Multiple calls to buildUnicodeString() set the UnicodeStrings to the98* builder's same char16_t array, without rebuilding.99* If buildUnicodeString() is called after build(), the trie will be100* re-serialized into a new array.101* If build() is called after buildUnicodeString(), 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 result A UnicodeString which will be set to the char16_t-serialized106* UCharsTrie for the add()ed data.107* @param errorCode Standard ICU error code. Its input value must108* pass the U_SUCCESS() test, or else the function returns109* immediately. Check for U_FAILURE() on output or use with110* function chaining. (See User Guide for details.)111* @return result112* @stable ICU 4.8113*/114UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,115UErrorCode &errorCode);116117/**118* Removes all (string, value) pairs.119* New data can then be add()ed and a new trie can be built.120* @return *this121* @stable ICU 4.8122*/123UCharsTrieBuilder &clear() {124strings.remove();125elementsLength=0;126ucharsLength=0;127return *this;128}129130private:131UCharsTrieBuilder(const UCharsTrieBuilder &other); // no copy constructor132UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other); // no assignment operator133134void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);135136virtual int32_t getElementStringLength(int32_t i) const;137virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const;138virtual int32_t getElementValue(int32_t i) const;139140virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;141142virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;143virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;144virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const;145146virtual UBool matchNodesCanHaveValues() const { return TRUE; }147148virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }149virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }150virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }151152class UCTLinearMatchNode : public LinearMatchNode {153public:154UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);155virtual UBool operator==(const Node &other) const;156virtual void write(StringTrieBuilder &builder);157private:158const char16_t *s;159};160161virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,162Node *nextNode) const;163164UBool ensureCapacity(int32_t length);165virtual int32_t write(int32_t unit);166int32_t write(const char16_t *s, int32_t length);167virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);168virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);169virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);170virtual int32_t writeDeltaTo(int32_t jumpTarget);171172UnicodeString strings;173UCharsTrieElement *elements;174int32_t elementsCapacity;175int32_t elementsLength;176177// char16_t serialization of the trie.178// Grows from the back: ucharsLength measures from the end of the buffer!179char16_t *uchars;180int32_t ucharsCapacity;181int32_t ucharsLength;182};183184U_NAMESPACE_END185186#endif // __UCHARSTRIEBUILDER_H__187188189