Loading...
Searching...
No Matches
ucharstriebuilder.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2010-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: ucharstriebuilder.h
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2010nov14
* created by: Markus W. Scherer
*/
#ifndef __UCHARSTRIEBUILDER_H__
#define __UCHARSTRIEBUILDER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/stringtriebuilder.h"
#include "unicode/ucharstrie.h"
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
class UCharsTrieElement;
class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
public:
UCharsTrieBuilder(UErrorCode &errorCode);
virtual ~UCharsTrieBuilder();
UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
UErrorCode &errorCode);
UCharsTrieBuilder &clear() {
strings.remove();
elementsLength=0;
ucharsLength=0;
return *this;
}
private:
UCharsTrieBuilder(const UCharsTrieBuilder &other) = delete; // no copy constructor
UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other) = delete; // no assignment operator
void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
virtual int32_t getElementStringLength(int32_t i) const override;
virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const override;
virtual int32_t getElementValue(int32_t i) const override;
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const override;
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const override;
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const override;
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const override;
virtual UBool matchNodesCanHaveValues() const override { return true; }
virtual int32_t getMaxBranchLinearSubNodeLength() const override { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
virtual int32_t getMinLinearMatch() const override { return UCharsTrie::kMinLinearMatch; }
virtual int32_t getMaxLinearMatchLength() const override { return UCharsTrie::kMaxLinearMatchLength; }
class UCTLinearMatchNode : public LinearMatchNode {
public:
UCTLinearMatchNode(const char16_t *units, int32_t len, Node *nextNode);
virtual bool operator==(const Node &other) const override;
virtual void write(StringTrieBuilder &builder) override;
private:
const char16_t *s;
};
virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
Node *nextNode) const override;
UBool ensureCapacity(int32_t length);
virtual int32_t write(int32_t unit) override;
int32_t write(const char16_t *s, int32_t length);
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) override;
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
UnicodeString strings;
UCharsTrieElement *elements;
int32_t elementsCapacity;
int32_t elementsLength;
// char16_t serialization of the trie.
// Grows from the back: ucharsLength measures from the end of the buffer!
char16_t *uchars;
int32_t ucharsCapacity;
int32_t ucharsLength;
};
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __UCHARSTRIEBUILDER_H__
icu::UCharsTrieBuilder
Builder class for UCharsTrie.
Definition ucharstriebuilder.h:43
icu::UCharsTrieBuilder::add
UCharsTrieBuilder & add(const UnicodeString &s, int32_t value, UErrorCode &errorCode)
Adds a (string, value) pair.
icu::UCharsTrieBuilder::build
UCharsTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data.
icu::UCharsTrieBuilder::buildUnicodeString
UnicodeString & buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result, UErrorCode &errorCode)
Builds a UCharsTrie for the add()ed data and char16_t-serializes it.
icu::UCharsTrieBuilder::~UCharsTrieBuilder
virtual ~UCharsTrieBuilder()
Destructor.
icu::UCharsTrieBuilder::UCharsTrieBuilder
UCharsTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
icu::UCharsTrieBuilder::clear
UCharsTrieBuilder & clear()
Removes all (string, value) pairs.
Definition ucharstriebuilder.h:128
icu::UCharsTrie
Light-weight, non-const reader class for a UCharsTrie.
Definition ucharstrie.h:53
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
icu::operator==
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
stringtriebuilder.h
C++ API: Builder API for trie builders.
UStringTrieBuildOption
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
Definition stringtriebuilder.h:41
ucharstrie.h
C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences) to integer values.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315