#include "unicode/uchriter.h"
-class RBBIAPITest;
struct UTrie;
U_NAMESPACE_BEGIN
*
* <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:
/**
* @internal
*/
int32_t fPositionInCache;
-
+
/**
*
* If present, UStack of LanguageBreakEngine objects that might handle
* @internal
*/
UStack *fLanguageBreakEngines;
-
+
/**
*
* If present, the special LanguageBreakEngine used for handling
* @internal
*/
UnhandledEngine *fUnhandledBreakEngine;
-
+
/**
*
* The type of the break iterator, or -1 if it has not been set.
* @internal
*/
int32_t fBreakType;
-
+
protected:
//=======================================================================
// constructors
* 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.
*/
void makeRuleStatusValid();
- friend class ::RBBIAPITest; // for access to ctors
};
//------------------------------------------------------------------------------
}
}
-// 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() {
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 {
}
// 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
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 */
/********************************************************************
- * 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();
/**
/**
*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 */
};
+/**
+ * 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
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",