]> granicus.if.org Git - icu/commitdiff
ICU-12071 revert premature commit for making RuleBasedBreakIterator final.
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 19 Apr 2016 00:26:46 +0000 (00:26 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 19 Apr 2016 00:26:46 +0000 (00:26 +0000)
X-SVN-Rev: 38627

icu4c/source/common/unicode/rbbi.h
icu4c/source/test/intltest/rbbiapts.cpp
icu4c/source/test/intltest/rbbiapts.h
icu4c/source/test/intltest/rbbitst.cpp

index eb395d7d65e0adc6852a8a7a23e673e4558fd297..589c457116dfe65b244b5101b4362d79c147566d 100644 (file)
@@ -30,7 +30,6 @@
 #include "unicode/uchriter.h"
 
 
-class RBBIAPITest;
 struct UTrie;
 
 U_NAMESPACE_BEGIN
@@ -57,10 +56,13 @@ struct RBBIStateTable;
  *
  * <p>See the ICU User Guide for information on Break Iterator Rules.</p>
  *
- * <p>This class is not intended to be subclassed.</p>
+ * <p>This class is not intended to be subclassed.  (Class DictionaryBasedBreakIterator
+ *    is a subclass, but that relationship is effectively internal to the ICU
+ *    implementation.  The subclassing interface to RulesBasedBreakIterator is
+ *    not part of the ICU API, and may not remain stable.</p>
  *
  */
-class U_COMMON_API RuleBasedBreakIterator U_FINAL : public BreakIterator {
+class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator {
 
 protected:
     /**
@@ -137,7 +139,7 @@ protected:
      * @internal
      */
     int32_t             fPositionInCache;
-
+    
     /**
      *
      * If present, UStack of LanguageBreakEngine objects that might handle
@@ -146,7 +148,7 @@ protected:
      * @internal
      */
     UStack              *fLanguageBreakEngines;
-
+    
     /**
      *
      * If present, the special LanguageBreakEngine used for handling
@@ -155,14 +157,14 @@ protected:
      * @internal
      */
     UnhandledEngine     *fUnhandledBreakEngine;
-
+    
     /**
      *
      * The type of the break iterator, or -1 if it has not been set.
      * @internal
      */
     int32_t             fBreakType;
-
+    
 protected:
     //=======================================================================
     // constructors
@@ -246,7 +248,7 @@ public:
      * constuction from source rules.
      *
      * Ownership of the storage containing the compiled rules remains with the
-     * caller of this function.  The compiled rules must not be  modified or
+     * caller of this function.  The compiled rules must not be  modified or 
      * deleted during the life of the break iterator.
      *
      * The compiled rules are not compatible across different major versions of ICU.
@@ -761,7 +763,6 @@ private:
      */
     void makeRuleStatusValid();
 
-    friend class ::RBBIAPITest; // for access to ctors
 };
 
 //------------------------------------------------------------------------------
index 189237606151e56496877a56d836cb7c56c18ada..1e6d18f9c9ddb99cde70e9f1fa1932cee65ec83f 100644 (file)
@@ -1058,7 +1058,8 @@ void RBBIAPITest::TestRoundtripRules() {
     }
 }
 
-// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*.
+// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*
+// (these are protected so we access them via a local class RBBIWithProtectedFunctions).
 // This is just a sanity check, not a thorough test (e.g. we don't check that the
 // first delete actually frees rulesCopy).
 void RBBIAPITest::TestCreateFromRBBIData() {
@@ -1069,14 +1070,14 @@ void RBBIAPITest::TestCreateFromRBBIData() {
     if ( U_SUCCESS(status) ) {
         const RBBIDataHeader * builtRules = (const RBBIDataHeader *)udata_getMemory(data.getAlias());
         uint32_t length = builtRules->fLength;
-        RuleBasedBreakIterator * brkItr;
+        RBBIWithProtectedFunctions * brkItr;
 
         // Try the memory-adopting constructor, need to copy the data first
         RBBIDataHeader * rulesCopy = (RBBIDataHeader *) uprv_malloc(length);
         if ( rulesCopy ) {
             uprv_memcpy( rulesCopy, builtRules, length );
 
-            brkItr = new RuleBasedBreakIterator(rulesCopy, status);
+            brkItr = new RBBIWithProtectedFunctions(rulesCopy, status);
             if ( U_SUCCESS(status) ) {
                 delete brkItr; // this should free rulesCopy
             } else {
@@ -1087,7 +1088,7 @@ void RBBIAPITest::TestCreateFromRBBIData() {
         }
 
         // Now try the non-adopting constructor
-        brkItr = new RuleBasedBreakIterator(builtRules, RuleBasedBreakIterator::kDontAdopt, status);
+        brkItr = new RBBIWithProtectedFunctions(builtRules, RBBIWithProtectedFunctions::kDontAdopt, status);
         if ( U_SUCCESS(status) ) {
             delete brkItr; // this should NOT attempt to free builtRules
             if (builtRules->fLength != length) { // sanity check
@@ -1503,4 +1504,18 @@ void RBBIAPITest::doTest(UnicodeString& testString, int32_t start, int32_t gotof
         logln(prettify("****selected \"" + selected + "\""));
 }
 
+//---------------------------------------------
+//RBBIWithProtectedFunctions class functions
+//---------------------------------------------
+
+RBBIWithProtectedFunctions::RBBIWithProtectedFunctions(RBBIDataHeader* data, UErrorCode &status)
+    : RuleBasedBreakIterator(data, status)
+{
+}
+
+RBBIWithProtectedFunctions::RBBIWithProtectedFunctions(const RBBIDataHeader* data, enum EDontAdopt, UErrorCode &status)
+    : RuleBasedBreakIterator(data, RuleBasedBreakIterator::kDontAdopt, status)
+{
+}
+
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
index 3493675dc76d42d0ea37bdfddc49eccec768a062..278fac08c6f112d6a53805e9330c7de5eb8a9a3c 100644 (file)
@@ -1,5 +1,5 @@
 /********************************************************************
- * COPYRIGHT:
+ * COPYRIGHT: 
  * Copyright (c) 1999-2016 International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
  */
 class RBBIAPITest: public IntlTest {
 public:
-
-
+   
+    
     void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
     /**
      * Tests Constructor behaviour of RuleBasedBreakIterator
      **/
-   // void TestConstruction(void);
+   // void TestConstruction(void);   
     /**
-     * Tests clone() and equals() methods of RuleBasedBreakIterator
+     * Tests clone() and equals() methods of RuleBasedBreakIterator         
      **/
     void TestCloneEquals();
     /**
@@ -92,7 +92,7 @@ public:
     /**
      *Internal subroutines
      **/
-    /* Internal subroutine used by TestIsBoundary() */
+    /* Internal subroutine used by TestIsBoundary() */ 
     void doBoundaryTest(BreakIterator& bi, UnicodeString& text, int32_t *boundaries);
 
     /*Internal subroutine used for comparision of expected and acquired results */
@@ -101,6 +101,18 @@ public:
 
 };
 
+/**
+ * Special class to enable testing of protected functions in RuleBasedBreakIterator
+ */
+class RBBIWithProtectedFunctions: public RuleBasedBreakIterator {
+public:
+    enum EDontAdopt {
+        kDontAdopt
+    };
+    RBBIWithProtectedFunctions(RBBIDataHeader* data, UErrorCode &status);
+    RBBIWithProtectedFunctions(const RBBIDataHeader* data, enum EDontAdopt dontAdopt, UErrorCode &status);
+};
+
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
 
 #endif
index 6f184370408ad0722712b103258bfa0408bfe95d..045cea024af068003e02d96b7835976b47dd0ae5 100644 (file)
@@ -1043,7 +1043,7 @@ void RBBITest::executeTest(TestParams *t, UErrorCode &status) {
                 expectedTagVal = 0;
             }
             int32_t line = t->getSrcLine(bp);
-            int32_t rs = t->bi->getRuleStatus();
+            int32_t rs = ((RuleBasedBreakIterator *)t->bi)->getRuleStatus();
             if (rs != expectedTagVal) {
                 errln("Incorrect status for forward break.  Pos=%4d  File line,col= %4d,%4d.\n"
                       "          Actual, Expected status = %4d, %4d",