ICU-2092 error status checks added
X-SVN-Rev: 13050
This commit is contained in:
parent
e76f09208e
commit
6f094669a2
@ -80,14 +80,16 @@ BreakIterator::makeWordInstance(const Locale& key, UErrorCode& status)
|
|||||||
else {
|
else {
|
||||||
result = new RuleBasedBreakIterator(file, status);
|
result = new RuleBasedBreakIterator(file, status);
|
||||||
}
|
}
|
||||||
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
||||||
|
if (result != NULL) {
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
udata_close(file);
|
udata_close(file);
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
||||||
delete result;
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -131,14 +133,16 @@ BreakIterator::makeLineInstance(const Locale& key, UErrorCode& status)
|
|||||||
else {
|
else {
|
||||||
result = new RuleBasedBreakIterator(file, status);
|
result = new RuleBasedBreakIterator(file, status);
|
||||||
}
|
}
|
||||||
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
||||||
|
if (result != NULL) {
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
udata_close(file);
|
udata_close(file);
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
||||||
delete result;
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,14 +173,17 @@ BreakIterator::makeCharacterInstance(const Locale& /* key */, UErrorCode& status
|
|||||||
// The UDataMemory is adopted by the break iterator.
|
// The UDataMemory is adopted by the break iterator.
|
||||||
|
|
||||||
result = new RuleBasedBreakIterator(file, status);
|
result = new RuleBasedBreakIterator(file, status);
|
||||||
|
|
||||||
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
||||||
|
if (result != NULL) {
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
udata_close(file);
|
udata_close(file);
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
||||||
delete result;
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,14 +214,16 @@ BreakIterator::makeSentenceInstance(const Locale& /*key */, UErrorCode& status)
|
|||||||
// The UDataMemory is adopted by the break iterator.
|
// The UDataMemory is adopted by the break iterator.
|
||||||
|
|
||||||
result = new RuleBasedBreakIterator(file, status);
|
result = new RuleBasedBreakIterator(file, status);
|
||||||
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
||||||
|
if (result != NULL) {
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
udata_close(file);
|
udata_close(file);
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
||||||
delete result;
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -246,14 +255,16 @@ BreakIterator::makeTitleInstance(const Locale& /* key */, UErrorCode& status)
|
|||||||
// The UDataMemory is adopted by the break iterator.
|
// The UDataMemory is adopted by the break iterator.
|
||||||
|
|
||||||
result = new RuleBasedBreakIterator(file, status);
|
result = new RuleBasedBreakIterator(file, status);
|
||||||
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
||||||
|
if (result != NULL) {
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
udata_close(file);
|
udata_close(file);
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
||||||
delete result;
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -437,7 +448,9 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
|
|||||||
case UBRK_SENTENCE: return BreakIterator::makeSentenceInstance(loc, status);
|
case UBRK_SENTENCE: return BreakIterator::makeSentenceInstance(loc, status);
|
||||||
case UBRK_TITLE: return BreakIterator::makeTitleInstance(loc, status);
|
case UBRK_TITLE: return BreakIterator::makeTitleInstance(loc, status);
|
||||||
default:
|
default:
|
||||||
|
if (U_SUCCESS(status)) {
|
||||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,17 +43,18 @@ DictionaryBasedBreakIterator::DictionaryBasedBreakIterator(UDataMemory* rbbiData
|
|||||||
init();
|
init();
|
||||||
if (U_FAILURE(status)) {return;};
|
if (U_FAILURE(status)) {return;};
|
||||||
fTables = new DictionaryBasedBreakIteratorTables(dictionaryFilename, status);
|
fTables = new DictionaryBasedBreakIteratorTables(dictionaryFilename, status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
if (fTables != NULL) {
|
||||||
|
fTables->removeReference();
|
||||||
|
fTables = NULL;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if(fTables == 0) {
|
if(fTables == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (U_FAILURE(status)) {
|
|
||||||
fTables->removeReference();
|
|
||||||
fTables = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -396,6 +397,9 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
c = fText->next();
|
c = fText->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return; // UStack below overwrites the status error codes
|
||||||
|
}
|
||||||
|
|
||||||
// initialize. We maintain two stacks: currentBreakPositions contains
|
// initialize. We maintain two stacks: currentBreakPositions contains
|
||||||
// the list of break positions that will be returned if we successfully
|
// the list of break positions that will be returned if we successfully
|
||||||
@ -412,6 +416,8 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
// further, this saves us from having to follow each possible path
|
// further, this saves us from having to follow each possible path
|
||||||
// through the text all the way to the error (hopefully avoiding many
|
// through the text all the way to the error (hopefully avoiding many
|
||||||
// future recursive calls as well).
|
// future recursive calls as well).
|
||||||
|
// there can be only one kind of error in UStack and UVector, so we'll
|
||||||
|
// just let the error fall through
|
||||||
UStack currentBreakPositions(status);
|
UStack currentBreakPositions(status);
|
||||||
UStack possibleBreakPositions(status);
|
UStack possibleBreakPositions(status);
|
||||||
UVector wrongBreakPositions(status);
|
UVector wrongBreakPositions(status);
|
||||||
@ -445,6 +451,9 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
// the possible-break-positions stack
|
// the possible-break-positions stack
|
||||||
if (fTables->fDictionary->at(state, (int32_t)0) == -1) {
|
if (fTables->fDictionary->at(state, (int32_t)0) == -1) {
|
||||||
possibleBreakPositions.push(fText->getIndex(), status);
|
possibleBreakPositions.push(fText->getIndex(), status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// look up the new state to transition to in the dictionary
|
// look up the new state to transition to in the dictionary
|
||||||
@ -456,6 +465,9 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
// of the loop.
|
// of the loop.
|
||||||
if (state == -1) {
|
if (state == -1) {
|
||||||
currentBreakPositions.push(fText->getIndex(), status);
|
currentBreakPositions.push(fText->getIndex(), status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,6 +513,9 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
currentBreakPositions.removeAllElements();
|
currentBreakPositions.removeAllElements();
|
||||||
for (int32_t i = 0; i < bestBreakPositions.size(); i++) {
|
for (int32_t i = 0; i < bestBreakPositions.size(); i++) {
|
||||||
currentBreakPositions.push(bestBreakPositions.elementAti(i), status);
|
currentBreakPositions.push(bestBreakPositions.elementAti(i), status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bestBreakPositions.removeAllElements();
|
bestBreakPositions.removeAllElements();
|
||||||
if (farthestEndPoint < endPos) {
|
if (farthestEndPoint < endPos) {
|
||||||
@ -515,9 +530,15 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
|| currentBreakPositions.peeki() != fText->getIndex())
|
|| currentBreakPositions.peeki() != fText->getIndex())
|
||||||
&& fText->getIndex() != startPos) {
|
&& fText->getIndex() != startPos) {
|
||||||
currentBreakPositions.push(fText->getIndex(), status);
|
currentBreakPositions.push(fText->getIndex(), status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fText->next();
|
fText->next();
|
||||||
currentBreakPositions.push(fText->getIndex(), status);
|
currentBreakPositions.push(fText->getIndex(), status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,6 +582,9 @@ DictionaryBasedBreakIterator::divideUpDictionaryRange(int32_t startPos, int32_t
|
|||||||
currentBreakPositions.popi();
|
currentBreakPositions.popi();
|
||||||
}
|
}
|
||||||
currentBreakPositions.push(endPos, status);
|
currentBreakPositions.push(endPos, status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// create a regular array to hold the break positions and copy
|
// create a regular array to hold the break positions and copy
|
||||||
// the break positions from the stack to the array (in addition,
|
// the break positions from the stack to the array (in addition,
|
||||||
|
@ -46,8 +46,8 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedBreakIterator)
|
|||||||
RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status)
|
RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
fData = new RBBIDataWrapper(data, status); // status checked in constructor
|
||||||
if (U_FAILURE(status)) {return;}
|
if (U_FAILURE(status)) {return;}
|
||||||
fData = new RBBIDataWrapper(data, status);
|
|
||||||
if(fData == 0) {
|
if(fData == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return;
|
return;
|
||||||
@ -63,8 +63,8 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode
|
|||||||
RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &status)
|
RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &status)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
fData = new RBBIDataWrapper(udm, status); // status checked in constructor
|
||||||
if (U_FAILURE(status)) {return;}
|
if (U_FAILURE(status)) {return;}
|
||||||
fData = new RBBIDataWrapper(udm, status);
|
|
||||||
if(fData == 0) {
|
if(fData == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return;
|
return;
|
||||||
|
@ -47,7 +47,7 @@ RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
|
|||||||
UErrorCode &status)
|
UErrorCode &status)
|
||||||
: fRules(rules)
|
: fRules(rules)
|
||||||
{
|
{
|
||||||
fStatus = &status;
|
fStatus = &status; // status is checked below
|
||||||
fParseError = &parseErr;
|
fParseError = &parseErr;
|
||||||
fDebugEnv = NULL;
|
fDebugEnv = NULL;
|
||||||
#ifdef RBBI_DEBUG
|
#ifdef RBBI_DEBUG
|
||||||
@ -59,9 +59,18 @@ RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
|
|||||||
fReverseTree = NULL;
|
fReverseTree = NULL;
|
||||||
fForwardTables = NULL;
|
fForwardTables = NULL;
|
||||||
fReverseTables = NULL;
|
fReverseTables = NULL;
|
||||||
fUSetNodes = new UVector(status);
|
|
||||||
|
UErrorCode oldstatus = status;
|
||||||
|
|
||||||
|
fUSetNodes = new UVector(status); // bcos status gets overwritten here
|
||||||
fScanner = new RBBIRuleScanner(this);
|
fScanner = new RBBIRuleScanner(this);
|
||||||
fSetBuilder = new RBBISetBuilder(this);
|
fSetBuilder = new RBBISetBuilder(this);
|
||||||
|
if (U_FAILURE(oldstatus)) {
|
||||||
|
status = oldstatus;
|
||||||
|
}
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(fSetBuilder == 0 || fScanner == 0 || fUSetNodes == 0) {
|
if(fSetBuilder == 0 || fScanner == 0 || fUSetNodes == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
@ -176,9 +185,7 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
|
|||||||
UParseError &parseError,
|
UParseError &parseError,
|
||||||
UErrorCode &status)
|
UErrorCode &status)
|
||||||
{
|
{
|
||||||
if (U_FAILURE(status)) {
|
// status checked below
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read the input rules, generate a parse tree, symbol table,
|
// Read the input rules, generate a parse tree, symbol table,
|
||||||
@ -186,7 +193,7 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
|
|||||||
//
|
//
|
||||||
RBBIRuleBuilder builder(rules, parseError, status);
|
RBBIRuleBuilder builder(rules, parseError, status);
|
||||||
builder.fScanner->parse();
|
builder.fScanner->parse();
|
||||||
if (U_FAILURE(status)) {
|
if (U_FAILURE(status)) { // status checked here bcos build below doesn't
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +211,9 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
|
|||||||
//
|
//
|
||||||
builder.fForwardTables = new RBBITableBuilder(&builder, &builder.fForwardTree);
|
builder.fForwardTables = new RBBITableBuilder(&builder, &builder.fForwardTree);
|
||||||
builder.fReverseTables = new RBBITableBuilder(&builder, &builder.fReverseTree);
|
builder.fReverseTables = new RBBITableBuilder(&builder, &builder.fReverseTree);
|
||||||
if(builder.fForwardTables == NULL || builder.fReverseTables == NULL) {
|
if (U_SUCCESS(status)
|
||||||
|
&& (builder.fForwardTables == NULL || builder.fReverseTables == NULL))
|
||||||
|
{
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -220,8 +229,7 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
|
|||||||
// Package up the compiled data into a memory image
|
// Package up the compiled data into a memory image
|
||||||
// in the run-time format.
|
// in the run-time format.
|
||||||
//
|
//
|
||||||
RBBIDataHeader *data;
|
RBBIDataHeader *data = builder.flattenData(); // returns NULL if error
|
||||||
data = builder.flattenData();
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -233,17 +241,15 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
|
|||||||
// Create a break iterator from the compiled rules.
|
// Create a break iterator from the compiled rules.
|
||||||
// (Identical to creation from stored pre-compiled rules)
|
// (Identical to creation from stored pre-compiled rules)
|
||||||
//
|
//
|
||||||
|
// status is checked after init in construction.
|
||||||
RuleBasedBreakIterator *This = new RuleBasedBreakIterator(data, status);
|
RuleBasedBreakIterator *This = new RuleBasedBreakIterator(data, status);
|
||||||
/* test for NULL */
|
|
||||||
if(This == NULL) {
|
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (U_FAILURE(status)) {
|
if (U_FAILURE(status)) {
|
||||||
delete This;
|
delete This;
|
||||||
This = NULL;
|
This = NULL;
|
||||||
}
|
}
|
||||||
|
else if(This == NULL) { // test for NULL
|
||||||
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
|
}
|
||||||
return This;
|
return This;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,9 @@ U_NAMESPACE_BEGIN
|
|||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
|
RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
|
||||||
{
|
{
|
||||||
|
if (U_FAILURE(*rb->fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fRB = rb;
|
fRB = rb;
|
||||||
fStackPtr = 0;
|
fStackPtr = 0;
|
||||||
fStack[fStackPtr] = 0;
|
fStack[fStackPtr] = 0;
|
||||||
@ -113,10 +116,6 @@ RBBIRuleScanner::RBBIRuleScanner(RBBIRuleBuilder *rb)
|
|||||||
fCharNum = 0;
|
fCharNum = 0;
|
||||||
fQuoteMode = FALSE;
|
fQuoteMode = FALSE;
|
||||||
|
|
||||||
if (U_FAILURE(*rb->fStatus)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set up the constant Unicode Sets.
|
// Set up the constant Unicode Sets.
|
||||||
// Note: These could be made static, lazily initialized, and shared among
|
// Note: These could be made static, lazily initialized, and shared among
|
||||||
|
@ -135,10 +135,13 @@ void RBBISetBuilder::build() {
|
|||||||
// Initialize the process by creating a single range encompassing all characters
|
// Initialize the process by creating a single range encompassing all characters
|
||||||
// that is in no sets.
|
// that is in no sets.
|
||||||
//
|
//
|
||||||
fRangeList = new RangeDescriptor(*fStatus);
|
fRangeList = new RangeDescriptor(*fStatus); // will check for status here
|
||||||
fRangeList->fStartChar = 0;
|
fRangeList->fStartChar = 0;
|
||||||
fRangeList->fEndChar = 0x10ffff;
|
fRangeList->fEndChar = 0x10ffff;
|
||||||
|
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Find the set of non-overlapping ranges of characters
|
// Find the set of non-overlapping ranges of characters
|
||||||
@ -176,6 +179,9 @@ void RBBISetBuilder::build() {
|
|||||||
// over
|
// over
|
||||||
if (rlRange->fStartChar < inputSetRangeBegin) {
|
if (rlRange->fStartChar < inputSetRangeBegin) {
|
||||||
rlRange->split(inputSetRangeBegin, *fStatus);
|
rlRange->split(inputSetRangeBegin, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,12 +192,18 @@ void RBBISetBuilder::build() {
|
|||||||
// wholly inside the Unicode set.
|
// wholly inside the Unicode set.
|
||||||
if (rlRange->fEndChar > inputSetRangeEnd) {
|
if (rlRange->fEndChar > inputSetRangeEnd) {
|
||||||
rlRange->split(inputSetRangeEnd+1, *fStatus);
|
rlRange->split(inputSetRangeEnd+1, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The current rlRange is now entirely within the UnicodeSet range.
|
// The current rlRange is now entirely within the UnicodeSet range.
|
||||||
// Add this unicode set to the list of sets for this rlRange
|
// Add this unicode set to the list of sets for this rlRange
|
||||||
if (rlRange->fIncludesSets->indexOf(usetNode) == -1) {
|
if (rlRange->fIncludesSets->indexOf(usetNode) == -1) {
|
||||||
rlRange->fIncludesSets->addElement(usetNode, *fStatus);
|
rlRange->fIncludesSets->addElement(usetNode, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance over ranges that we are finished with.
|
// Advance over ranges that we are finished with.
|
||||||
@ -475,7 +487,14 @@ RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &statu
|
|||||||
this->fEndChar = other.fEndChar;
|
this->fEndChar = other.fEndChar;
|
||||||
this->fNum = other.fNum;
|
this->fNum = other.fNum;
|
||||||
this->fNext = NULL;
|
this->fNext = NULL;
|
||||||
|
UErrorCode oldstatus = status;
|
||||||
this->fIncludesSets = new UVector(status);
|
this->fIncludesSets = new UVector(status);
|
||||||
|
if (U_FAILURE(oldstatus)) {
|
||||||
|
status = oldstatus;
|
||||||
|
}
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (this->fIncludesSets == 0) {
|
if (this->fIncludesSets == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
@ -498,7 +517,14 @@ RangeDescriptor::RangeDescriptor(UErrorCode &status) {
|
|||||||
this->fEndChar = 0;
|
this->fEndChar = 0;
|
||||||
this->fNum = 0;
|
this->fNum = 0;
|
||||||
this->fNext = NULL;
|
this->fNext = NULL;
|
||||||
|
UErrorCode oldstatus = status;
|
||||||
this->fIncludesSets = new UVector(status);
|
this->fIncludesSets = new UVector(status);
|
||||||
|
if (U_FAILURE(oldstatus)) {
|
||||||
|
status = oldstatus;
|
||||||
|
}
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if(this->fIncludesSets == 0) {
|
if(this->fIncludesSets == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
@ -526,6 +552,9 @@ RangeDescriptor::~RangeDescriptor() {
|
|||||||
void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
|
void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
|
||||||
U_ASSERT(where>fStartChar && where<=fEndChar);
|
U_ASSERT(where>fStartChar && where<=fEndChar);
|
||||||
RangeDescriptor *nr = new RangeDescriptor(*this, status);
|
RangeDescriptor *nr = new RangeDescriptor(*this, status);
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if(nr == 0) {
|
if(nr == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
|
@ -43,11 +43,12 @@ RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules
|
|||||||
{
|
{
|
||||||
fHashTable = NULL;
|
fHashTable = NULL;
|
||||||
fCachedSetLookup = NULL;
|
fCachedSetLookup = NULL;
|
||||||
|
|
||||||
|
fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, &status);
|
||||||
|
// uhash_open checks status
|
||||||
if (U_FAILURE(status)) {
|
if (U_FAILURE(status)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, &status);
|
|
||||||
uhash_setValueDeleter(fHashTable, RBBISymbolTableEntry_deleter);
|
uhash_setValueDeleter(fHashTable, RBBISymbolTableEntry_deleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,18 @@ RBBITableBuilder::RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode) :
|
|||||||
fTree(*rootNode) {
|
fTree(*rootNode) {
|
||||||
fRB = rb;
|
fRB = rb;
|
||||||
fStatus = fRB->fStatus;
|
fStatus = fRB->fStatus;
|
||||||
fDStates = new UVector(*fStatus);
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
fDStates = new UVector(status);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (U_FAILURE(status)) {
|
||||||
|
*fStatus = status;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fDStates == NULL) {
|
||||||
|
*fStatus = U_MEMORY_ALLOCATION_ERROR;;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -309,19 +320,37 @@ void RBBITableBuilder::calcFollowPos(RBBINode *n) {
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void RBBITableBuilder::buildStateTable() {
|
void RBBITableBuilder::buildStateTable() {
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// Add a dummy state 0 - the stop state. Not from Aho.
|
// Add a dummy state 0 - the stop state. Not from Aho.
|
||||||
int lastInputSymbol = fRB->fSetBuilder->getNumCharCategories() - 1;
|
int lastInputSymbol = fRB->fSetBuilder->getNumCharCategories() - 1;
|
||||||
RBBIStateDescriptor *failState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
RBBIStateDescriptor *failState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
||||||
failState->fPositions = new UVector(*fStatus);
|
failState->fPositions = new UVector(*fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fDStates->addElement(failState, *fStatus);
|
fDStates->addElement(failState, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// initially, the only unmarked state in Dstates is firstpos(root),
|
// initially, the only unmarked state in Dstates is firstpos(root),
|
||||||
// where toot is the root of the syntax tree for (r)#;
|
// where toot is the root of the syntax tree for (r)#;
|
||||||
RBBIStateDescriptor *initialState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
RBBIStateDescriptor *initialState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
initialState->fPositions = new UVector(*fStatus);
|
initialState->fPositions = new UVector(*fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setAdd(initialState->fPositions, fTree->fFirstPosSet);
|
setAdd(initialState->fPositions, fTree->fFirstPosSet);
|
||||||
fDStates->addElement(initialState, *fStatus);
|
fDStates->addElement(initialState, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// while there is an unmarked state T in Dstates do begin
|
// while there is an unmarked state T in Dstates do begin
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -383,8 +412,14 @@ void RBBITableBuilder::buildStateTable() {
|
|||||||
if (!UinDstates)
|
if (!UinDstates)
|
||||||
{
|
{
|
||||||
RBBIStateDescriptor *newState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
RBBIStateDescriptor *newState = new RBBIStateDescriptor(lastInputSymbol, fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
newState->fPositions = U;
|
newState->fPositions = U;
|
||||||
fDStates->addElement(newState, *fStatus);
|
fDStates->addElement(newState, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ux = fDStates->size()-1;
|
ux = fDStates->size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,12 +442,22 @@ void RBBITableBuilder::buildStateTable() {
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void RBBITableBuilder::flagAcceptingStates() {
|
void RBBITableBuilder::flagAcceptingStates() {
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UVector endMarkerNodes(*fStatus);
|
UVector endMarkerNodes(*fStatus);
|
||||||
RBBINode *endMarker;
|
RBBINode *endMarker;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
int32_t n;
|
int32_t n;
|
||||||
|
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fTree->findNodes(&endMarkerNodes, RBBINode::endMark, *fStatus);
|
fTree->findNodes(&endMarkerNodes, RBBINode::endMark, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i<endMarkerNodes.size(); i++) {
|
for (i=0; i<endMarkerNodes.size(); i++) {
|
||||||
endMarker = (RBBINode *)endMarkerNodes.elementAt(i);
|
endMarker = (RBBINode *)endMarkerNodes.elementAt(i);
|
||||||
@ -444,12 +489,18 @@ void RBBITableBuilder::flagAcceptingStates() {
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void RBBITableBuilder::flagLookAheadStates() {
|
void RBBITableBuilder::flagLookAheadStates() {
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UVector lookAheadNodes(*fStatus);
|
UVector lookAheadNodes(*fStatus);
|
||||||
RBBINode *lookAheadNode;
|
RBBINode *lookAheadNode;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
int32_t n;
|
int32_t n;
|
||||||
|
|
||||||
fTree->findNodes(&lookAheadNodes, RBBINode::lookAhead, *fStatus);
|
fTree->findNodes(&lookAheadNodes, RBBINode::lookAhead, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (i=0; i<lookAheadNodes.size(); i++) {
|
for (i=0; i<lookAheadNodes.size(); i++) {
|
||||||
lookAheadNode = (RBBINode *)lookAheadNodes.elementAt(i);
|
lookAheadNode = (RBBINode *)lookAheadNodes.elementAt(i);
|
||||||
|
|
||||||
@ -471,12 +522,21 @@ void RBBITableBuilder::flagLookAheadStates() {
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void RBBITableBuilder::flagTaggedStates() {
|
void RBBITableBuilder::flagTaggedStates() {
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UVector tagNodes(*fStatus);
|
UVector tagNodes(*fStatus);
|
||||||
RBBINode *tagNode;
|
RBBINode *tagNode;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
int32_t n;
|
int32_t n;
|
||||||
|
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fTree->findNodes(&tagNodes, RBBINode::tag, *fStatus);
|
fTree->findNodes(&tagNodes, RBBINode::tag, *fStatus);
|
||||||
|
if (U_FAILURE(*fStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (i=0; i<tagNodes.size(); i++) { // For each tag node t (all of 'em)
|
for (i=0; i<tagNodes.size(); i++) { // For each tag node t (all of 'em)
|
||||||
tagNode = (RBBINode *)tagNodes.elementAt(i);
|
tagNode = (RBBINode *)tagNodes.elementAt(i);
|
||||||
|
|
||||||
@ -507,7 +567,7 @@ void RBBITableBuilder::setAdd(UVector *dest, UVector *source) {
|
|||||||
int sourceSize = source->size();
|
int sourceSize = source->size();
|
||||||
int32_t si, di;
|
int32_t si, di;
|
||||||
|
|
||||||
for (si=0; si<sourceSize; si++) {
|
for (si=0; si<sourceSize && U_SUCCESS(*fStatus); si++) {
|
||||||
void *elToAdd = source->elementAt(si);
|
void *elToAdd = source->elementAt(si);
|
||||||
for (di=0; di<destOriginalSize; di++) {
|
for (di=0; di<destOriginalSize; di++) {
|
||||||
if (dest->elementAt(di) == elToAdd) {
|
if (dest->elementAt(di) == elToAdd) {
|
||||||
@ -730,10 +790,16 @@ RBBIStateDescriptor::RBBIStateDescriptor(int lastInputSymbol, UErrorCode *fStatu
|
|||||||
fTagVal = 0;
|
fTagVal = 0;
|
||||||
fPositions = NULL;
|
fPositions = NULL;
|
||||||
fDtran = NULL;
|
fDtran = NULL;
|
||||||
|
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
fDtran = new UVector(lastInputSymbol+1, status);
|
||||||
if (U_FAILURE(*fStatus)) {
|
if (U_FAILURE(*fStatus)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fDtran = new UVector(lastInputSymbol+1, *fStatus);
|
if (U_FAILURE(status)) {
|
||||||
|
*fStatus = status;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (fDtran == NULL) {
|
if (fDtran == NULL) {
|
||||||
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user