diff --git a/icu4c/source/common/rbbinode.cpp b/icu4c/source/common/rbbinode.cpp index 8c1ee8baf82..123c21e44cf 100644 --- a/icu4c/source/common/rbbinode.cpp +++ b/icu4c/source/common/rbbinode.cpp @@ -169,8 +169,6 @@ RBBINode *RBBINode::cloneTree() { } } } - n->fRuleRoot = this->fRuleRoot; - n->fChainIn = this->fChainIn; return n; } @@ -196,8 +194,12 @@ RBBINode *RBBINode::cloneTree() { //------------------------------------------------------------------------- RBBINode *RBBINode::flattenVariables() { if (fType == varRef) { - RBBINode *retNode = fLeftChild->cloneTree(); - delete this; + RBBINode *retNode = fLeftChild->cloneTree(); + if (retNode != NULL) { + retNode->fRuleRoot = this->fRuleRoot; + retNode->fChainIn = this->fChainIn; + } + delete this; // TODO: undefined behavior. Fix. return retNode; } diff --git a/icu4c/source/common/rbbistbl.cpp b/icu4c/source/common/rbbistbl.cpp index 09e928daf80..d937edbd7c3 100644 --- a/icu4c/source/common/rbbistbl.cpp +++ b/icu4c/source/common/rbbistbl.cpp @@ -19,10 +19,10 @@ #include "unicode/uchar.h" #include "unicode/parsepos.h" -#include "umutex.h" - -#include "rbbirb.h" +#include "cstr.h" #include "rbbinode.h" +#include "rbbirb.h" +#include "umutex.h" // @@ -228,9 +228,9 @@ RBBISymbolTableEntry::~RBBISymbolTableEntry() { // #ifdef RBBI_DEBUG void RBBISymbolTable::rbbiSymtablePrint() const { - RBBIDebugPrintf("Variable Definitions\n" - "Name Node Val String Val\n" - "----------------------------------------------------------------------\n"); + RBBIDebugPrintf("Variable Definitions Symbol Table\n" + "Name Node serial String Val\n" + "-------------------------------------------------------------------\n"); int32_t pos = UHASH_FIRST; const UHashElement *e = NULL; @@ -241,10 +241,8 @@ void RBBISymbolTable::rbbiSymtablePrint() const { } RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer; - RBBI_DEBUG_printUnicodeString(s->key, 15); - RBBIDebugPrintf(" %8p ", (void *)s->val); - RBBI_DEBUG_printUnicodeString(s->val->fLeftChild->fText); - RBBIDebugPrintf("\n"); + RBBIDebugPrintf("%-19s %8p %7d ", CStr(s->key)(), (void *)s->val, s->val->fSerialNum); + RBBIDebugPrintf(" %s\n", CStr(s->val->fLeftChild->fText)()); } RBBIDebugPrintf("\nParsed Variable Definitions\n"); @@ -255,8 +253,9 @@ void RBBISymbolTable::rbbiSymtablePrint() const { break; } RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer; - RBBI_DEBUG_printUnicodeString(s->key); - RBBINode::printTree(s->val->fLeftChild, TRUE); + RBBIDebugPrintf("%s\n", CStr(s->key)()); + RBBINode::printTree(s->val, TRUE); + RBBINode::printTree(s->val->fLeftChild, FALSE); RBBIDebugPrintf("\n"); } } diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index a7939c543c3..a3102c12d84 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -102,6 +102,7 @@ void RBBITest::runIndexedTest( int32_t index, UBool exec, const char* &name, cha TESTCASE_AUTO(TestDictRules); TESTCASE_AUTO(TestBug5532); TESTCASE_AUTO(TestBug7547); + TESTCASE_AUTO(TestBug12797); TESTCASE_AUTO_END; } @@ -4633,35 +4634,32 @@ void RBBITest::TestBug7547() { } +void RBBITest::TestBug12797() { + UnicodeString rules = "!!chain; !!forward; $v=b c; a b; $v; !!reverse; .*;"; + UErrorCode status = U_ZERO_ERROR; + UParseError parseError; + RuleBasedBreakIterator bi(rules, parseError, status); + if (U_FAILURE(status)) { + errln("%s:%s status = %s", __FILE__, __LINE__, u_errorName(status)); + return; + } + UnicodeString text = "abc"; + bi.setText(text); + bi.first(); + int32_t boundary = bi.next(); + if (boundary != 3) { + errln("%s:%d expected boundary==3, got %d", __FILE__, __LINE__, boundary); + } +} + + // // TestDebug - A place-holder test for debugging purposes. // For putting in fragments of other tests that can be invoked // for tracing without a lot of unwanted extra stuff happening. // void RBBITest::TestDebug(void) { -#if 0 - UErrorCode status = U_ZERO_ERROR; - int pos = 0; - int ruleStatus = 0; - RuleBasedBreakIterator* bi = - // (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getDefault(), status); - // (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::Locale("th"), status); - (RuleBasedBreakIterator *)BreakIterator::createSentenceInstance(Locale::getDefault(), status); - UnicodeString s("\\u2008\\u002e\\udc6a\\u37cd\\u71d0\\u2048\\U000e006a\\u002e\\u0046\\ufd3f\\u000a\\u002e"); - // UnicodeString s("Aaa. Bcd"); - s = s.unescape(); - bi->setText(s); - UBool r = bi->isBoundary(8); - printf("%s", r?"true":"false"); - return; - pos = bi->last(); - do { - // ruleStatus = bi->getRuleStatus(); - printf("%d\t%d\n", pos, ruleStatus); - pos = bi->previous(); - } while (pos != BreakIterator::DONE); -#endif } void RBBITest::TestProperties() { diff --git a/icu4c/source/test/intltest/rbbitst.h b/icu4c/source/test/intltest/rbbitst.h index 5d4c9696382..6b2c2f0eb72 100644 --- a/icu4c/source/test/intltest/rbbitst.h +++ b/icu4c/source/test/intltest/rbbitst.h @@ -75,6 +75,7 @@ public: void TestBug5532(); void TestBug9983(); void TestBug7547(); + void TestBug12797(); void TestDebug(); void TestProperties();