2010-12-31 18:21:36 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2011-01-02 07:22:36 +00:00
|
|
|
* Copyright (C) 2010-2011, International Business Machines
|
2010-12-31 18:21:36 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
2011-01-05 21:05:47 +00:00
|
|
|
* file name: ucharstriebuilder.h
|
2010-12-31 18:21:36 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2010nov14
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
#ifndef __UCHARSTRIEBUILDER_H__
|
|
|
|
#define __UCHARSTRIEBUILDER_H__
|
2010-12-31 18:21:36 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unistr.h"
|
2011-01-05 21:05:47 +00:00
|
|
|
#include "stringtriebuilder.h"
|
|
|
|
#include "ucharstrie.h"
|
2010-12-31 18:21:36 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
class UCharsTrieElement;
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
/**
|
|
|
|
* Builder class for UCharsTrie.
|
|
|
|
*/
|
|
|
|
class U_TOOLUTIL_API UCharsTrieBuilder : public StringTrieBuilder {
|
2010-12-31 18:21:36 +00:00
|
|
|
public:
|
2011-01-05 21:05:47 +00:00
|
|
|
UCharsTrieBuilder()
|
2010-12-31 18:21:36 +00:00
|
|
|
: elements(NULL), elementsCapacity(0), elementsLength(0),
|
|
|
|
uchars(NULL), ucharsCapacity(0), ucharsLength(0) {}
|
2011-01-05 21:05:47 +00:00
|
|
|
virtual ~UCharsTrieBuilder();
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
UnicodeString &build(UStringTrieBuildOption buildOption, UnicodeString &result, UErrorCode &errorCode);
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
UCharsTrieBuilder &clear() {
|
2010-12-31 18:21:36 +00:00
|
|
|
strings.remove();
|
|
|
|
elementsLength=0;
|
|
|
|
ucharsLength=0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-01-02 07:22:36 +00:00
|
|
|
virtual int32_t getElementStringLength(int32_t i) const;
|
|
|
|
virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
|
|
|
|
virtual int32_t getElementValue(int32_t i) const;
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-02 07:22:36 +00:00
|
|
|
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-02 07:22:36 +00:00
|
|
|
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
|
|
|
|
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
|
|
|
|
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
|
2010-12-31 23:56:06 +00:00
|
|
|
|
2011-01-02 07:22:36 +00:00
|
|
|
virtual UBool matchNodesCanHaveValues() const { return TRUE; }
|
2010-12-31 23:56:06 +00:00
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
|
|
|
|
virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
|
|
|
|
virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
|
2010-12-31 18:21:36 +00:00
|
|
|
|
|
|
|
class UCTLinearMatchNode : public LinearMatchNode {
|
|
|
|
public:
|
|
|
|
UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
|
|
|
|
virtual UBool operator==(const Node &other) const;
|
2011-01-05 21:05:47 +00:00
|
|
|
virtual void write(StringTrieBuilder &builder);
|
2010-12-31 18:21:36 +00:00
|
|
|
private:
|
|
|
|
const UChar *s;
|
|
|
|
};
|
|
|
|
|
2011-01-02 07:22:36 +00:00
|
|
|
virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
|
|
|
|
Node *nextNode) const;
|
2010-12-31 18:21:36 +00:00
|
|
|
|
2011-01-02 07:22:36 +00:00
|
|
|
UBool ensureCapacity(int32_t length);
|
|
|
|
virtual int32_t write(int32_t unit);
|
|
|
|
int32_t write(const UChar *s, int32_t length);
|
|
|
|
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
|
|
|
|
virtual int32_t writeValueAndFinal(int32_t i, UBool final);
|
|
|
|
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
|
|
|
|
virtual int32_t writeDeltaTo(int32_t jumpTarget);
|
2010-12-31 18:21:36 +00:00
|
|
|
|
|
|
|
UnicodeString strings;
|
2011-01-05 21:05:47 +00:00
|
|
|
UCharsTrieElement *elements;
|
2010-12-31 18:21:36 +00:00
|
|
|
int32_t elementsCapacity;
|
|
|
|
int32_t elementsLength;
|
|
|
|
|
|
|
|
// UChar serialization of the trie.
|
|
|
|
// Grows from the back: ucharsLength measures from the end of the buffer!
|
|
|
|
UChar *uchars;
|
|
|
|
int32_t ucharsCapacity;
|
|
|
|
int32_t ucharsLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2011-01-05 21:05:47 +00:00
|
|
|
#endif // __UCHARSTRIEBUILDER_H__
|