ICU4C 79
Loading...
Searching...
No Matches
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
46
47#ifndef U_HIDE_INTERNAL_API
61 public:
67
77 virtual bool isFor(UChar32 c, const char* locale) const = 0;
78
87 virtual bool handles(UChar32 c) const = 0;
88
102 virtual int32_t fillBreaks(UText* text, int32_t start, int32_t end,
104 UErrorCode& status) const = 0;
105};
106#endif /* U_HIDE_INTERNAL_API */
107
108
121
122private:
126 UText fText = UTEXT_INITIALIZER;
127
128#ifndef U_HIDE_INTERNAL_API
129public:
130#endif /* U_HIDE_INTERNAL_API */
136 RBBIDataWrapper *fData = nullptr;
137
138private:
143 UErrorCode fErrorCode = U_ZERO_ERROR;
144
149 int32_t fPosition = 0;
150
154 int32_t fRuleStatusIndex = 0;
155
159 class BreakCache;
160 BreakCache *fBreakCache = nullptr;
161
166 class DictionaryCache;
167 DictionaryCache *fDictionaryCache = nullptr;
168
175 UStack *fLanguageBreakEngines = nullptr;
176
183 UnhandledEngine *fUnhandledBreakEngine = nullptr;
184
189 uint32_t fDictionaryCharCount = 0;
190
196 CharacterIterator *fCharIter = &fSCharIter;
197
203 UCharCharacterIterator fSCharIter {u"", 0};
204
208 bool fDone = false;
209
213 int32_t *fLookAheadMatches = nullptr;
214
218 UBool fIsPhraseBreaking = false;
219
220 //=======================================================================
221 // constructors
222 //=======================================================================
223
234
248
249 friend class RBBIRuleBuilder;
250 friend class BreakIterator;
251
258
259public:
260
267
275
287
314
328
334
343
352 virtual bool operator==(const BreakIterator& that) const override;
353
361 inline bool operator!=(const BreakIterator& that) const {
362 return !operator==(that);
363 }
364
375 virtual RuleBasedBreakIterator* clone() const override;
376
382 virtual int32_t hashCode() const;
383
390
391 //=======================================================================
392 // BreakIterator overrides
393 //=======================================================================
394
420
436
445
458
472 virtual void setText(UText *text, UErrorCode &status) override;
473
480
487
499
506
513
521 virtual int32_t following(int32_t offset) override;
522
530 virtual int32_t preceding(int32_t offset) override;
531
540 virtual UBool isBoundary(int32_t offset) override;
541
551
583 virtual int32_t getRuleStatus() const override;
584
609
621 virtual UClassID getDynamicClassID() const override;
622
634 static UClassID U_EXPORT2 getStaticClassID();
635
636#ifndef U_FORCE_HIDE_DEPRECATED_API
665 UErrorCode &status) override;
666#endif // U_FORCE_HIDE_DEPRECATED_API
667
686
714
715
716private:
717 //=======================================================================
718 // implementation
719 //=======================================================================
720
721#ifndef U_HIDE_INTERNAL_API
722public:
723#endif /* U_HIDE_INTERNAL_API */
736
737private:
748 int32_t handleNext();
749
750 /*
751 * Templatized version of handleNext() and handleSafePrevious().
752 *
753 * There will be exactly four instantiations, two each for 8 and 16 bit tables,
754 * two each for 8 and 16 bit trie.
755 * Having separate instantiations for the table types keeps conditional tests of
756 * the table type out of the inner loops, at the expense of replicated code.
757 *
758 * The template parameter for the Trie access function is a value, not a type.
759 * Doing it this way, the compiler will inline the Trie function in the
760 * expanded functions. (Both the 8 and 16 bit access functions have the same type
761 * signature)
762 */
763
764 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
765
766 template<typename RowType, PTrieFunc trieFunc>
767 int32_t handleSafePrevious(int32_t fromPosition);
768
769 template<typename RowType, PTrieFunc trieFunc>
770 int32_t handleNext();
771
772
779 const LanguageBreakEngine* getLanguageBreakEngine(UChar32 c,
780 const char* locale) U_LIFETIME_BOUND;
781
782 public:
783#ifndef U_HIDE_INTERNAL_API
788 void dumpCache();
789
795#endif /* U_HIDE_INTERNAL_API */
796
797#ifndef U_HIDE_INTERNAL_API
809#endif /* U_HIDE_INTERNAL_API */
810
811};
812
813
815
816#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
817
818#endif /* U_SHOW_CPLUSPLUS_API */
819
820#endif
C++ API: Break Iterator.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:106
virtual U_COMMON_API bool operator==(const BreakIterator &) const =0
Return true if another object is semantically equal to this one.
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:363
The ExternalBreakEngine class define an abstract interface for the host environment to provide a low ...
Definition rbbi.h:60
virtual bool isFor(UChar32 c, const char *locale) const =0
virtual int32_t fillBreaks(UText *text, int32_t start, int32_t end, int32_t *foundBreaks, int32_t foundBreaksCapacity, UErrorCode &status) const =0
virtual bool handles(UChar32 c) const =0
virtual ~ExternalBreakEngine()
destructor
Definition rbbi.h:66
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A subclass of BreakIterator whose behavior is specified using a list of rules.
Definition rbbi.h:120
virtual const UnicodeString & getRules() const
Returns the description used to create this iterator.
virtual int32_t hashCode() const
Compute a hash code for this BreakIterator.
virtual bool operator==(const BreakIterator &that) const override
Equality operator.
virtual RuleBasedBreakIterator * clone() const override
Returns a newly-constructed RuleBasedBreakIterator with the same behavior, and iterating over the sam...
virtual RuleBasedBreakIterator * createBufferClone(void *stackBuffer, int32_t &BufferSize, UErrorCode &status) override
Deprecated functionality.
void dumpTables()
Debugging function only.
bool operator!=(const BreakIterator &that) const
Not-equal operator.
Definition rbbi.h:361
void dumpCache()
Debugging function only.
static void registerExternalBreakEngine(ExternalBreakEngine *toAdopt, UErrorCode &status)
Register a new external break engine.
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...
RuleBasedBreakIterator()
Default constructor.
int32_t handleSafePrevious(int32_t fromPosition)
Iterate backwards from an arbitrary position in the input text using the synthesized Safe Reverse rul...
RuleBasedBreakIterator & operator=(const RuleBasedBreakIterator &that)
Assignment operator.
RuleBasedBreakIterator(const RuleBasedBreakIterator &that)
Copy constructor.
RuleBasedBreakIterator(UDataMemory *image, UErrorCode &status)
This constructor uses the udata interface to create a BreakIterator whose internal tables live in a m...
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...
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 uchriter.h:38
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
C API: Parse Error Information.
C++ API: String Character Iterator.
Immutable Unicode code point trie structure.
Definition ucptrie.h:59
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
UText struct.
Definition utext.h:1342
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:449
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
#define UTEXT_INITIALIZER
initializer to be used with local (stack) instances of a UText struct.
Definition utext.h:1572
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
@ U_ZERO_ERROR
No error, no warning.
Definition utypes.h:544
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315