ICU 69.1 69.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
35struct UCPTrie;
36
37U_NAMESPACE_BEGIN
38
40class LanguageBreakEngine;
41struct RBBIDataHeader;
42class RBBIDataWrapper;
43class UnhandledEngine;
44class UStack;
45
58
59private:
64 UText fText;
65
66#ifndef U_HIDE_INTERNAL_API
67public:
68#endif /* U_HIDE_INTERNAL_API */
74 RBBIDataWrapper *fData;
75private:
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
150 //=======================================================================
151 // constructors
152 //=======================================================================
153
164 RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
165
167 friend class RBBIRuleBuilder;
169 friend class BreakIterator;
170
171public:
172
178
186
196 UParseError &parseError,
197 UErrorCode &status);
198
222 RuleBasedBreakIterator(const uint8_t *compiledRules,
223 uint32_t ruleLength,
224 UErrorCode &status);
225
239
245
254
263 virtual UBool operator==(const BreakIterator& that) const;
264
272 inline UBool operator!=(const BreakIterator& that) const;
273
285
291 virtual int32_t hashCode(void) const;
292
298 virtual const UnicodeString& getRules(void) const;
299
300 //=======================================================================
301 // BreakIterator overrides
302 //=======================================================================
303
329 virtual CharacterIterator& getText(void) const;
330
331
346 virtual UText *getUText(UText *fillIn, UErrorCode &status) const;
347
355 virtual void adoptText(CharacterIterator* newText);
356
368 virtual void setText(const UnicodeString& newText);
369
383 virtual void setText(UText *text, UErrorCode &status);
384
390 virtual int32_t first(void);
391
397 virtual int32_t last(void);
398
409 virtual int32_t next(int32_t n);
410
416 virtual int32_t next(void);
417
423 virtual int32_t previous(void);
424
432 virtual int32_t following(int32_t offset);
433
441 virtual int32_t preceding(int32_t offset);
442
451 virtual UBool isBoundary(int32_t offset);
452
461 virtual int32_t current(void) const;
462
463
495 virtual int32_t getRuleStatus() const;
496
520 virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);
521
533 virtual UClassID getDynamicClassID(void) const;
534
546 static UClassID U_EXPORT2 getStaticClassID(void);
547
548#ifndef U_FORCE_HIDE_DEPRECATED_API
575 virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer,
576 int32_t &BufferSize,
577 UErrorCode &status);
578#endif // U_FORCE_HIDE_DEPRECATED_API
579
597 virtual const uint8_t *getBinaryRules(uint32_t &length);
598
625
626
627private:
628 //=======================================================================
629 // implementation
630 //=======================================================================
636 void reset(void);
637
642 void init(UErrorCode &status);
643
653 int32_t handleSafePrevious(int32_t fromPosition);
654
667 int32_t handleNext();
668
669 /*
670 * Templatized version of handleNext() and handleSafePrevious().
671 *
672 * There will be exactly four instantiations, two each for 8 and 16 bit tables,
673 * two each for 8 and 16 bit trie.
674 * Having separate instantiations for the table types keeps conditional tests of
675 * the table type out of the inner loops, at the expense of replicated code.
676 *
677 * The template parameter for the Trie access function is a value, not a type.
678 * Doing it this way, the compiler will inline the Trie function in the
679 * expanded functions. (Both the 8 and 16 bit access functions have the same type
680 * signature)
681 */
682
683 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
684
685 template<typename RowType, PTrieFunc trieFunc>
686 int32_t handleSafePrevious(int32_t fromPosition);
687
688 template<typename RowType, PTrieFunc trieFunc>
689 int32_t handleNext();
690
691
698 const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c);
699
700 public:
701#ifndef U_HIDE_INTERNAL_API
706 void dumpCache();
707
713#endif /* U_HIDE_INTERNAL_API */
714};
715
716//------------------------------------------------------------------------------
717//
718// Inline Functions Definitions ...
719//
720//------------------------------------------------------------------------------
721
722inline UBool RuleBasedBreakIterator::operator!=(const BreakIterator& that) const {
723 return !operator==(that);
724}
725
726U_NAMESPACE_END
727
728#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
729
730#endif /* U_SHOW_CPLUSPLUS_API */
731
732#endif
C++ API: Break Iterator.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:106
UBool operator!=(const BreakIterator &rhs) const
Returns the complement of the result of operator==.
Definition brkiter.h:135
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:361
A subclass of BreakIterator whose behavior is specified using a list of rules.
Definition rbbi.h:57
virtual RuleBasedBreakIterator & refreshInputText(UText *input, UErrorCode &status)
Set the subject text string upon which the break iterator is operating without changing any other asp...
virtual void setText(UText *text, UErrorCode &status)
Reset the break iterator to operate over the text represented by the UText.
RBBIDataWrapper * fData
The rule data for this BreakIterator instance.
Definition rbbi.h:74
virtual CharacterIterator & getText(void) const
virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status)
Get the status (tag) values from the break rule(s) that determined the boundary at the current iterat...
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual UText * getUText(UText *fillIn, UErrorCode &status) const
Get a UText for the text being analyzed.
void dumpTables()
Debugging function only.
virtual int32_t previous(void)
Moves the iterator backwards, to the last boundary preceding this one.
virtual int32_t current(void) const
Returns the current iteration position.
virtual int32_t next(void)
Advances the iterator to the next boundary position.
void dumpCache()
Debugging function only.
virtual int32_t getRuleStatus() const
Return the status tag from the break rule that determined the boundary at the current iteration posit...
RuleBasedBreakIterator()
Default constructor.
virtual void setText(const UnicodeString &newText)
Set the iterator to analyze a new piece of text.
virtual UBool operator==(const BreakIterator &that) const
Equality operator.
RuleBasedBreakIterator & operator=(const RuleBasedBreakIterator &that)
Assignment operator.
static UClassID getStaticClassID(void)
Returns the class ID for this class.
virtual UBool isBoundary(int32_t offset)
Returns true if the specified position is a boundary position.
virtual int32_t preceding(int32_t offset)
Sets the iterator to refer to the last boundary position before the specified position.
RuleBasedBreakIterator(const RuleBasedBreakIterator &that)
Copy constructor.
virtual RuleBasedBreakIterator * clone() const
Returns a newly-constructed RuleBasedBreakIterator with the same behavior, and iterating over the sam...
virtual int32_t next(int32_t n)
Advances the iterator either forward or backward the specified number of steps.
RuleBasedBreakIterator(UDataMemory *image, UErrorCode &status)
This constructor uses the udata interface to create a BreakIterator whose internal tables live in a m...
virtual int32_t following(int32_t offset)
Sets the iterator to refer to the first boundary position following the specified position.
virtual int32_t first(void)
Sets the current iteration position to the beginning of the text, position zero.
virtual const UnicodeString & getRules(void) const
Returns the description used to create this iterator.
virtual int32_t last(void)
Sets the current iteration position to the end of the text.
virtual RuleBasedBreakIterator * createBufferClone(void *stackBuffer, int32_t &BufferSize, UErrorCode &status)
Deprecated functionality.
virtual ~RuleBasedBreakIterator()
Destructor.
RuleBasedBreakIterator(const UnicodeString &rules, UParseError &parseError, UErrorCode &status)
Construct a RuleBasedBreakIterator from a set of rules supplied as a string.
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...
virtual void adoptText(CharacterIterator *newText)
Set the iterator to analyze a new piece of text.
virtual int32_t hashCode(void) const
Compute a hash code for this BreakIterator.
RuleBasedBreakIterator(const uint8_t *compiledRules, uint32_t ruleLength, UErrorCode &status)
Construct a RuleBasedBreakIterator from a set of precompiled binary rules.
A concrete subclass of CharacterIterator that iterates over the characters (code units or code points...
Definition schriter.h:48
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C API: Parse Error Information.
C++ API: String Character Iterator.
Immutable Unicode code point trie structure.
Definition ucptrie.h:60
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
UText struct.
Definition utext.h:1328
C API: Data loading interface.
struct UDataMemory UDataMemory
Forward declaration of the data memory type.
Definition udata.h:161
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:467
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:300