00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef RBBI_H
00017 #define RBBI_H
00018
00019 #include "unicode/utypes.h"
00020
00021 #if U_SHOW_CPLUSPLUS_API
00022
00028 #if !UCONFIG_NO_BREAK_ITERATION
00029
00030 #include "unicode/brkiter.h"
00031 #include "unicode/udata.h"
00032 #include "unicode/parseerr.h"
00033 #include "unicode/schriter.h"
00034
00035 struct UCPTrie;
00036
00037 U_NAMESPACE_BEGIN
00038
00040 class LanguageBreakEngine;
00041 struct RBBIDataHeader;
00042 class RBBIDataWrapper;
00043 class UnhandledEngine;
00044 class UStack;
00045
00057 class U_COMMON_API RuleBasedBreakIterator : public BreakIterator {
00058
00059 private:
00064 UText fText = UTEXT_INITIALIZER;
00065
00066 #ifndef U_HIDE_INTERNAL_API
00067 public:
00068 #endif
00069
00074 RBBIDataWrapper *fData = nullptr;
00075
00076 private:
00081 UErrorCode fErrorCode = U_ZERO_ERROR;
00082
00087 int32_t fPosition = 0;
00088
00092 int32_t fRuleStatusIndex = 0;
00093
00097 class BreakCache;
00098 BreakCache *fBreakCache = nullptr;
00099
00104 class DictionaryCache;
00105 DictionaryCache *fDictionaryCache = nullptr;
00106
00114 UStack *fLanguageBreakEngines = nullptr;
00115
00123 UnhandledEngine *fUnhandledBreakEngine = nullptr;
00124
00130 uint32_t fDictionaryCharCount = 0;
00131
00137 CharacterIterator *fCharIter = &fSCharIter;
00138
00144 UCharCharacterIterator fSCharIter {u"", 0};
00145
00149 bool fDone = false;
00150
00154 int32_t *fLookAheadMatches = nullptr;
00155
00159 UBool fIsPhraseBreaking = false;
00160
00161
00162
00163
00164
00175 RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
00176
00190 RuleBasedBreakIterator(UDataMemory* image, UBool isPhraseBreaking, UErrorCode &status);
00191
00193 friend class RBBIRuleBuilder;
00195 friend class BreakIterator;
00196
00203 RuleBasedBreakIterator(UErrorCode *status);
00204
00205 public:
00206
00212 RuleBasedBreakIterator();
00213
00220 RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
00221
00230 RuleBasedBreakIterator( const UnicodeString &rules,
00231 UParseError &parseError,
00232 UErrorCode &status);
00233
00257 RuleBasedBreakIterator(const uint8_t *compiledRules,
00258 uint32_t ruleLength,
00259 UErrorCode &status);
00260
00273 RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
00274
00279 virtual ~RuleBasedBreakIterator();
00280
00288 RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
00289
00298 virtual bool operator==(const BreakIterator& that) const override;
00299
00307 inline bool operator!=(const BreakIterator& that) const {
00308 return !operator==(that);
00309 }
00310
00321 virtual RuleBasedBreakIterator* clone() const override;
00322
00328 virtual int32_t hashCode(void) const;
00329
00335 virtual const UnicodeString& getRules(void) const;
00336
00337
00338
00339
00340
00365 virtual CharacterIterator& getText(void) const override;
00366
00367
00382 virtual UText *getUText(UText *fillIn, UErrorCode &status) const override;
00383
00391 virtual void adoptText(CharacterIterator* newText) override;
00392
00404 virtual void setText(const UnicodeString& newText) override;
00405
00419 virtual void setText(UText *text, UErrorCode &status) override;
00420
00426 virtual int32_t first(void) override;
00427
00433 virtual int32_t last(void) override;
00434
00445 virtual int32_t next(int32_t n) override;
00446
00452 virtual int32_t next(void) override;
00453
00459 virtual int32_t previous(void) override;
00460
00468 virtual int32_t following(int32_t offset) override;
00469
00477 virtual int32_t preceding(int32_t offset) override;
00478
00487 virtual UBool isBoundary(int32_t offset) override;
00488
00497 virtual int32_t current(void) const override;
00498
00499
00531 virtual int32_t getRuleStatus() const override;
00532
00556 virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override;
00557
00569 virtual UClassID getDynamicClassID(void) const override;
00570
00582 static UClassID U_EXPORT2 getStaticClassID(void);
00583
00584 #ifndef U_FORCE_HIDE_DEPRECATED_API
00585
00611 virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer,
00612 int32_t &BufferSize,
00613 UErrorCode &status) override;
00614 #endif // U_FORCE_HIDE_DEPRECATED_API
00615
00633 virtual const uint8_t *getBinaryRules(uint32_t &length);
00634
00660 virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status) override;
00661
00662
00663 private:
00664
00665
00666
00676 int32_t handleSafePrevious(int32_t fromPosition);
00677
00690 int32_t handleNext();
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
00707
00708 template<typename RowType, PTrieFunc trieFunc>
00709 int32_t handleSafePrevious(int32_t fromPosition);
00710
00711 template<typename RowType, PTrieFunc trieFunc>
00712 int32_t handleNext();
00713
00714
00721 const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c);
00722
00723 public:
00724 #ifndef U_HIDE_INTERNAL_API
00725
00729 void dumpCache();
00730
00735 void dumpTables();
00736 #endif
00737 };
00738
00739 U_NAMESPACE_END
00740
00741 #endif
00742
00743 #endif
00744
00745 #endif