2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// rbbisetb.cpp
|
2002-06-27 21:14:47 +00:00
|
|
|
//
|
2002-06-25 17:23:07 +00:00
|
|
|
/*
|
2003-06-02 22:21:58 +00:00
|
|
|
***************************************************************************
|
2008-01-14 20:10:23 +00:00
|
|
|
* Copyright (C) 2002-2008 International Business Machines Corporation *
|
2003-06-02 22:21:58 +00:00
|
|
|
* and others. All rights reserved. *
|
|
|
|
***************************************************************************
|
2002-06-25 17:23:07 +00:00
|
|
|
*/
|
|
|
|
//
|
2002-06-27 21:14:47 +00:00
|
|
|
// RBBISetBuilder Handles processing of Unicode Sets from RBBI rules
|
|
|
|
// (part of the rule building process.)
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// Starting with the rules parse tree from the scanner,
|
|
|
|
//
|
|
|
|
// - Enumerate the set of UnicodeSets that are referenced
|
2002-06-27 21:14:47 +00:00
|
|
|
// by the RBBI rules.
|
2002-06-25 17:23:07 +00:00
|
|
|
// - compute a set of non-overlapping character ranges
|
|
|
|
// with all characters within a range belonging to the same
|
|
|
|
// set of input uniocde sets.
|
|
|
|
// - Derive a set of non-overlapping UnicodeSet (like things)
|
|
|
|
// that will correspond to columns in the state table for
|
|
|
|
// the RBBI execution engine. All characters within one
|
|
|
|
// of these sets belong to the same set of the original
|
|
|
|
// UnicodeSets from the user's rules.
|
|
|
|
// - construct the trie table that maps input characters
|
|
|
|
// to the index of the matching non-overlapping set of set from
|
|
|
|
// the previous step.
|
|
|
|
//
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "utrie.h"
|
|
|
|
#include "uvector.h"
|
2002-07-22 23:24:55 +00:00
|
|
|
#include "uassert.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "cmemory.h"
|
2002-08-01 16:17:41 +00:00
|
|
|
#include "cstring.h"
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
#include "rbbisetb.h"
|
|
|
|
#include "rbbinode.h"
|
|
|
|
|
|
|
|
|
2003-03-15 01:57:10 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// getFoldedRBBIValue Call-back function used during building of Trie table.
|
|
|
|
// Folding value: just store the offset (16 bits)
|
|
|
|
// if there is any non-0 entry.
|
|
|
|
// (It'd really be nice if the Trie builder would provide a
|
|
|
|
// simple default, so this function could go away from here.)
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
/* folding value: just store the offset (16 bits) if there is any non-0 entry */
|
|
|
|
U_CDECL_BEGIN
|
|
|
|
static uint32_t U_CALLCONV
|
|
|
|
getFoldedRBBIValue(UNewTrie *trie, UChar32 start, int32_t offset) {
|
|
|
|
uint32_t value;
|
|
|
|
UChar32 limit;
|
|
|
|
UBool inBlockZero;
|
|
|
|
|
|
|
|
limit=start+0x400;
|
|
|
|
while(start<limit) {
|
|
|
|
value=utrie_get32(trie, start, &inBlockZero);
|
|
|
|
if(inBlockZero) {
|
|
|
|
start+=UTRIE_DATA_BLOCK_LENGTH;
|
|
|
|
} else if(value!=0) {
|
|
|
|
return (uint32_t)(offset|0x8000);
|
|
|
|
} else {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CDECL_END
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Constructor
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
RBBISetBuilder::RBBISetBuilder(RBBIRuleBuilder *rb)
|
|
|
|
{
|
|
|
|
fRB = rb;
|
|
|
|
fStatus = rb->fStatus;
|
|
|
|
fRangeList = 0;
|
|
|
|
fTrie = 0;
|
|
|
|
fTrieSize = 0;
|
|
|
|
fGroupCount = 0;
|
2005-09-27 00:03:32 +00:00
|
|
|
fSawBOF = FALSE;
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destructor
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
2002-06-27 21:14:47 +00:00
|
|
|
RBBISetBuilder::~RBBISetBuilder()
|
2002-06-25 17:23:07 +00:00
|
|
|
{
|
|
|
|
RangeDescriptor *nextRangeDesc;
|
2002-06-27 21:14:47 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
// Walk through & delete the linked list of RangeDescriptors
|
|
|
|
for (nextRangeDesc = fRangeList; nextRangeDesc!=NULL;) {
|
|
|
|
RangeDescriptor *r = nextRangeDesc;
|
|
|
|
nextRangeDesc = r->fNext;
|
|
|
|
delete r;
|
|
|
|
}
|
|
|
|
|
|
|
|
utrie_close(fTrie);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// build Build the list of non-overlapping character ranges
|
|
|
|
// from the Unicode Sets.
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
void RBBISetBuilder::build() {
|
|
|
|
RBBINode *usetNode;
|
|
|
|
RangeDescriptor *rlRange;
|
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "usets")) {printSets();}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the process by creating a single range encompassing all characters
|
|
|
|
// that is in no sets.
|
|
|
|
//
|
2003-09-09 23:51:17 +00:00
|
|
|
fRangeList = new RangeDescriptor(*fStatus); // will check for status here
|
2008-01-14 20:10:23 +00:00
|
|
|
if (fRangeList == NULL) {
|
|
|
|
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
fRangeList->fStartChar = 0;
|
|
|
|
fRangeList->fEndChar = 0x10ffff;
|
|
|
|
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(*fStatus)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Find the set of non-overlapping ranges of characters
|
|
|
|
//
|
2002-08-28 22:24:17 +00:00
|
|
|
int ni;
|
2005-03-23 02:13:53 +00:00
|
|
|
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
|
2002-08-28 22:24:17 +00:00
|
|
|
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
|
|
|
|
if (usetNode==NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
UnicodeSet *inputSet = usetNode->fInputSet;
|
|
|
|
int32_t inputSetRangeCount = inputSet->getRangeCount();
|
|
|
|
int inputSetRangeIndex = 0;
|
|
|
|
rlRange = fRangeList;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (inputSetRangeIndex >= inputSetRangeCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UChar32 inputSetRangeBegin = inputSet->getRangeStart(inputSetRangeIndex);
|
|
|
|
UChar32 inputSetRangeEnd = inputSet->getRangeEnd(inputSetRangeIndex);
|
|
|
|
|
|
|
|
// skip over ranges from the range list that are completely
|
|
|
|
// below the current range from the input unicode set.
|
|
|
|
while (rlRange->fEndChar < inputSetRangeBegin) {
|
|
|
|
rlRange = rlRange->fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start of the range from the range list is before with
|
|
|
|
// the start of the range from the unicode set, split the range list range
|
|
|
|
// in two, with one part being before (wholly outside of) the unicode set
|
|
|
|
// and the other containing the rest.
|
|
|
|
// Then continue the loop; the post-split current range will then be skipped
|
|
|
|
// over
|
|
|
|
if (rlRange->fStartChar < inputSetRangeBegin) {
|
|
|
|
rlRange->split(inputSetRangeBegin, *fStatus);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(*fStatus)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same thing at the end of the ranges...
|
|
|
|
// If the end of the range from the range list doesn't coincide with
|
|
|
|
// the end of the range from the unicode set, split the range list
|
|
|
|
// range in two. The first part of the split range will be
|
|
|
|
// wholly inside the Unicode set.
|
|
|
|
if (rlRange->fEndChar > inputSetRangeEnd) {
|
|
|
|
rlRange->split(inputSetRangeEnd+1, *fStatus);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(*fStatus)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The current rlRange is now entirely within the UnicodeSet range.
|
|
|
|
// Add this unicode set to the list of sets for this rlRange
|
|
|
|
if (rlRange->fIncludesSets->indexOf(usetNode) == -1) {
|
|
|
|
rlRange->fIncludesSets->addElement(usetNode, *fStatus);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(*fStatus)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advance over ranges that we are finished with.
|
|
|
|
if (inputSetRangeEnd == rlRange->fEndChar) {
|
|
|
|
inputSetRangeIndex++;
|
|
|
|
}
|
|
|
|
rlRange = rlRange->fNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "range")) { printRanges();}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Group the above ranges, with each group consisting of one or more
|
|
|
|
// ranges that are in exactly the same set of original UnicodeSets.
|
|
|
|
// The groups are numbered, and these group numbers are the set of
|
|
|
|
// input symbols recognized by the run-time state machine.
|
|
|
|
//
|
2005-03-23 02:13:53 +00:00
|
|
|
// Numbering: # 0 (state table column 0) is unused.
|
|
|
|
// # 1 is reserved - table column 1 is for end-of-input
|
2005-09-27 00:03:32 +00:00
|
|
|
// # 2 is reserved - table column 2 is for beginning-in-input
|
|
|
|
// # 3 is the first range list.
|
2005-03-23 02:13:53 +00:00
|
|
|
//
|
2002-06-25 17:23:07 +00:00
|
|
|
RangeDescriptor *rlSearchRange;
|
|
|
|
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
|
|
|
|
for (rlSearchRange=fRangeList; rlSearchRange != rlRange; rlSearchRange=rlSearchRange->fNext) {
|
|
|
|
if (rlRange->fIncludesSets->equals(*rlSearchRange->fIncludesSets)) {
|
|
|
|
rlRange->fNum = rlSearchRange->fNum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rlRange->fNum == 0) {
|
|
|
|
fGroupCount ++;
|
2005-09-27 00:03:32 +00:00
|
|
|
rlRange->fNum = fGroupCount+2;
|
2002-06-25 17:23:07 +00:00
|
|
|
rlRange->setDictionaryFlag();
|
2005-09-27 00:03:32 +00:00
|
|
|
addValToSets(rlRange->fIncludesSets, fGroupCount+2);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 02:13:53 +00:00
|
|
|
// Handle input sets that contain the special string {eof}.
|
|
|
|
// Column 1 of the state table is reserved for EOF on input.
|
2005-09-27 00:03:32 +00:00
|
|
|
// Column 2 is reserved for before-the-start-input.
|
|
|
|
// (This column can be optimized away later if there are no rule
|
|
|
|
// references to {bof}.)
|
|
|
|
// Add this column value (1 or 2) to the equivalent expression
|
2005-03-23 02:13:53 +00:00
|
|
|
// subtree for each UnicodeSet that contains the string {eof}
|
2005-09-27 00:03:32 +00:00
|
|
|
// Because {bof} and {eof} are not a characters in the normal sense,
|
|
|
|
// they doesn't affect the computation of ranges or TRIE.
|
2005-06-06 06:59:26 +00:00
|
|
|
static const UChar eofUString[] = {0x65, 0x6f, 0x66, 0};
|
2005-09-27 00:03:32 +00:00
|
|
|
static const UChar bofUString[] = {0x62, 0x6f, 0x66, 0};
|
|
|
|
|
2005-03-23 02:13:53 +00:00
|
|
|
UnicodeString eofString(eofUString);
|
2005-09-27 00:03:32 +00:00
|
|
|
UnicodeString bofString(bofUString);
|
2005-03-23 02:13:53 +00:00
|
|
|
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
|
|
|
|
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
|
|
|
|
if (usetNode==NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UnicodeSet *inputSet = usetNode->fInputSet;
|
|
|
|
if (inputSet->contains(eofString)) {
|
|
|
|
addValToSet(usetNode, 1);
|
|
|
|
}
|
2005-09-27 00:03:32 +00:00
|
|
|
if (inputSet->contains(bofString)) {
|
|
|
|
addValToSet(usetNode, 2);
|
|
|
|
fSawBOF = TRUE;
|
|
|
|
}
|
2005-03-23 02:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "rgroup")) {printRangeGroups();}
|
|
|
|
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "esets")) {printSets();}
|
2002-06-27 21:14:47 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// Build the Trie table for mapping UChar32 values to the corresponding
|
|
|
|
// range group number
|
|
|
|
//
|
|
|
|
fTrie = utrie_open(NULL, // Pre-existing trie to be filled in
|
|
|
|
NULL, // Data array (utrie will allocate one)
|
|
|
|
100000, // Max Data Length
|
|
|
|
0, // Initial value for all code points
|
2003-07-24 23:23:19 +00:00
|
|
|
0, // Lead surrogate unit value
|
2002-06-25 17:23:07 +00:00
|
|
|
TRUE); // Keep Latin 1 in separately
|
|
|
|
|
|
|
|
|
|
|
|
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
|
|
|
|
utrie_setRange32(fTrie, rlRange->fStartChar, rlRange->fEndChar+1, rlRange->fNum, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// getTrieSize() Return the size that will be required to serialize the Trie.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------------
|
2004-03-27 07:05:32 +00:00
|
|
|
int32_t RBBISetBuilder::getTrieSize() /*const*/ {
|
2002-06-25 17:23:07 +00:00
|
|
|
fTrieSize = utrie_serialize(fTrie,
|
|
|
|
NULL, // Buffer
|
|
|
|
0, // Capacity
|
|
|
|
getFoldedRBBIValue,
|
|
|
|
TRUE, // Reduce to 16 bits
|
|
|
|
fStatus);
|
2002-08-01 16:17:41 +00:00
|
|
|
// RBBIDebugPrintf("Trie table size is %d\n", trieSize);
|
2002-06-25 17:23:07 +00:00
|
|
|
return fTrieSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// serializeTrie() Put the serialized trie at the specified address.
|
|
|
|
// Trust the caller to have given us enough memory.
|
|
|
|
// getTrieSize() MUST be called first.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
void RBBISetBuilder::serializeTrie(uint8_t *where) {
|
2002-07-11 17:09:05 +00:00
|
|
|
utrie_serialize(fTrie,
|
|
|
|
where, // Buffer
|
|
|
|
fTrieSize, // Capacity
|
|
|
|
getFoldedRBBIValue,
|
|
|
|
TRUE, // Reduce to 16 bits
|
|
|
|
fStatus);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2002-06-27 21:14:47 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// addValToSets Add a runtime-mapped input value to each uset from a
|
2005-03-23 02:13:53 +00:00
|
|
|
// list of uset nodes. (val corresponds to a state table column.)
|
2002-06-25 17:23:07 +00:00
|
|
|
// For each of the original Unicode sets - which correspond
|
|
|
|
// directly to uset nodes - a logically equivalent expression
|
|
|
|
// is constructed in terms of the remapped runtime input
|
|
|
|
// symbol set. This function adds one runtime input symbol to
|
|
|
|
// a list of sets.
|
|
|
|
//
|
|
|
|
// The "logically equivalent expression" is the tree for an
|
|
|
|
// or-ing together of all of the symbols that go into the set.
|
2002-06-27 21:14:47 +00:00
|
|
|
//
|
2002-06-25 17:23:07 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
void RBBISetBuilder::addValToSets(UVector *sets, uint32_t val) {
|
|
|
|
int32_t ix;
|
|
|
|
|
|
|
|
for (ix=0; ix<sets->size(); ix++) {
|
|
|
|
RBBINode *usetNode = (RBBINode *)sets->elementAt(ix);
|
2005-03-23 02:13:53 +00:00
|
|
|
addValToSet(usetNode, val);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 02:13:53 +00:00
|
|
|
void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
|
|
|
|
RBBINode *leafNode = new RBBINode(RBBINode::leafChar);
|
2008-01-14 20:10:23 +00:00
|
|
|
if (leafNode == NULL) {
|
|
|
|
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2005-03-23 02:13:53 +00:00
|
|
|
leafNode->fVal = (unsigned short)val;
|
|
|
|
if (usetNode->fLeftChild == NULL) {
|
|
|
|
usetNode->fLeftChild = leafNode;
|
|
|
|
leafNode->fParent = usetNode;
|
|
|
|
} else {
|
|
|
|
// There are already input symbols present for this set.
|
|
|
|
// Set up an OR node, with the previous stuff as the left child
|
|
|
|
// and the new value as the right child.
|
|
|
|
RBBINode *orNode = new RBBINode(RBBINode::opOr);
|
2008-01-14 20:10:23 +00:00
|
|
|
if (orNode == NULL) {
|
|
|
|
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2005-03-23 02:13:53 +00:00
|
|
|
orNode->fLeftChild = usetNode->fLeftChild;
|
|
|
|
orNode->fRightChild = leafNode;
|
|
|
|
orNode->fLeftChild->fParent = orNode;
|
|
|
|
orNode->fRightChild->fParent = orNode;
|
|
|
|
usetNode->fLeftChild = orNode;
|
|
|
|
orNode->fParent = usetNode;
|
|
|
|
}
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
2005-03-23 02:13:53 +00:00
|
|
|
// getNumCharCategories
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
2004-03-27 07:05:32 +00:00
|
|
|
int32_t RBBISetBuilder::getNumCharCategories() const {
|
2005-09-27 00:03:32 +00:00
|
|
|
return fGroupCount + 3;
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-27 00:03:32 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// sawBOF
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
UBool RBBISetBuilder::sawBOF() const {
|
|
|
|
return fSawBOF;
|
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2003-10-11 00:44:36 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// getFirstChar Given a runtime RBBI character category, find
|
|
|
|
// the first UChar32 that is in the set of chars
|
|
|
|
// in the category.
|
|
|
|
//------------------------------------------------------------------------
|
2004-03-27 07:05:32 +00:00
|
|
|
UChar32 RBBISetBuilder::getFirstChar(int32_t category) const {
|
2003-10-11 00:44:36 +00:00
|
|
|
RangeDescriptor *rlRange;
|
|
|
|
UChar32 retVal = (UChar32)-1;
|
|
|
|
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
|
|
|
|
if (rlRange->fNum == category) {
|
|
|
|
retVal = rlRange->fStartChar;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// printRanges A debugging function.
|
|
|
|
// dump out all of the range definitions.
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
2003-05-16 20:11:01 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2003-12-04 22:44:05 +00:00
|
|
|
void RBBISetBuilder::printRanges() {
|
2002-06-25 17:23:07 +00:00
|
|
|
RangeDescriptor *rlRange;
|
|
|
|
int i;
|
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n\n Nonoverlapping Ranges ...\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("%2i %4x-%4x ", rlRange->fNum, rlRange->fStartChar, rlRange->fEndChar);
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
for (i=0; i<rlRange->fIncludesSets->size(); i++) {
|
|
|
|
RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
|
2004-08-26 22:51:40 +00:00
|
|
|
UnicodeString setName = UNICODE_STRING("anon", 4);
|
2002-06-25 17:23:07 +00:00
|
|
|
RBBINode *setRef = usetNode->fParent;
|
|
|
|
if (setRef != NULL) {
|
|
|
|
RBBINode *varRef = setRef->fParent;
|
|
|
|
if (varRef != NULL && varRef->fType == RBBINode::varRef) {
|
|
|
|
setName = varRef->fText;
|
|
|
|
}
|
2002-06-27 21:14:47 +00:00
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" ");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// printRangeGroups A debugging function.
|
|
|
|
// dump out all of the range groups.
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
2003-12-04 22:44:05 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2002-06-25 17:23:07 +00:00
|
|
|
void RBBISetBuilder::printRangeGroups() {
|
|
|
|
RangeDescriptor *rlRange;
|
|
|
|
RangeDescriptor *tRange;
|
|
|
|
int i;
|
|
|
|
int lastPrintedGroupNum = 0;
|
2002-06-27 21:14:47 +00:00
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\nRanges grouped by Unicode Set Membership...\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
|
|
|
|
int groupNum = rlRange->fNum & 0xbfff;
|
|
|
|
if (groupNum > lastPrintedGroupNum) {
|
|
|
|
lastPrintedGroupNum = groupNum;
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("%2i ", groupNum);
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2002-11-30 04:41:53 +00:00
|
|
|
if (rlRange->fNum & 0x4000) { RBBIDebugPrintf(" <DICT> ");}
|
2002-06-27 21:14:47 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
for (i=0; i<rlRange->fIncludesSets->size(); i++) {
|
|
|
|
RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
|
2004-08-26 22:51:40 +00:00
|
|
|
UnicodeString setName = UNICODE_STRING("anon", 4);
|
2002-06-25 17:23:07 +00:00
|
|
|
RBBINode *setRef = usetNode->fParent;
|
|
|
|
if (setRef != NULL) {
|
|
|
|
RBBINode *varRef = setRef->fParent;
|
|
|
|
if (varRef != NULL && varRef->fType == RBBINode::varRef) {
|
|
|
|
setName = varRef->fText;
|
|
|
|
}
|
2002-06-27 21:14:47 +00:00
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" ");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (tRange = rlRange; tRange != 0; tRange = tRange->fNext) {
|
|
|
|
if (tRange->fNum == rlRange->fNum) {
|
|
|
|
if (i++ % 5 == 0) {
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n ");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf(" %05x-%05x", tRange->fStartChar, tRange->fEndChar);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// printSets A debugging function.
|
|
|
|
// dump out all of the set definitions.
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
2003-05-16 20:11:01 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2003-12-04 22:44:05 +00:00
|
|
|
void RBBISetBuilder::printSets() {
|
2002-06-25 17:23:07 +00:00
|
|
|
int i;
|
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n\nUnicode Sets List\n------------------\n");
|
2002-08-28 22:24:17 +00:00
|
|
|
for (i=0; ; i++) {
|
|
|
|
RBBINode *usetNode;
|
|
|
|
RBBINode *setRef;
|
|
|
|
RBBINode *varRef;
|
|
|
|
UnicodeString setName;
|
|
|
|
|
|
|
|
usetNode = (RBBINode *)fRB->fUSetNodes->elementAt(i);
|
|
|
|
if (usetNode == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("%3d ", i);
|
2004-08-26 22:51:40 +00:00
|
|
|
setName = UNICODE_STRING("anonymous", 9);
|
2002-06-25 17:23:07 +00:00
|
|
|
setRef = usetNode->fParent;
|
|
|
|
if (setRef != NULL) {
|
|
|
|
varRef = setRef->fParent;
|
|
|
|
if (varRef != NULL && varRef->fType == RBBINode::varRef) {
|
|
|
|
setName = varRef->fText;
|
|
|
|
}
|
2002-06-27 21:14:47 +00:00
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
RBBI_DEBUG_printUnicodeString(setName);
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf(" ");
|
2003-12-04 22:44:05 +00:00
|
|
|
RBBI_DEBUG_printUnicodeString(usetNode->fText);
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
if (usetNode->fLeftChild != NULL) {
|
2003-12-04 22:44:05 +00:00
|
|
|
usetNode->fLeftChild->printTree(TRUE);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
RBBIDebugPrintf("\n");
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2003-12-04 22:44:05 +00:00
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
//
|
2002-07-16 01:55:55 +00:00
|
|
|
// RangeDescriptor copy constructor
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------
|
2002-07-16 01:55:55 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &status) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
this->fStartChar = other.fStartChar;
|
|
|
|
this->fEndChar = other.fEndChar;
|
|
|
|
this->fNum = other.fNum;
|
|
|
|
this->fNext = NULL;
|
2003-09-09 23:51:17 +00:00
|
|
|
UErrorCode oldstatus = status;
|
2002-06-25 17:23:07 +00:00
|
|
|
this->fIncludesSets = new UVector(status);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(oldstatus)) {
|
|
|
|
status = oldstatus;
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (this->fIncludesSets == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
for (i=0; i<other.fIncludesSets->size(); i++) {
|
|
|
|
this->fIncludesSets->addElement(other.fIncludesSets->elementAt(i), status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RangeDesriptor default constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
RangeDescriptor::RangeDescriptor(UErrorCode &status) {
|
|
|
|
this->fStartChar = 0;
|
|
|
|
this->fEndChar = 0;
|
|
|
|
this->fNum = 0;
|
|
|
|
this->fNext = NULL;
|
2003-09-09 23:51:17 +00:00
|
|
|
UErrorCode oldstatus = status;
|
2002-06-25 17:23:07 +00:00
|
|
|
this->fIncludesSets = new UVector(status);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(oldstatus)) {
|
|
|
|
status = oldstatus;
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if(this->fIncludesSets == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2002-08-01 16:17:41 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RangeDesriptor Destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
RangeDescriptor::~RangeDescriptor() {
|
|
|
|
delete fIncludesSets;
|
|
|
|
fIncludesSets = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RangeDesriptor::split()
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
|
2002-07-22 23:24:55 +00:00
|
|
|
U_ASSERT(where>fStartChar && where<=fEndChar);
|
2002-06-25 17:23:07 +00:00
|
|
|
RangeDescriptor *nr = new RangeDescriptor(*this, status);
|
2002-06-29 09:31:05 +00:00
|
|
|
if(nr == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 09:35:50 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
delete nr;
|
|
|
|
return;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
// RangeDescriptor copy constructor copies all fields.
|
|
|
|
// Only need to update those that are different after the split.
|
|
|
|
nr->fStartChar = where;
|
|
|
|
this->fEndChar = where-1;
|
|
|
|
nr->fNext = this->fNext;
|
|
|
|
this->fNext = nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RangeDescriptor::setDictionaryFlag
|
|
|
|
//
|
|
|
|
// Character Category Numbers that include characters from
|
|
|
|
// the original Unicode Set named "dictionary" have bit 14
|
|
|
|
// set to 1. The RBBI runtime engine uses this to trigger
|
|
|
|
// use of the word dictionary.
|
|
|
|
//
|
|
|
|
// This function looks through the Unicode Sets that it
|
|
|
|
// (the range) includes, and sets the bit in fNum when
|
|
|
|
// "dictionary" is among them.
|
|
|
|
//
|
|
|
|
// TODO: a faster way would be to find the set node for
|
|
|
|
// "dictionary" just once, rather than looking it
|
|
|
|
// up by name every time.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
|
|
void RangeDescriptor::setDictionaryFlag() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<this->fIncludesSets->size(); i++) {
|
|
|
|
RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i);
|
|
|
|
UnicodeString setName;
|
|
|
|
RBBINode *setRef = usetNode->fParent;
|
|
|
|
if (setRef != NULL) {
|
|
|
|
RBBINode *varRef = setRef->fParent;
|
|
|
|
if (varRef != NULL && varRef->fType == RBBINode::varRef) {
|
|
|
|
setName = varRef->fText;
|
|
|
|
}
|
|
|
|
}
|
2004-08-26 22:51:40 +00:00
|
|
|
if (setName.compare(UNICODE_STRING("dictionary", 10)) == 0) { // TODO: no string literals.
|
2002-06-25 17:23:07 +00:00
|
|
|
this->fNum |= 0x4000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|