#ifdef UCPTRIE_DEBUG
# include <stdio.h>
#endif
#include "unicode/utypes.h"
#include "unicode/ucptrie.h"
#include "unicode/umutablecptrie.h"
#include "unicode/uobject.h"
#include "unicode/utf16.h"
#include "cmemory.h"
#include "uassert.h"
#include "ucptrie_impl.h"
#ifdef OVERFLOW
#undef OVERFLOW
#endif
U_NAMESPACE_BEGIN
namespace {
constexpr int32_t MAX_UNICODE = …;
constexpr int32_t UNICODE_LIMIT = …;
constexpr int32_t BMP_LIMIT = …;
constexpr int32_t ASCII_LIMIT = …;
constexpr int32_t I_LIMIT = …;
constexpr int32_t BMP_I_LIMIT = …;
constexpr int32_t ASCII_I_LIMIT = …;
constexpr int32_t SMALL_DATA_BLOCKS_PER_BMP_BLOCK = …;
constexpr uint8_t ALL_SAME = …;
constexpr uint8_t MIXED = …;
constexpr uint8_t SAME_AS = …;
constexpr int32_t INITIAL_DATA_LENGTH = …;
constexpr int32_t MEDIUM_DATA_LENGTH = …;
constexpr int32_t MAX_DATA_LENGTH = …;
constexpr uint8_t I3_NULL = …;
constexpr uint8_t I3_BMP = …;
constexpr uint8_t I3_16 = …;
constexpr uint8_t I3_18 = …;
constexpr int32_t INDEX_3_18BIT_BLOCK_LENGTH = …;
class AllSameBlocks;
class MixedBlocks;
class MutableCodePointTrie : public UMemory { … };
MutableCodePointTrie::MutableCodePointTrie(uint32_t iniValue, uint32_t errValue, UErrorCode &errorCode) : … { … }
MutableCodePointTrie::MutableCodePointTrie(const MutableCodePointTrie &other, UErrorCode &errorCode) : … { … }
MutableCodePointTrie::~MutableCodePointTrie() { … }
MutableCodePointTrie *MutableCodePointTrie::fromUCPMap(const UCPMap *map, UErrorCode &errorCode) { … }
MutableCodePointTrie *MutableCodePointTrie::fromUCPTrie(const UCPTrie *trie, UErrorCode &errorCode) { … }
void MutableCodePointTrie::clear() { … }
uint32_t MutableCodePointTrie::get(UChar32 c) const { … }
inline uint32_t maybeFilterValue(uint32_t value, uint32_t initialValue, uint32_t nullValue,
UCPMapValueFilter *filter, const void *context) { … }
UChar32 MutableCodePointTrie::getRange(
UChar32 start, UCPMapValueFilter *filter, const void *context,
uint32_t *pValue) const { … }
void
writeBlock(uint32_t *block, uint32_t value) { … }
bool MutableCodePointTrie::ensureHighStart(UChar32 c) { … }
int32_t MutableCodePointTrie::allocDataBlock(int32_t blockLength) { … }
int32_t MutableCodePointTrie::getDataBlock(int32_t i) { … }
void MutableCodePointTrie::set(UChar32 c, uint32_t value, UErrorCode &errorCode) { … }
void
fillBlock(uint32_t *block, UChar32 start, UChar32 limit, uint32_t value) { … }
void MutableCodePointTrie::setRange(UChar32 start, UChar32 end, uint32_t value, UErrorCode &errorCode) { … }
void MutableCodePointTrie::maskValues(uint32_t mask) { … }
template<typename UIntA, typename UIntB>
bool equalBlocks(const UIntA *s, const UIntB *t, int32_t length) { … }
bool allValuesSameAs(const uint32_t *p, int32_t length, uint32_t value) { … }
int32_t findSameBlock(const uint16_t *p, int32_t pStart, int32_t length,
const uint16_t *q, int32_t qStart, int32_t blockLength) { … }
int32_t findAllSameBlock(const uint32_t *p, int32_t start, int32_t limit,
uint32_t value, int32_t blockLength) { … }
template<typename UIntA, typename UIntB>
int32_t getOverlap(const UIntA *p, int32_t length,
const UIntB *q, int32_t qStart, int32_t blockLength) { … }
int32_t getAllSameOverlap(const uint32_t *p, int32_t length, uint32_t value,
int32_t blockLength) { … }
bool isStartOfSomeFastBlock(uint32_t dataOffset, const uint32_t index[], int32_t fastILimit) { … }
UChar32 MutableCodePointTrie::findHighStart() const { … }
class AllSameBlocks { … };
class MixedBlocks { … };
int32_t MutableCodePointTrie::compactWholeDataBlocks(int32_t fastILimit, AllSameBlocks &allSameBlocks) { … }
#ifdef UCPTRIE_DEBUG
#define DEBUG_DO …
#else
#define DEBUG_DO(expr) …
#endif
#ifdef UCPTRIE_DEBUG
int32_t appendValue(char s[], int32_t length, uint32_t value) {
value ^= value >> 16;
value ^= value >> 8;
s[length] = 0xE2;
s[length + 1] = (char)(0xA0 + ((value >> 6) & 3));
s[length + 2] = (char)(0x80 + (value & 0x3F));
return length + 3;
}
void printBlock(const uint32_t *block, int32_t blockLength, uint32_t value,
UChar32 start, int32_t overlap, uint32_t initialValue) {
char s[UCPTRIE_FAST_DATA_BLOCK_LENGTH * 3 + 3];
int32_t length = 0;
int32_t i;
for (i = 0; i < overlap; ++i) {
length = appendValue(s, length, 0);
}
s[length++] = '|';
for (; i < blockLength; ++i) {
if (block != nullptr) {
value = block[i];
}
if (value == initialValue) {
value = 0x40;
}
length = appendValue(s, length, value);
}
s[length] = 0;
start += overlap;
if (start <= 0xffff) {
printf(" %04lX %s|\n", (long)start, s);
} else if (start <= 0xfffff) {
printf(" %5lX %s|\n", (long)start, s);
} else {
printf(" %6lX %s|\n", (long)start, s);
}
}
#endif
int32_t MutableCodePointTrie::compactData(
int32_t fastILimit, uint32_t *newData, int32_t newDataCapacity,
int32_t dataNullIndex, MixedBlocks &mixedBlocks, UErrorCode &errorCode) { … }
int32_t MutableCodePointTrie::compactIndex(int32_t fastILimit, MixedBlocks &mixedBlocks,
UErrorCode &errorCode) { … }
int32_t MutableCodePointTrie::compactTrie(int32_t fastILimit, UErrorCode &errorCode) { … }
UCPTrie *MutableCodePointTrie::build(UCPTrieType type, UCPTrieValueWidth valueWidth, UErrorCode &errorCode) { … }
}
U_NAMESPACE_END
U_NAMESPACE_USE
U_CAPI UMutableCPTrie * U_EXPORT2
umutablecptrie_open(uint32_t initialValue, uint32_t errorValue, UErrorCode *pErrorCode) { … }
U_CAPI UMutableCPTrie * U_EXPORT2
umutablecptrie_clone(const UMutableCPTrie *other, UErrorCode *pErrorCode) { … }
U_CAPI void U_EXPORT2
umutablecptrie_close(UMutableCPTrie *trie) { … }
U_CAPI UMutableCPTrie * U_EXPORT2
umutablecptrie_fromUCPMap(const UCPMap *map, UErrorCode *pErrorCode) { … }
U_CAPI UMutableCPTrie * U_EXPORT2
umutablecptrie_fromUCPTrie(const UCPTrie *trie, UErrorCode *pErrorCode) { … }
U_CAPI uint32_t U_EXPORT2
umutablecptrie_get(const UMutableCPTrie *trie, UChar32 c) { … }
namespace {
UChar32 getRange(const void *trie, UChar32 start,
UCPMapValueFilter *filter, const void *context, uint32_t *pValue) { … }
}
U_CAPI UChar32 U_EXPORT2
umutablecptrie_getRange(const UMutableCPTrie *trie, UChar32 start,
UCPMapRangeOption option, uint32_t surrogateValue,
UCPMapValueFilter *filter, const void *context, uint32_t *pValue) { … }
U_CAPI void U_EXPORT2
umutablecptrie_set(UMutableCPTrie *trie, UChar32 c, uint32_t value, UErrorCode *pErrorCode) { … }
U_CAPI void U_EXPORT2
umutablecptrie_setRange(UMutableCPTrie *trie, UChar32 start, UChar32 end,
uint32_t value, UErrorCode *pErrorCode) { … }
U_CAPI UCPTrie * U_EXPORT2
umutablecptrie_buildImmutable(UMutableCPTrie *trie, UCPTrieType type, UCPTrieValueWidth valueWidth,
UErrorCode *pErrorCode) { … }
#ifdef UCPTRIE_DEBUG
U_CFUNC void umutablecptrie_setName(UMutableCPTrie *trie, const char *name) {
reinterpret_cast<MutableCodePointTrie *>(trie)->name = name;
}
#endif