]> granicus.if.org Git - icu/commitdiff
ICU-12797 RBBI rule compiler fix.
authorAndy Heninger <andy.heninger@gmail.com>
Mon, 10 Oct 2016 21:49:01 +0000 (21:49 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Mon, 10 Oct 2016 21:49:01 +0000 (21:49 +0000)
X-SVN-Rev: 39432

icu4c/source/common/rbbinode.cpp
icu4c/source/common/rbbistbl.cpp
icu4c/source/test/intltest/rbbitst.cpp
icu4c/source/test/intltest/rbbitst.h

index 8c1ee8baf82418e5b89b4b0ae80e399c000709d0..123c21e44cf3dd83d30f385cab0350daa03219ae 100644 (file)
@@ -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;
     }
 
index 09e928daf801c4523a801fc7591516324e2cc9d6..d937edbd7c33c2dc44ded43f5c157bfe36239575 100644 (file)
 #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");
     }
 }
index a7939c543c313b201892457c36f0e2097b5b6788..a3102c12d843826c279838445734ccd4c2fd2ce2 100644 (file)
@@ -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() {
index 5d4c96963827dc84a25ae1cfd38988970e975088..6b2c2f0eb72f36ac9dcc5dc599729f92d000ff3d 100644 (file)
@@ -75,6 +75,7 @@ public:
     void TestBug5532();
     void TestBug9983();
     void TestBug7547();
+    void TestBug12797();
 
     void TestDebug();
     void TestProperties();