rbbi.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
***************************************************************************
* Copyright (C) 1999-2016 International Business Machines Corporation *
* and others. All rights reserved. *
***************************************************************************
**********************************************************************
* Date Name Description
* 10/22/99 alan Creation.
* 11/11/99 rgillam Complete port from Java.
**********************************************************************
*/
#ifndef RBBI_H
#define RBBI_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_BREAK_ITERATION
#include "unicode/brkiter.h"
#include "unicode/udata.h"
#include "unicode/parseerr.h"
#include "unicode/schriter.h"
struct UCPTrie;
U_NAMESPACE_BEGIN
class LanguageBreakEngine;
struct RBBIDataHeader;
class RBBIDataWrapper;
class UnhandledEngine;
class UStack;
#ifndef U_HIDE_DRAFT_API
class ExternalBreakEngine : public UObject {
public:
virtual ~ExternalBreakEngine() {}
virtual bool isFor(UChar32 c, const char* locale) const = 0;
virtual bool handles(UChar32 c) const = 0;
virtual int32_t fillBreaks(UText* text, int32_t start, int32_t end,
int32_t* foundBreaks, int32_t foundBreaksCapacity,
UErrorCode& status) const = 0;
};
#endif /* U_HIDE_DRAFT_API */
class U_COMMON_API RuleBasedBreakIterator /*final*/ : public BreakIterator {
private:
UText fText = UTEXT_INITIALIZER;
#ifndef U_HIDE_INTERNAL_API
public:
#endif /* U_HIDE_INTERNAL_API */
RBBIDataWrapper *fData = nullptr;
private:
UErrorCode fErrorCode = U_ZERO_ERROR;
int32_t fPosition = 0;
int32_t fRuleStatusIndex = 0;
class BreakCache;
BreakCache *fBreakCache = nullptr;
class DictionaryCache;
DictionaryCache *fDictionaryCache = nullptr;
UStack *fLanguageBreakEngines = nullptr;
UnhandledEngine *fUnhandledBreakEngine = nullptr;
uint32_t fDictionaryCharCount = 0;
CharacterIterator *fCharIter = &fSCharIter;
UCharCharacterIterator fSCharIter {u"", 0};
bool fDone = false;
int32_t *fLookAheadMatches = nullptr;
UBool fIsPhraseBreaking = false;
//=======================================================================
// constructors
//=======================================================================
RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
RuleBasedBreakIterator(UDataMemory* image, UBool isPhraseBreaking, UErrorCode &status);
friend class RBBIRuleBuilder;
friend class BreakIterator;
RuleBasedBreakIterator(UErrorCode *status);
public:
RuleBasedBreakIterator();
RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
RuleBasedBreakIterator( const UnicodeString &rules,
UParseError &parseError,
UErrorCode &status);
RuleBasedBreakIterator(const uint8_t *compiledRules,
uint32_t ruleLength,
UErrorCode &status);
RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
virtual ~RuleBasedBreakIterator();
RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
virtual bool operator==(const BreakIterator& that) const override;
inline bool operator!=(const BreakIterator& that) const {
return !operator==(that);
}
virtual RuleBasedBreakIterator* clone() const override;
virtual int32_t hashCode(void) const;
virtual const UnicodeString& getRules(void) const;
//=======================================================================
// BreakIterator overrides
//=======================================================================
virtual CharacterIterator& getText(void) const override;
virtual UText *getUText(UText *fillIn, UErrorCode &status) const override;
virtual void adoptText(CharacterIterator* newText) override;
virtual void setText(const UnicodeString& newText) override;
virtual void setText(UText *text, UErrorCode &status) override;
virtual int32_t first(void) override;
virtual int32_t last(void) override;
virtual int32_t next(int32_t n) override;
virtual int32_t next(void) override;
virtual int32_t previous(void) override;
virtual int32_t following(int32_t offset) override;
virtual int32_t preceding(int32_t offset) override;
virtual UBool isBoundary(int32_t offset) override;
virtual int32_t current(void) const override;
virtual int32_t getRuleStatus() const override;
virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override;
virtual UClassID getDynamicClassID(void) const override;
static UClassID U_EXPORT2 getStaticClassID(void);
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer,
int32_t &BufferSize,
UErrorCode &status) override;
#endif // U_FORCE_HIDE_DEPRECATED_API
virtual const uint8_t *getBinaryRules(uint32_t &length);
virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status) override;
private:
//=======================================================================
// implementation
//=======================================================================
int32_t handleSafePrevious(int32_t fromPosition);
int32_t handleNext();
/*
* Templatized version of handleNext() and handleSafePrevious().
*
* There will be exactly four instantiations, two each for 8 and 16 bit tables,
* two each for 8 and 16 bit trie.
* Having separate instantiations for the table types keeps conditional tests of
* the table type out of the inner loops, at the expense of replicated code.
*
* The template parameter for the Trie access function is a value, not a type.
* Doing it this way, the compiler will inline the Trie function in the
* expanded functions. (Both the 8 and 16 bit access functions have the same type
* signature)
*/
typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
template<typename RowType, PTrieFunc trieFunc>
int32_t handleSafePrevious(int32_t fromPosition);
template<typename RowType, PTrieFunc trieFunc>
int32_t handleNext();
const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c, const char* locale);
public:
#ifndef U_HIDE_INTERNAL_API
void dumpCache();
void dumpTables();
#endif /* U_HIDE_INTERNAL_API */
#ifndef U_HIDE_DRAFT_API
static void U_EXPORT2 registerExternalBreakEngine(
ExternalBreakEngine* toAdopt, UErrorCode& status);
#endif /* U_HIDE_DRAFT_API */
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
brkiter.h
C++ API: Break Iterator.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:106
icu::BreakIterator::operator==
virtual bool operator==(const BreakIterator &) const =0
Return true if another object is semantically equal to this one.
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::ExternalBreakEngine
The ExternalBreakEngine class define an abstract interface for the host environment to provide a low ...
Definition: rbbi.h:60
icu::ExternalBreakEngine::isFor
virtual bool isFor(UChar32 c, const char *locale) const =0
icu::ExternalBreakEngine::fillBreaks
virtual int32_t fillBreaks(UText *text, int32_t start, int32_t end, int32_t *foundBreaks, int32_t foundBreaksCapacity, UErrorCode &status) const =0
icu::ExternalBreakEngine::handles
virtual bool handles(UChar32 c) const =0
icu::ExternalBreakEngine::~ExternalBreakEngine
virtual ~ExternalBreakEngine()
destructor
Definition: rbbi.h:66
icu::RuleBasedBreakIterator
A subclass of BreakIterator whose behavior is specified using a list of rules.
Definition: rbbi.h:120
icu::RuleBasedBreakIterator::current
virtual int32_t current(void) const override
Returns the current iteration position.
icu::RuleBasedBreakIterator::following
virtual int32_t following(int32_t offset) override
Sets the iterator to refer to the first boundary position following the specified position.
icu::RuleBasedBreakIterator::operator==
virtual bool operator==(const BreakIterator &that) const override
Equality operator.
icu::RuleBasedBreakIterator::refreshInputText
virtual RuleBasedBreakIterator & refreshInputText(UText *input, UErrorCode &status) override
Set the subject text string upon which the break iterator is operating without changing any other asp...
icu::RuleBasedBreakIterator::operator=
RuleBasedBreakIterator & operator=(const RuleBasedBreakIterator &that)
Assignment operator.
icu::RuleBasedBreakIterator::dumpTables
void dumpTables()
Debugging function only.
icu::RuleBasedBreakIterator::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override
Returns a unique class ID POLYMORPHICALLY.
icu::RuleBasedBreakIterator::last
virtual int32_t last(void) override
Sets the current iteration position to the end of the text.
icu::RuleBasedBreakIterator::getRuleStatus
virtual int32_t getRuleStatus() const override
Return the status tag from the break rule that determined the boundary at the current iteration posit...
icu::RuleBasedBreakIterator::createBufferClone
virtual RuleBasedBreakIterator * createBufferClone(void *stackBuffer, int32_t &BufferSize, UErrorCode &status) override
Deprecated functionality.
icu::RuleBasedBreakIterator::isBoundary
virtual UBool isBoundary(int32_t offset) override
Returns true if the specified position is a boundary position.
icu::RuleBasedBreakIterator::operator!=
bool operator!=(const BreakIterator &that) const
Not-equal operator.
Definition: rbbi.h:370
icu::RuleBasedBreakIterator::clone
virtual RuleBasedBreakIterator * clone() const override
Returns a newly-constructed RuleBasedBreakIterator with the same behavior, and iterating over the sam...
icu::RuleBasedBreakIterator::dumpCache
void dumpCache()
Debugging function only.
icu::RuleBasedBreakIterator::registerExternalBreakEngine
static void registerExternalBreakEngine(ExternalBreakEngine *toAdopt, UErrorCode &status)
Register a new external break engine.
icu::RuleBasedBreakIterator::RuleBasedBreakIterator
RuleBasedBreakIterator()
Default constructor.
icu::RuleBasedBreakIterator::getRuleStatusVec
virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override
Get the status (tag) values from the break rule(s) that determined the boundary at the current iterat...
icu::RuleBasedBreakIterator::getBinaryRules
virtual const uint8_t * getBinaryRules(uint32_t &length)
Return the binary form of compiled break rules, which can then be used to create a new break iterator...
icu::RuleBasedBreakIterator::first
virtual int32_t first(void) override
Sets the current iteration position to the beginning of the text, position zero.
icu::RuleBasedBreakIterator::getStaticClassID
static UClassID getStaticClassID(void)
Returns the class ID for this class.
icu::RuleBasedBreakIterator::preceding
virtual int32_t preceding(int32_t offset) override
Sets the iterator to refer to the last boundary position before the specified position.
icu::RuleBasedBreakIterator::RuleBasedBreakIterator
RuleBasedBreakIterator(const RuleBasedBreakIterator &that)
Copy constructor.
icu::RuleBasedBreakIterator::previous
virtual int32_t previous(void) override
Moves the iterator backwards, to the last boundary preceding this one.
icu::RuleBasedBreakIterator::adoptText
virtual void adoptText(CharacterIterator *newText) override
Set the iterator to analyze a new piece of text.
icu::RuleBasedBreakIterator::getUText
virtual UText * getUText(UText *fillIn, UErrorCode &status) const override
Get a UText for the text being analyzed.
icu::RuleBasedBreakIterator::getRules
virtual const UnicodeString & getRules(void) const
Returns the description used to create this iterator.
icu::RuleBasedBreakIterator::RuleBasedBreakIterator
RuleBasedBreakIterator(UDataMemory *image, UErrorCode &status)
This constructor uses the udata interface to create a BreakIterator whose internal tables live in a m...
icu::RuleBasedBreakIterator::next
virtual int32_t next(int32_t n) override
Advances the iterator either forward or backward the specified number of steps.
icu::RuleBasedBreakIterator::setText
virtual void setText(UText *text, UErrorCode &status) override
Reset the break iterator to operate over the text represented by the UText.
icu::RuleBasedBreakIterator::~RuleBasedBreakIterator
virtual ~RuleBasedBreakIterator()
Destructor.
icu::RuleBasedBreakIterator::RuleBasedBreakIterator
RuleBasedBreakIterator(const UnicodeString &rules, UParseError &parseError, UErrorCode &status)
Construct a RuleBasedBreakIterator from a set of rules supplied as a string.
icu::RuleBasedBreakIterator::getText
virtual CharacterIterator & getText(void) const override
icu::RuleBasedBreakIterator::hashCode
virtual int32_t hashCode(void) const
Compute a hash code for this BreakIterator.
icu::RuleBasedBreakIterator::next
virtual int32_t next(void) override
Advances the iterator to the next boundary position.
icu::RuleBasedBreakIterator::RuleBasedBreakIterator
RuleBasedBreakIterator(const uint8_t *compiledRules, uint32_t ruleLength, UErrorCode &status)
Construct a RuleBasedBreakIterator from a set of precompiled binary rules.
icu::RuleBasedBreakIterator::setText
virtual void setText(const UnicodeString &newText) override
Set the iterator to analyze a new piece of text.
icu::UCharCharacterIterator
A concrete subclass of CharacterIterator that iterates over the characters (code units or code points...
Definition: uchriter.h:38
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
parseerr.h
C API: Parse Error Information.
schriter.h
C++ API: String Character Iterator.
UCPTrie
Immutable Unicode code point trie structure.
Definition: ucptrie.h:59
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
UText
UText struct.
Definition: utext.h:1328
udata.h
C API: Data loading interface.
UDataMemory
struct UDataMemory UDataMemory
Forward declaration of the data memory type.
Definition: udata.h:161
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:435
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UTEXT_INITIALIZER
#define UTEXT_INITIALIZER
initializer to be used with local (stack) instances of a UText struct.
Definition: utext.h:1558
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300