ICU 72.1 72.1

rbbi.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ***************************************************************************
5 * Copyright (C) 1999-2016 International Business Machines Corporation *
6 * and others. All rights reserved. *
7 ***************************************************************************
8
9 **********************************************************************
10 * Date Name Description
11 * 10/22/99 alan Creation.
12 * 11/11/99 rgillam Complete port from Java.
13 **********************************************************************
14 */
15
16 #ifndef RBBI_H
17 #define RBBI_H
18
19 #include "unicode/utypes.h"
20
21 #if U_SHOW_CPLUSPLUS_API
22
28 #if !UCONFIG_NO_BREAK_ITERATION
29
30 #include "unicode/brkiter.h"
31 #include "unicode/udata.h"
32 #include "unicode/parseerr.h"
33 #include "unicode/schriter.h"
34
35 struct UCPTrie;
36
37 U_NAMESPACE_BEGIN
38
40 class LanguageBreakEngine;
41 struct RBBIDataHeader;
42 class RBBIDataWrapper;
43 class UnhandledEngine;
44 class UStack;
45
57 class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator {
58
59 private:
64 UText fText;
65
66 #ifndef U_HIDE_INTERNAL_API
67 public:
68 #endif /* U_HIDE_INTERNAL_API */
74 RBBIDataWrapper *fData;
75 private:
76
81 int32_t fPosition;
82
86 int32_t fRuleStatusIndex;
87
91 class BreakCache;
92 BreakCache *fBreakCache;
93
98 class DictionaryCache;
99 DictionaryCache *fDictionaryCache;
100
108 UStack *fLanguageBreakEngines;
109
117 UnhandledEngine *fUnhandledBreakEngine;
118
124 uint32_t fDictionaryCharCount;
125
131 CharacterIterator *fCharIter;
132
138 StringCharacterIterator fSCharIter;
139
143 UBool fDone;
144
148 int32_t *fLookAheadMatches;
149
153 UBool fIsPhraseBreaking;
154
155 //=======================================================================
156 // constructors
157 //=======================================================================
158
169 RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
170
184 RuleBasedBreakIterator(UDataMemory* image, UBool isPhraseBreaking, UErrorCode &status);
185
187 friend class RBBIRuleBuilder;
189 friend class BreakIterator;
190
191 public:
192
197 RuleBasedBreakIterator();
198
205 RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
206
215 RuleBasedBreakIterator( const UnicodeString &rules,
216 UParseError &parseError,
217 UErrorCode &status);
218
242 RuleBasedBreakIterator(const uint8_t *compiledRules,
243 uint32_t ruleLength,
244 UErrorCode &status);
245
258 RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
259
264 virtual ~RuleBasedBreakIterator();
265
273 RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
274
283 virtual bool operator==(const BreakIterator& that) const override;
284
292 inline bool operator!=(const BreakIterator& that) const;
293
304 virtual RuleBasedBreakIterator* clone() const override;
305
311 virtual int32_t hashCode(void) const;
312
318 virtual const UnicodeString& getRules(void) const;
319
320 //=======================================================================
321 // BreakIterator overrides
322 //=======================================================================
323
349 virtual CharacterIterator& getText(void) const override;
350
351
366 virtual UText *getUText(UText *fillIn, UErrorCode &status) const override;
367
375 virtual void adoptText(CharacterIterator* newText) override;
376
388 virtual void setText(const UnicodeString& newText) override;
389
403 virtual void setText(UText *text, UErrorCode &status) override;
404
410 virtual int32_t first(void) override;
411
417 virtual int32_t last(void) override;
418
429 virtual int32_t next(int32_t n) override;
430
436 virtual int32_t next(void) override;
437
443 virtual int32_t previous(void) override;
444
452 virtual int32_t following(int32_t offset) override;
453
461 virtual int32_t preceding(int32_t offset) override;
462
471 virtual UBool isBoundary(int32_t offset) override;
472
481 virtual int32_t current(void) const override;
482
483
515 virtual int32_t getRuleStatus() const override;
516
540 virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override;
541
553 virtual UClassID getDynamicClassID(void) const override;
554
566 static UClassID U_EXPORT2 getStaticClassID(void);
567
568 #ifndef U_FORCE_HIDE_DEPRECATED_API
595 virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer,
596 int32_t &BufferSize,
597 UErrorCode &status) override;
598 #endif // U_FORCE_HIDE_DEPRECATED_API
599
617 virtual const uint8_t *getBinaryRules(uint32_t &length);
618
644 virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status) override;
645
646
647 private:
648 //=======================================================================
649 // implementation
650 //=======================================================================
655 void init(UErrorCode &status);
656
666 int32_t handleSafePrevious(int32_t fromPosition);
667
680 int32_t handleNext();
681
682 /*
683 * Templatized version of handleNext() and handleSafePrevious().
684 *
685 * There will be exactly four instantiations, two each for 8 and 16 bit tables,
686 * two each for 8 and 16 bit trie.
687 * Having separate instantiations for the table types keeps conditional tests of
688 * the table type out of the inner loops, at the expense of replicated code.
689 *
690 * The template parameter for the Trie access function is a value, not a type.
691 * Doing it this way, the compiler will inline the Trie function in the
692 * expanded functions. (Both the 8 and 16 bit access functions have the same type
693 * signature)
694 */
695
696 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
697
698 template<typename RowType, PTrieFunc trieFunc>
699 int32_t handleSafePrevious(int32_t fromPosition);
700
701 template<typename RowType, PTrieFunc trieFunc>
702 int32_t handleNext();
703
704
711 const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c);
712
713 public:
714 #ifndef U_HIDE_INTERNAL_API
719 void dumpCache();
720
725 void dumpTables();
726 #endif /* U_HIDE_INTERNAL_API */
727 };
728
729 //------------------------------------------------------------------------------
730 //
731 // Inline Functions Definitions ...
732 //
733 //------------------------------------------------------------------------------
734
735 inline bool RuleBasedBreakIterator::operator!=(const BreakIterator& that) const {
736 return !operator==(that);
737 }
738
739 U_NAMESPACE_END
740
741 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
742
743 #endif /* U_SHOW_CPLUSPLUS_API */
744
745 #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!=
bool operator!=(const BreakIterator &rhs) const
Returns the complement of the result of operator==.
Definition: brkiter.h:135
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::RuleBasedBreakIterator
A subclass of BreakIterator whose behavior is specified using a list of rules.
Definition: rbbi.h:57
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::fData
RBBIDataWrapper * fData
The rule data for this BreakIterator instance.
Definition: rbbi.h:74
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::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::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::StringCharacterIterator
A concrete subclass of CharacterIterator that iterates over the characters (code units or code points...
Definition: schriter.h:48
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
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:461
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
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_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