From: Andy Heninger Date: Tue, 19 Apr 2016 00:26:46 +0000 (+0000) Subject: ICU-12071 revert premature commit for making RuleBasedBreakIterator final. X-Git-Tag: milestone-59-0-1~498 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c7cfc31bc195d0563af267df05f7ef257960eea;p=icu ICU-12071 revert premature commit for making RuleBasedBreakIterator final. X-SVN-Rev: 38627 --- diff --git a/icu4c/source/common/unicode/rbbi.h b/icu4c/source/common/unicode/rbbi.h index eb395d7d65e..589c457116d 100644 --- a/icu4c/source/common/unicode/rbbi.h +++ b/icu4c/source/common/unicode/rbbi.h @@ -30,7 +30,6 @@ #include "unicode/uchriter.h" -class RBBIAPITest; struct UTrie; U_NAMESPACE_BEGIN @@ -57,10 +56,13 @@ struct RBBIStateTable; * *

See the ICU User Guide for information on Break Iterator Rules.

* - *

This class is not intended to be subclassed.

+ *

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.

* */ -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 }; //------------------------------------------------------------------------------ diff --git a/icu4c/source/test/intltest/rbbiapts.cpp b/icu4c/source/test/intltest/rbbiapts.cpp index 18923760615..1e6d18f9c9d 100644 --- a/icu4c/source/test/intltest/rbbiapts.cpp +++ b/icu4c/source/test/intltest/rbbiapts.cpp @@ -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 */ diff --git a/icu4c/source/test/intltest/rbbiapts.h b/icu4c/source/test/intltest/rbbiapts.h index 3493675dc76..278fac08c6f 100644 --- a/icu4c/source/test/intltest/rbbiapts.h +++ b/icu4c/source/test/intltest/rbbiapts.h @@ -1,5 +1,5 @@ /******************************************************************** - * COPYRIGHT: + * COPYRIGHT: * Copyright (c) 1999-2016 International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -25,15 +25,15 @@ */ 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 diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index 6f184370408..045cea024af 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -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",