ICU-12071 Make RuleBasedBreakIterator a final class.

X-SVN-Rev: 38626
This commit is contained in:
Andy Heninger 2016-04-19 00:06:56 +00:00
parent 13be2f95ae
commit f576761ec7
4 changed files with 23 additions and 51 deletions

View file

@ -1,6 +1,6 @@
/*
***************************************************************************
* Copyright (C) 1999-2014 International Business Machines Corporation *
* Copyright (C) 1999-2016 International Business Machines Corporation *
* and others. All rights reserved. *
***************************************************************************
@ -30,6 +30,7 @@
#include "unicode/uchriter.h"
class RBBIAPITest;
struct UTrie;
U_NAMESPACE_BEGIN
@ -56,13 +57,10 @@ struct RBBIStateTable;
*
* <p>See the ICU User Guide for information on Break Iterator Rules.</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>
* <p>This class is not intended to be subclassed.</p>
*
*/
class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator {
class U_COMMON_API RuleBasedBreakIterator U_FINAL : public BreakIterator {
protected:
/**
@ -139,7 +137,7 @@ protected:
* @internal
*/
int32_t fPositionInCache;
/**
*
* If present, UStack of LanguageBreakEngine objects that might handle
@ -148,7 +146,7 @@ protected:
* @internal
*/
UStack *fLanguageBreakEngines;
/**
*
* If present, the special LanguageBreakEngine used for handling
@ -157,14 +155,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
@ -248,7 +246,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.
@ -763,6 +761,7 @@ private:
*/
void makeRuleStatusValid();
friend class ::RBBIAPITest; // for access to ctors
};
//------------------------------------------------------------------------------

View file

@ -1,5 +1,5 @@
/********************************************************************
* Copyright (c) 1999-2014, International Business Machines
* Copyright (c) 1999-2016, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************
* Date Name Description
@ -1058,8 +1058,7 @@ void RBBIAPITest::TestRoundtripRules() {
}
}
// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*
// (these are protected so we access them via a local class RBBIWithProtectedFunctions).
// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*.
// 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() {
@ -1070,14 +1069,14 @@ void RBBIAPITest::TestCreateFromRBBIData() {
if ( U_SUCCESS(status) ) {
const RBBIDataHeader * builtRules = (const RBBIDataHeader *)udata_getMemory(data.getAlias());
uint32_t length = builtRules->fLength;
RBBIWithProtectedFunctions * brkItr;
RuleBasedBreakIterator * 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 RBBIWithProtectedFunctions(rulesCopy, status);
brkItr = new RuleBasedBreakIterator(rulesCopy, status);
if ( U_SUCCESS(status) ) {
delete brkItr; // this should free rulesCopy
} else {
@ -1088,7 +1087,7 @@ void RBBIAPITest::TestCreateFromRBBIData() {
}
// Now try the non-adopting constructor
brkItr = new RBBIWithProtectedFunctions(builtRules, RBBIWithProtectedFunctions::kDontAdopt, status);
brkItr = new RuleBasedBreakIterator(builtRules, RuleBasedBreakIterator::kDontAdopt, status);
if ( U_SUCCESS(status) ) {
delete brkItr; // this should NOT attempt to free builtRules
if (builtRules->fLength != length) { // sanity check
@ -1504,18 +1503,4 @@ 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 */

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1999-2014 International Business Machines Corporation and
* 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,18 +101,6 @@ 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

View file

@ -1043,7 +1043,7 @@ void RBBITest::executeTest(TestParams *t, UErrorCode &status) {
expectedTagVal = 0;
}
int32_t line = t->getSrcLine(bp);
int32_t rs = ((RuleBasedBreakIterator *)t->bi)->getRuleStatus();
int32_t rs = 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",