ICU-8167 move string tries to the common library and make API headers public
X-SVN-Rev: 29531
This commit is contained in:
parent
32ca14d226
commit
d55e005cf7
@ -85,7 +85,10 @@ ucnv_u7.o ucnv_u8.o ucnv_u16.o ucnv_u32.o ucnvscsu.o ucnvbocu.o \
|
||||
ucnv_ext.o ucnvmbcs.o ucnv2022.o ucnvhz.o ucnv_lmb.o ucnvisci.o ucnvdisp.o ucnv_set.o ucnv_ct.o \
|
||||
uresbund.o ures_cnv.o uresdata.o resbund.o resbund_cnv.o \
|
||||
ucat.o locmap.o uloc.o locid.o locutil.o locavailable.o locdispnames.o loclikely.o locresdata.o \
|
||||
bytestream.o stringpiece.o bytestrie.o bytestrieiterator.o \
|
||||
bytestream.o stringpiece.o \
|
||||
stringtriebuilder.o bytestriebuilder.o \
|
||||
bytestrie.o bytestrieiterator.o \
|
||||
ucharstrie.o ucharstriebuilder.o ucharstrieiterator.o \
|
||||
appendable.o ustr_cnv.o unistr_cnv.o unistr.o unistr_case.o unistr_props.o \
|
||||
utf_impl.o ustring.o ustrcase.o ucasemap.o cstring.o ustrfmt.o ustrtrns.o ustr_wcs.o utext.o \
|
||||
normalizer2impl.o normalizer2.o filterednormalizer2.o normlzr.o unorm.o unormcmp.o unorm_it.o \
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestream.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "cmemory.h"
|
||||
#include "uassert.h"
|
||||
#include "bytestrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
|
@ -13,12 +13,14 @@
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/bytestriebuilder.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "bytestrie.h"
|
||||
#include "bytestriebuilder.h"
|
||||
#include "charstr.h"
|
||||
#include "cmemory.h"
|
||||
#include "uhash.h"
|
||||
#include "uarrsort.h"
|
||||
#include "uassert.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -121,11 +123,20 @@ BytesTrieElement::compareStringTo(const BytesTrieElement &other, const CharStrin
|
||||
return diff!=0 ? diff : lengthDiff;
|
||||
}
|
||||
|
||||
BytesTrieBuilder::BytesTrieBuilder(UErrorCode & /*errorCode*/)
|
||||
: elements(NULL), elementsCapacity(0), elementsLength(0),
|
||||
bytes(NULL), bytesCapacity(0), bytesLength(0) {}
|
||||
BytesTrieBuilder::BytesTrieBuilder(UErrorCode &errorCode)
|
||||
: strings(NULL), elements(NULL), elementsCapacity(0), elementsLength(0),
|
||||
bytes(NULL), bytesCapacity(0), bytesLength(0) {
|
||||
if(U_FAILURE(errorCode)) {
|
||||
return;
|
||||
}
|
||||
strings=new CharString();
|
||||
if(strings==NULL) {
|
||||
errorCode=U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
BytesTrieBuilder::~BytesTrieBuilder() {
|
||||
delete strings;
|
||||
delete[] elements;
|
||||
uprv_free(bytes);
|
||||
}
|
||||
@ -158,7 +169,7 @@ BytesTrieBuilder::add(const StringPiece &s, int32_t value, UErrorCode &errorCode
|
||||
elements=newElements;
|
||||
elementsCapacity=newCapacity;
|
||||
}
|
||||
elements[elementsLength++].setTo(s, value, strings, errorCode);
|
||||
elements[elementsLength++].setTo(s, value, *strings, errorCode);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -215,16 +226,16 @@ BytesTrieBuilder::buildBytes(UStringTrieBuildOption buildOption, UErrorCode &err
|
||||
return;
|
||||
}
|
||||
uprv_sortArray(elements, elementsLength, (int32_t)sizeof(BytesTrieElement),
|
||||
compareElementStrings, &strings,
|
||||
compareElementStrings, strings,
|
||||
FALSE, // need not be a stable sort
|
||||
&errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
return;
|
||||
}
|
||||
// Duplicate strings are not allowed.
|
||||
StringPiece prev=elements[0].getString(strings);
|
||||
StringPiece prev=elements[0].getString(*strings);
|
||||
for(int32_t i=1; i<elementsLength; ++i) {
|
||||
StringPiece current=elements[i].getString(strings);
|
||||
StringPiece current=elements[i].getString(*strings);
|
||||
if(prev==current) {
|
||||
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
@ -234,7 +245,7 @@ BytesTrieBuilder::buildBytes(UStringTrieBuildOption buildOption, UErrorCode &err
|
||||
}
|
||||
// Create and byte-serialize the trie for the elements.
|
||||
bytesLength=0;
|
||||
int32_t capacity=strings.length();
|
||||
int32_t capacity=strings->length();
|
||||
if(capacity<1024) {
|
||||
capacity=1024;
|
||||
}
|
||||
@ -254,14 +265,22 @@ BytesTrieBuilder::buildBytes(UStringTrieBuildOption buildOption, UErrorCode &err
|
||||
}
|
||||
}
|
||||
|
||||
BytesTrieBuilder &
|
||||
BytesTrieBuilder::clear() {
|
||||
strings->clear();
|
||||
elementsLength=0;
|
||||
bytesLength=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int32_t
|
||||
BytesTrieBuilder::getElementStringLength(int32_t i) const {
|
||||
return elements[i].getStringLength(strings);
|
||||
return elements[i].getStringLength(*strings);
|
||||
}
|
||||
|
||||
UChar
|
||||
BytesTrieBuilder::getElementUnit(int32_t i, int32_t byteIndex) const {
|
||||
return (uint8_t)elements[i].charAt(byteIndex, strings);
|
||||
return (uint8_t)elements[i].charAt(byteIndex, *strings);
|
||||
}
|
||||
|
||||
int32_t
|
||||
@ -273,10 +292,10 @@ int32_t
|
||||
BytesTrieBuilder::getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const {
|
||||
const BytesTrieElement &firstElement=elements[first];
|
||||
const BytesTrieElement &lastElement=elements[last];
|
||||
int32_t minStringLength=firstElement.getStringLength(strings);
|
||||
int32_t minStringLength=firstElement.getStringLength(*strings);
|
||||
while(++byteIndex<minStringLength &&
|
||||
firstElement.charAt(byteIndex, strings)==
|
||||
lastElement.charAt(byteIndex, strings)) {}
|
||||
firstElement.charAt(byteIndex, *strings)==
|
||||
lastElement.charAt(byteIndex, *strings)) {}
|
||||
return byteIndex;
|
||||
}
|
||||
|
||||
@ -285,8 +304,8 @@ BytesTrieBuilder::countElementUnits(int32_t start, int32_t limit, int32_t byteIn
|
||||
int32_t length=0; // Number of different bytes at byteIndex.
|
||||
int32_t i=start;
|
||||
do {
|
||||
char byte=elements[i++].charAt(byteIndex, strings);
|
||||
while(i<limit && byte==elements[i].charAt(byteIndex, strings)) {
|
||||
char byte=elements[i++].charAt(byteIndex, *strings);
|
||||
while(i<limit && byte==elements[i].charAt(byteIndex, *strings)) {
|
||||
++i;
|
||||
}
|
||||
++length;
|
||||
@ -297,8 +316,8 @@ BytesTrieBuilder::countElementUnits(int32_t start, int32_t limit, int32_t byteIn
|
||||
int32_t
|
||||
BytesTrieBuilder::skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const {
|
||||
do {
|
||||
char byte=elements[i++].charAt(byteIndex, strings);
|
||||
while(byte==elements[i].charAt(byteIndex, strings)) {
|
||||
char byte=elements[i++].charAt(byteIndex, *strings);
|
||||
while(byte==elements[i].charAt(byteIndex, *strings)) {
|
||||
++i;
|
||||
}
|
||||
} while(--count>0);
|
||||
@ -308,7 +327,7 @@ BytesTrieBuilder::skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t
|
||||
int32_t
|
||||
BytesTrieBuilder::indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, UChar byte) const {
|
||||
char b=(char)byte;
|
||||
while(b==elements[i].charAt(byteIndex, strings)) {
|
||||
while(b==elements[i].charAt(byteIndex, *strings)) {
|
||||
++i;
|
||||
}
|
||||
return i;
|
||||
@ -343,7 +362,7 @@ StringTrieBuilder::Node *
|
||||
BytesTrieBuilder::createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
|
||||
Node *nextNode) const {
|
||||
return new BTLinearMatchNode(
|
||||
elements[i].getString(strings).data()+byteIndex,
|
||||
elements[i].getString(*strings).data()+byteIndex,
|
||||
length,
|
||||
nextNode);
|
||||
}
|
||||
@ -397,7 +416,7 @@ BytesTrieBuilder::write(const char *b, int32_t length) {
|
||||
|
||||
int32_t
|
||||
BytesTrieBuilder::writeElementUnits(int32_t i, int32_t byteIndex, int32_t length) {
|
||||
return write(elements[i].getString(strings).data()+byteIndex, length);
|
||||
return write(elements[i].getString(*strings).data()+byteIndex, length);
|
||||
}
|
||||
|
||||
int32_t
|
@ -13,8 +13,8 @@
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "bytestrie.h"
|
||||
#include "charstr.h"
|
||||
#include "uvectr32.h"
|
||||
|
||||
|
@ -402,6 +402,7 @@
|
||||
<ClCompile Include="appendable.cpp" />
|
||||
<ClCompile Include="bytestream.cpp" />
|
||||
<ClCompile Include="bytestrie.cpp" />
|
||||
<ClCompile Include="bytestriebuilder.cpp" />
|
||||
<ClCompile Include="bytestrieiterator.cpp" />
|
||||
<ClCompile Include="chariter.cpp" />
|
||||
<ClCompile Include="charstr.cpp" />
|
||||
@ -409,7 +410,11 @@
|
||||
<ClCompile Include="cwchar.c" />
|
||||
<ClCompile Include="schriter.cpp" />
|
||||
<ClCompile Include="stringpiece.cpp" />
|
||||
<ClCompile Include="stringtriebuilder.cpp" />
|
||||
<ClCompile Include="ucasemap.c" />
|
||||
<ClCompile Include="ucharstrie.cpp" />
|
||||
<ClCompile Include="ucharstriebuilder.cpp" />
|
||||
<ClCompile Include="ucharstrieiterator.cpp" />
|
||||
<ClCompile Include="uchriter.cpp" />
|
||||
<ClCompile Include="uinvchar.c" />
|
||||
<ClCompile Include="uiter.cpp" />
|
||||
@ -559,7 +564,6 @@
|
||||
<ClInclude Include="uhash.h" />
|
||||
<ClInclude Include="ulist.h" />
|
||||
<ClInclude Include="ustrenum.h" />
|
||||
<ClInclude Include="ustringtrie.h" />
|
||||
<ClInclude Include="utrie.h" />
|
||||
<ClInclude Include="utrie2.h" />
|
||||
<ClInclude Include="utrie2_impl.h" />
|
||||
@ -1383,7 +1387,34 @@
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="bytestrie.h" />
|
||||
<CustomBuild Include="unicode\bytestrie.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\bytestriebuilder.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\chariter.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
@ -1440,6 +1471,20 @@
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\stringtriebuilder.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
@ -1454,6 +1499,34 @@
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\ucharstrie.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\ucharstriebuilder.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
@ -1527,6 +1600,20 @@
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\ustringtrie.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
|
@ -13,8 +13,8 @@
|
||||
#define PROPNAME_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/uchar.h"
|
||||
#include "bytestrie.h"
|
||||
#include "udataswp.h"
|
||||
#include "uprops.h"
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include <typeinfo> // for 'typeid' to work
|
||||
#include "unicode/utypes.h"
|
||||
#include "stringtriebuilder.h"
|
||||
#include "unicode/stringtriebuilder.h"
|
||||
#include "uassert.h"
|
||||
#include "uhash.h"
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/appendable.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "cmemory.h"
|
||||
#include "uassert.h"
|
||||
#include "ucharstrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
@ -13,12 +13,14 @@
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/ucharstriebuilder.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "cmemory.h"
|
||||
#include "uarrsort.h"
|
||||
#include "ucharstrie.h"
|
||||
#include "ucharstriebuilder.h"
|
||||
#include "uassert.h"
|
||||
#include "uhash.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
@ -13,8 +13,8 @@
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "ucharstrie.h"
|
||||
#include "uvectr32.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
@ -23,8 +23,7 @@
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "uassert.h"
|
||||
#include "ustringtrie.h"
|
||||
#include "unicode/ustringtrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -44,6 +43,7 @@ class UVector32;
|
||||
* There is no assignment operator.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API BytesTrie : public UMemory {
|
||||
public:
|
||||
@ -59,6 +59,7 @@ public:
|
||||
* the BytesTrie object is in use.
|
||||
*
|
||||
* @param trieBytes The byte array that contains the serialized trie.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrie(const void *trieBytes)
|
||||
: ownedArray_(NULL), bytes_(reinterpret_cast<const uint8_t *>(trieBytes)),
|
||||
@ -66,13 +67,15 @@ public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
~BytesTrie();
|
||||
|
||||
/**
|
||||
* Copy constructor, copies the other trie reader object and its state,
|
||||
* but not the byte array which will be shared. (Shallow copy.)
|
||||
* @param Another BytesTrie object.
|
||||
* @param other Another BytesTrie object.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrie(const BytesTrie &other)
|
||||
: ownedArray_(NULL), bytes_(other.bytes_),
|
||||
@ -80,6 +83,8 @@ public:
|
||||
|
||||
/**
|
||||
* Resets this trie to its initial state.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrie &reset() {
|
||||
pos_=bytes_;
|
||||
@ -90,9 +95,14 @@ public:
|
||||
/**
|
||||
* BytesTrie state object, for saving a trie's current state
|
||||
* and resetting the trie back to this state later.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class State : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty State.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
State() { bytes=NULL; }
|
||||
private:
|
||||
friend class BytesTrie;
|
||||
@ -104,7 +114,10 @@ public:
|
||||
|
||||
/**
|
||||
* Saves the state of this trie.
|
||||
* @param state The State object to hold the trie's state.
|
||||
* @return *this
|
||||
* @see resetToState
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
const BytesTrie &saveState(State &state) const {
|
||||
state.bytes=bytes_;
|
||||
@ -117,8 +130,11 @@ public:
|
||||
* Resets this trie to the saved state.
|
||||
* If the state object contains no state, or the state of a different trie,
|
||||
* then this trie remains unchanged.
|
||||
* @param state The State object which holds a saved trie state.
|
||||
* @return *this
|
||||
* @see saveState
|
||||
* @see reset
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrie &resetToState(const State &state) {
|
||||
if(bytes_==state.bytes && bytes_!=NULL) {
|
||||
@ -132,6 +148,7 @@ public:
|
||||
* Determines whether the byte sequence so far matches, whether it has a value,
|
||||
* and whether another input byte can continue a matching byte sequence.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult current() const;
|
||||
|
||||
@ -141,6 +158,7 @@ public:
|
||||
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
|
||||
* Values below -0x100 and above 0xff will never match.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UStringTrieResult first(int32_t inByte) {
|
||||
remainingMatchLength_=-1;
|
||||
@ -155,6 +173,7 @@ public:
|
||||
* @param inByte Input byte value. Values -0x100..-1 are treated like 0..0xff.
|
||||
* Values below -0x100 and above 0xff will never match.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(int32_t inByte);
|
||||
|
||||
@ -168,7 +187,10 @@ public:
|
||||
* result=next(c);
|
||||
* return result;
|
||||
* \endcode
|
||||
* @param s A string or byte sequence. Can be NULL if length is 0.
|
||||
* @param length The length of the byte sequence. Can be -1 if NUL-terminated.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(const char *s, int32_t length);
|
||||
|
||||
@ -178,11 +200,13 @@ public:
|
||||
* getValue() can be called multiple times.
|
||||
*
|
||||
* Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!
|
||||
* @return The value for the byte sequence so far.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline int32_t getValue() const {
|
||||
const uint8_t *pos=pos_;
|
||||
int32_t leadByte=*pos++;
|
||||
U_ASSERT(leadByte>=kMinValueLead);
|
||||
// U_ASSERT(leadByte>=kMinValueLead);
|
||||
return readValue(pos, leadByte>>1);
|
||||
}
|
||||
|
||||
@ -193,6 +217,7 @@ public:
|
||||
* (output-only)
|
||||
* @return TRUE if all byte sequences reachable from the current state
|
||||
* map to the same value.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UBool hasUniqueValue(int32_t &uniqueValue) const {
|
||||
const uint8_t *pos=pos_;
|
||||
@ -206,11 +231,13 @@ public:
|
||||
* @param out Each next byte is appended to this object.
|
||||
* (Only uses the out.Append(s, length) method.)
|
||||
* @return the number of bytes which continue the byte sequence from here
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
int32_t getNextBytes(ByteSink &out) const;
|
||||
|
||||
/**
|
||||
* Iterator for all of the (byte sequence, value) pairs in a BytesTrie.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_COMMON_API Iterator : public UMemory {
|
||||
public:
|
||||
@ -223,6 +250,7 @@ public:
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator(const void *trieBytes, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
@ -235,18 +263,26 @@ public:
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator(const BytesTrie &trie, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
~Iterator();
|
||||
|
||||
/**
|
||||
* Resets this iterator to its initial state.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator &reset();
|
||||
|
||||
/**
|
||||
* @return TRUE if there are more elements.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UBool hasNext() const;
|
||||
|
||||
@ -257,16 +293,23 @@ public:
|
||||
* have a real value, then the value is set to -1.
|
||||
* In this case, this "not a real value" is indistinguishable from
|
||||
* a real value of -1.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return TRUE if there is another element.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UBool next(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* @return The NUL-terminated byte sequence for the last successful next().
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
const StringPiece &getString() const { return sp_; }
|
||||
/**
|
||||
* @return The value for the last successful next().
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
int32_t getValue() const { return value_; }
|
||||
|
||||
@ -321,7 +364,7 @@ private:
|
||||
// pos is already after the leadByte, and the lead byte is already shifted right by 1.
|
||||
static int32_t readValue(const uint8_t *pos, int32_t leadByte);
|
||||
static inline const uint8_t *skipValue(const uint8_t *pos, int32_t leadByte) {
|
||||
U_ASSERT(leadByte>=kMinValueLead);
|
||||
// U_ASSERT(leadByte>=kMinValueLead);
|
||||
if(leadByte>=(kMinTwoByteValueLead<<1)) {
|
||||
if(leadByte<(kMinThreeByteValueLead<<1)) {
|
||||
++pos;
|
@ -16,30 +16,33 @@
|
||||
#define __BYTESTRIEBUILDER_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "bytestrie.h"
|
||||
#include "charstr.h"
|
||||
#include "stringtriebuilder.h"
|
||||
#include "unicode/stringtriebuilder.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class BytesTrieElement;
|
||||
class CharString;
|
||||
|
||||
/**
|
||||
* Builder class for BytesTrie.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_TOOLUTIL_API BytesTrieBuilder : public StringTrieBuilder {
|
||||
class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty builder.
|
||||
* @param errorCode Standard ICU error code.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
virtual ~BytesTrieBuilder();
|
||||
|
||||
@ -55,6 +58,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder &add(const StringPiece &s, int32_t value, UErrorCode &errorCode);
|
||||
|
||||
@ -71,6 +75,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return A new BytesTrie for the add()ed data.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
@ -91,6 +96,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return A StringPiece which refers to the byte-serialized BytesTrie for the add()ed data.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
@ -98,13 +104,9 @@ public:
|
||||
* Removes all (byte sequence, value) pairs.
|
||||
* New data can then be add()ed and a new trie can be built.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
BytesTrieBuilder &clear() {
|
||||
strings.clear();
|
||||
elementsLength=0;
|
||||
bytesLength=0;
|
||||
return *this;
|
||||
}
|
||||
BytesTrieBuilder &clear();
|
||||
|
||||
private:
|
||||
BytesTrieBuilder(const BytesTrieBuilder &other); // no copy constructor
|
||||
@ -148,7 +150,7 @@ private:
|
||||
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
|
||||
virtual int32_t writeDeltaTo(int32_t jumpTarget);
|
||||
|
||||
CharString strings;
|
||||
CharString *strings; // Pointer not object so we need not #include internal charstr.h.
|
||||
BytesTrieElement *elements;
|
||||
int32_t elementsCapacity;
|
||||
int32_t elementsLength;
|
@ -17,14 +17,19 @@
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "uhash.h"
|
||||
|
||||
// Forward declaration.
|
||||
struct UHashtable;
|
||||
typedef struct UHashtable UHashtable;
|
||||
|
||||
/**
|
||||
* Build options for BytesTrieBuilder and CharsTrieBuilder.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
enum UStringTrieBuildOption {
|
||||
/**
|
||||
* Builds a trie quickly.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_BUILD_FAST,
|
||||
/**
|
||||
@ -35,6 +40,7 @@ enum UStringTrieBuildOption {
|
||||
* This option can be effective when many integer values are the same
|
||||
* and string/byte sequence suffixes can be shared.
|
||||
* Runtime speed is not expected to improve.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_BUILD_SMALL
|
||||
};
|
||||
@ -45,8 +51,9 @@ U_NAMESPACE_BEGIN
|
||||
* Base class for string trie builder classes.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_TOOLUTIL_API StringTrieBuilder : public UObject {
|
||||
class U_COMMON_API StringTrieBuilder : public UObject {
|
||||
public:
|
||||
/** @internal */
|
||||
static UBool hashNode(const void *node);
|
@ -24,8 +24,7 @@
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/uobject.h"
|
||||
#include "uassert.h"
|
||||
#include "ustringtrie.h"
|
||||
#include "unicode/ustringtrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -44,8 +43,9 @@ class UVector32;
|
||||
* There is no assignment operator.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_TOOLUTIL_API UCharsTrie : public UMemory {
|
||||
class U_COMMON_API UCharsTrie : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructs a UCharsTrie reader instance.
|
||||
@ -59,6 +59,7 @@ public:
|
||||
* the UCharsTrie object is in use.
|
||||
*
|
||||
* @param trieUChars The UChar array that contains the serialized trie.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrie(const UChar *trieUChars)
|
||||
: ownedArray_(NULL), uchars_(trieUChars),
|
||||
@ -66,13 +67,15 @@ public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
~UCharsTrie();
|
||||
|
||||
/**
|
||||
* Copy constructor, copies the other trie reader object and its state,
|
||||
* but not the UChar array which will be shared. (Shallow copy.)
|
||||
* @param Another UCharsTrie object.
|
||||
* @param other Another UCharsTrie object.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrie(const UCharsTrie &other)
|
||||
: ownedArray_(NULL), uchars_(other.uchars_),
|
||||
@ -80,6 +83,8 @@ public:
|
||||
|
||||
/**
|
||||
* Resets this trie to its initial state.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrie &reset() {
|
||||
pos_=uchars_;
|
||||
@ -90,9 +95,14 @@ public:
|
||||
/**
|
||||
* UCharsTrie state object, for saving a trie's current state
|
||||
* and resetting the trie back to this state later.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class State : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty State.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
State() { uchars=NULL; }
|
||||
private:
|
||||
friend class UCharsTrie;
|
||||
@ -104,7 +114,10 @@ public:
|
||||
|
||||
/**
|
||||
* Saves the state of this trie.
|
||||
* @param state The State object to hold the trie's state.
|
||||
* @return *this
|
||||
* @see resetToState
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
const UCharsTrie &saveState(State &state) const {
|
||||
state.uchars=uchars_;
|
||||
@ -117,8 +130,11 @@ public:
|
||||
* Resets this trie to the saved state.
|
||||
* If the state object contains no state, or the state of a different trie,
|
||||
* then this trie remains unchanged.
|
||||
* @param state The State object which holds a saved trie state.
|
||||
* @return *this
|
||||
* @see saveState
|
||||
* @see reset
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrie &resetToState(const State &state) {
|
||||
if(uchars_==state.uchars && uchars_!=NULL) {
|
||||
@ -132,6 +148,7 @@ public:
|
||||
* Determines whether the string so far matches, whether it has a value,
|
||||
* and whether another input UChar can continue a matching string.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult current() const;
|
||||
|
||||
@ -140,6 +157,7 @@ public:
|
||||
* Equivalent to reset().next(uchar).
|
||||
* @param uchar Input char value. Values below 0 and above 0xffff will never match.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UStringTrieResult first(int32_t uchar) {
|
||||
remainingMatchLength_=-1;
|
||||
@ -152,6 +170,7 @@ public:
|
||||
* Equivalent to reset().nextForCodePoint(cp).
|
||||
* @param cp A Unicode code point 0..0x10ffff.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UStringTrieResult firstForCodePoint(UChar32 cp) {
|
||||
return cp<=0xffff ?
|
||||
@ -165,6 +184,7 @@ public:
|
||||
* Traverses the trie from the current state for this input UChar.
|
||||
* @param uchar Input char value. Values below 0 and above 0xffff will never match.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(int32_t uchar);
|
||||
|
||||
@ -173,6 +193,7 @@ public:
|
||||
* one or two UTF-16 code units for this input code point.
|
||||
* @param cp A Unicode code point 0..0x10ffff.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UStringTrieResult nextForCodePoint(UChar32 cp) {
|
||||
return cp<=0xffff ?
|
||||
@ -192,7 +213,10 @@ public:
|
||||
* result=next(c);
|
||||
* return result;
|
||||
* \endcode
|
||||
* @param s A string. Can be NULL if length is 0.
|
||||
* @param length The length of the string. Can be -1 if NUL-terminated.
|
||||
* @return The match/value Result.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UStringTrieResult next(const UChar *s, int32_t length);
|
||||
|
||||
@ -202,11 +226,13 @@ public:
|
||||
* getValue() can be called multiple times.
|
||||
*
|
||||
* Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!
|
||||
* @return The value for the string so far.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline int32_t getValue() const {
|
||||
const UChar *pos=pos_;
|
||||
int32_t leadUnit=*pos++;
|
||||
U_ASSERT(leadUnit>=kMinValueLead);
|
||||
// U_ASSERT(leadUnit>=kMinValueLead);
|
||||
return leadUnit&kValueIsFinal ?
|
||||
readValue(pos, leadUnit&0x7fff) : readNodeValue(pos, leadUnit);
|
||||
}
|
||||
@ -218,6 +244,7 @@ public:
|
||||
* (output-only)
|
||||
* @return TRUE if all strings reachable from the current state
|
||||
* map to the same value.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
inline UBool hasUniqueValue(int32_t &uniqueValue) const {
|
||||
const UChar *pos=pos_;
|
||||
@ -230,11 +257,13 @@ public:
|
||||
* That is, each UChar c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
|
||||
* @param out Each next UChar is appended to this object.
|
||||
* @return the number of UChars which continue the string from here
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
int32_t getNextUChars(Appendable &out) const;
|
||||
|
||||
/**
|
||||
* Iterator for all of the (string, value) pairs in a UCharsTrie.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_TOOLUTIL_API Iterator : public UMemory {
|
||||
public:
|
||||
@ -247,6 +276,7 @@ public:
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator(const UChar *trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
@ -259,18 +289,26 @@ public:
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator(const UCharsTrie &trie, int32_t maxStringLength, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
~Iterator();
|
||||
|
||||
/**
|
||||
* Resets this iterator to its initial state.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
Iterator &reset();
|
||||
|
||||
/**
|
||||
* @return TRUE if there are more elements.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UBool hasNext() const;
|
||||
|
||||
@ -281,16 +319,23 @@ public:
|
||||
* have a real value, then the value is set to -1.
|
||||
* In this case, this "not a real value" is indistinguishable from
|
||||
* a real value of -1.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return TRUE if there is another element.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UBool next(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* @return The string for the last successful next().
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
const UnicodeString &getString() const { return str_; }
|
||||
/**
|
||||
* @return The value for the last successful next().
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
int32_t getValue() const { return value_; }
|
||||
|
||||
@ -373,7 +418,7 @@ private:
|
||||
}
|
||||
|
||||
static inline int32_t readNodeValue(const UChar *pos, int32_t leadUnit) {
|
||||
U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
|
||||
// U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
|
||||
int32_t value;
|
||||
if(leadUnit<kMinTwoUnitNodeValueLead) {
|
||||
value=(leadUnit>>6)-1;
|
||||
@ -385,7 +430,7 @@ private:
|
||||
return value;
|
||||
}
|
||||
static inline const UChar *skipNodeValue(const UChar *pos, int32_t leadUnit) {
|
||||
U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
|
||||
// U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
|
||||
if(leadUnit>=kMinTwoUnitNodeValueLead) {
|
||||
if(leadUnit<kThreeUnitNodeValueLead) {
|
||||
++pos;
|
@ -16,9 +16,9 @@
|
||||
#define __UCHARSTRIEBUILDER_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/stringtriebuilder.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "stringtriebuilder.h"
|
||||
#include "ucharstrie.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -28,17 +28,20 @@ class UCharsTrieElement;
|
||||
* Builder class for UCharsTrie.
|
||||
*
|
||||
* This class is not intended for public subclassing.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
class U_TOOLUTIL_API UCharsTrieBuilder : public StringTrieBuilder {
|
||||
class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
|
||||
public:
|
||||
/**
|
||||
* Constructs an empty builder.
|
||||
* @param errorCode Standard ICU error code.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrieBuilder(UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
virtual ~UCharsTrieBuilder();
|
||||
|
||||
@ -54,6 +57,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
|
||||
|
||||
@ -70,6 +74,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return A new UCharsTrie for the add()ed data.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
|
||||
|
||||
@ -92,6 +97,7 @@ public:
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return result
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
|
||||
UErrorCode &errorCode);
|
||||
@ -100,6 +106,7 @@ public:
|
||||
* Removes all (string, value) pairs.
|
||||
* New data can then be add()ed and a new trie can be built.
|
||||
* @return *this
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
UCharsTrieBuilder &clear() {
|
||||
strings.remove();
|
@ -27,6 +27,7 @@
|
||||
* @see USTRINGTRIE_MATCHES
|
||||
* @see USTRINGTRIE_HAS_VALUE
|
||||
* @see USTRINGTRIE_HAS_NEXT
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
enum UStringTrieResult {
|
||||
/**
|
||||
@ -34,12 +35,14 @@ enum UStringTrieResult {
|
||||
* Once current()/next() return USTRINGTRIE_NO_MATCH,
|
||||
* all further calls to current()/next() will also return USTRINGTRIE_NO_MATCH,
|
||||
* until the trie is reset to its original state or to a saved state.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_NO_MATCH,
|
||||
/**
|
||||
* The input unit(s) continued a matching string
|
||||
* but there is no value for the string so far.
|
||||
* (It is a prefix of a longer string.)
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_NO_VALUE,
|
||||
/**
|
||||
@ -47,6 +50,7 @@ enum UStringTrieResult {
|
||||
* and there is a value for the string so far.
|
||||
* This value will be returned by getValue().
|
||||
* No further input byte/unit can continue a matching string.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_FINAL_VALUE,
|
||||
/**
|
||||
@ -54,6 +58,7 @@ enum UStringTrieResult {
|
||||
* and there is a value for the string so far.
|
||||
* This value will be returned by getValue().
|
||||
* Another input byte/unit can continue a matching string.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
USTRINGTRIE_INTERMEDIATE_VALUE
|
||||
};
|
||||
@ -62,6 +67,7 @@ enum UStringTrieResult {
|
||||
* Same as (result!=USTRINGTRIE_NO_MATCH).
|
||||
* @param result A result from BytesTrie::first(), UCharsTrie::next() etc.
|
||||
* @return true if the input bytes/units so far are part of a matching string/byte sequence.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
#define USTRINGTRIE_MATCHES(result) ((result)!=USTRINGTRIE_NO_MATCH)
|
||||
|
||||
@ -72,6 +78,7 @@ enum UStringTrieResult {
|
||||
* @return true if there is a value for the input bytes/units so far.
|
||||
* @see BytesTrie::getValue
|
||||
* @see UCharsTrie::getValue
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
#define USTRINGTRIE_HAS_VALUE(result) ((result)>=USTRINGTRIE_FINAL_VALUE)
|
||||
|
||||
@ -80,6 +87,7 @@ enum UStringTrieResult {
|
||||
* this macro evaluates result exactly once.
|
||||
* @param result A result from BytesTrie::first(), UCharsTrie::next() etc.
|
||||
* @return true if another input byte/unit can continue a matching string.
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
#define USTRINGTRIE_HAS_NEXT(result) ((result)&1)
|
||||
|
@ -15,10 +15,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/bytestriebuilder.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "bytestrie.h"
|
||||
#include "bytestriebuilder.h"
|
||||
#include "intltest.h"
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
@ -71,7 +71,7 @@ void IntlTestUtilities::runIndexedTest( int32_t index, UBool exec, const char* &
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
name = "ByteTrieTest";
|
||||
name = "BytesTrieTest";
|
||||
if (exec) {
|
||||
logln("TestSuite BytesTrieTest---"); logln();
|
||||
LocalPointer<IntlTest> test(createBytesTrieTest());
|
||||
@ -79,7 +79,7 @@ void IntlTestUtilities::runIndexedTest( int32_t index, UBool exec, const char* &
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
name = "UCharTrieTest";
|
||||
name = "UCharsTrieTest";
|
||||
if (exec) {
|
||||
logln("TestSuite UCharsTrieTest---"); logln();
|
||||
LocalPointer<IntlTest> test(createUCharsTrieTest());
|
||||
|
@ -17,10 +17,10 @@
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/appendable.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/ucharstriebuilder.h"
|
||||
#include "unicode/uniset.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "ucharstrie.h"
|
||||
#include "ucharstriebuilder.h"
|
||||
#include "intltest.h"
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
@ -24,18 +24,18 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "unicode/bytestrie.h"
|
||||
#include "unicode/bytestriebuilder.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/ucharstrie.h"
|
||||
#include "unicode/ucharstriebuilder.h"
|
||||
#include "unicode/uperf.h"
|
||||
#include "unicode/utext.h"
|
||||
#include "bytestrie.h"
|
||||
#include "bytestriebuilder.h"
|
||||
#include "charstr.h"
|
||||
#include "package.h"
|
||||
#include "toolutil.h"
|
||||
#include "triedict.h"
|
||||
#include "ucbuf.h" // struct ULine
|
||||
#include "ucharstrie.h"
|
||||
#include "ucharstriebuilder.h"
|
||||
#include "uoptions.h"
|
||||
#include "uvectr32.h"
|
||||
|
||||
|
@ -52,8 +52,6 @@ LDFLAGS += $(LDFLAGSICUTOOLUTIL)
|
||||
LIBS = $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS)
|
||||
|
||||
OBJECTS = filestrm.o package.o pkgitems.o swapimpl.o toolutil.o unewdata.o \
|
||||
stringtriebuilder.o bytestriebuilder.o \
|
||||
ucharstrie.o ucharstriebuilder.o ucharstrieiterator.o \
|
||||
denseranges.o \
|
||||
ucm.o ucmstate.o uoptions.o uparse.o \
|
||||
ucbuf.o xmlparser.o writesrc.o \
|
||||
|
@ -246,7 +246,6 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="bytestriebuilder.cpp" />
|
||||
<ClCompile Include="denseranges.cpp" />
|
||||
<ClCompile Include="filestrm.c" />
|
||||
<ClCompile Include="filetools.cpp" />
|
||||
@ -266,7 +265,6 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="pkg_icu.cpp" />
|
||||
<ClCompile Include="pkgitems.cpp" />
|
||||
<ClCompile Include="stringtriebuilder.cpp" />
|
||||
<ClCompile Include="swapimpl.cpp" />
|
||||
<ClCompile Include="toolutil.cpp">
|
||||
<DisableLanguageExtensions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</DisableLanguageExtensions>
|
||||
@ -275,9 +273,6 @@
|
||||
<DisableLanguageExtensions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</DisableLanguageExtensions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ucbuf.c" />
|
||||
<ClCompile Include="ucharstrie.cpp" />
|
||||
<ClCompile Include="ucharstriebuilder.cpp" />
|
||||
<ClCompile Include="ucharstrieiterator.cpp" />
|
||||
<ClCompile Include="ucm.c" />
|
||||
<ClCompile Include="ucmstate.c" />
|
||||
<ClCompile Include="unewdata.c" />
|
||||
@ -295,7 +290,6 @@
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="bytestriebuilder.h" />
|
||||
<ClInclude Include="denseranges.h" />
|
||||
<ClInclude Include="filestrm.h" />
|
||||
<ClInclude Include="filetools.h" />
|
||||
@ -306,12 +300,9 @@
|
||||
<ClInclude Include="pkg_icu.h" />
|
||||
<ClInclude Include="pkg_imp.h" />
|
||||
<ClInclude Include="platform_xopen_source_extended.h" />
|
||||
<ClInclude Include="stringtriebuilder.h" />
|
||||
<ClInclude Include="swapimpl.h" />
|
||||
<ClInclude Include="toolutil.h" />
|
||||
<ClInclude Include="ucbuf.h" />
|
||||
<ClInclude Include="ucharstrie.h" />
|
||||
<ClInclude Include="ucharstriebuilder.h" />
|
||||
<ClInclude Include="ucm.h" />
|
||||
<ClInclude Include="unewdata.h" />
|
||||
<ClInclude Include="uoptions.h" />
|
||||
|
Loading…
Reference in New Issue
Block a user