rbbi.h

Go to the documentation of this file.
00001 /*
00002 ***************************************************************************
00003 *   Copyright (C) 1999-2005 International Business Machines Corporation   *
00004 *   and others. All rights reserved.                                      *
00005 ***************************************************************************
00006 
00007 **********************************************************************
00008 *   Date        Name        Description
00009 *   10/22/99    alan        Creation.
00010 *   11/11/99    rgillam     Complete port from Java.
00011 **********************************************************************
00012 */
00013 
00014 #ifndef RBBI_H
00015 #define RBBI_H
00016 
00017 #include "unicode/utypes.h"
00018 
00024 #if !UCONFIG_NO_BREAK_ITERATION
00025 
00026 #include "unicode/brkiter.h"
00027 #include "unicode/udata.h"
00028 #include "unicode/parseerr.h"
00029 
00030 
00031 struct UTrie;
00032 
00033 U_NAMESPACE_BEGIN
00034 
00036 struct RBBIDataHeader;
00037 class  RuleBasedBreakIteratorTables;
00038 class  BreakIterator;
00039 class  RBBIDataWrapper;
00040 struct RBBIStateTable;
00041 
00042 
00043 
00059 class U_COMMON_API RuleBasedBreakIterator : public BreakIterator {
00060 
00061 protected:
00066     CharacterIterator*  fText;
00067 
00072     RBBIDataWrapper    *fData;
00073 
00077     int32_t             fLastRuleStatusIndex;
00078 
00085     UBool               fLastStatusIndexValid;
00086 
00094     uint32_t           fDictionaryCharCount;
00095 
00100     static UBool        fTrace;
00101 
00102 
00103 protected:
00104     //=======================================================================
00105     // constructors
00106     //=======================================================================
00107 
00118     RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
00119 
00121     friend class RBBIRuleBuilder;
00123     friend class BreakIterator;
00124 
00125 
00126 
00127 public:
00128 
00133     RuleBasedBreakIterator();
00134 
00141     RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
00142 
00151     RuleBasedBreakIterator( const UnicodeString    &rules,
00152                              UParseError           &parseError,
00153                              UErrorCode            &status);
00154 
00155 
00168     RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
00169 
00174     virtual ~RuleBasedBreakIterator();
00175 
00183     RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
00184 
00193     virtual UBool operator==(const BreakIterator& that) const;
00194 
00202     UBool operator!=(const BreakIterator& that) const;
00203 
00214     virtual BreakIterator* clone() const;
00215 
00221     virtual int32_t hashCode(void) const;
00222 
00228     virtual const UnicodeString& getRules(void) const;
00229 
00230     //=======================================================================
00231     // BreakIterator overrides
00232     //=======================================================================
00233 
00242     virtual const CharacterIterator& getText(void) const;
00243 
00244 
00259      virtual UText *getUText(UText *fillIn, UErrorCode &status) const;
00260 
00268     virtual void adoptText(CharacterIterator* newText);
00269 
00276     virtual void setText(const UnicodeString& newText);
00277 
00291     virtual void  setText(UText *text, UErrorCode &status);
00292 
00299     virtual int32_t first(void);
00300 
00307     virtual int32_t last(void);
00308 
00319     virtual int32_t next(int32_t n);
00320 
00326     virtual int32_t next(void);
00327 
00333     virtual int32_t previous(void);
00334 
00342     virtual int32_t following(int32_t offset);
00343 
00351     virtual int32_t preceding(int32_t offset);
00352 
00361     virtual UBool isBoundary(int32_t offset);
00362 
00368     virtual int32_t current(void) const;
00369 
00370 
00403     virtual int32_t getRuleStatus() const;
00404 
00428     virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);
00429 
00441     virtual UClassID getDynamicClassID(void) const;
00442 
00454     static UClassID U_EXPORT2 getStaticClassID(void);
00455 
00456     /*
00457      * Create a clone (copy) of this break iterator in memory provided
00458      *  by the caller.  The idea is to increase performance by avoiding
00459      *  a storage allocation.  Use of this functoin is NOT RECOMMENDED.
00460      *  Performance gains are minimal, and correct buffer management is
00461      *  tricky.  Use clone() instead.
00462      *
00463      * @param stackBuffer  The pointer to the memory into which the cloned object
00464      *                     should be placed.  If NULL,  allocate heap memory
00465      *                     for the cloned object.
00466      * @param BufferSize   The size of the buffer.  If zero, return the required
00467      *                     buffer size, but do not clone the object.  If the
00468      *                     size was too small (but not zero), allocate heap
00469      *                     storage for the cloned object.
00470      *
00471      * @param status       Error status.  U_SAFECLONE_ALLOCATED_WARNING will be
00472      *                     returned if the the provided buffer was too small, and
00473      *                     the clone was therefore put on the heap.
00474      *
00475      * @return  Pointer to the clone object.  This may differ from the stackBuffer
00476      *          address if the byte alignment of the stack buffer was not suitable
00477      *          or if the stackBuffer was too small to hold the clone.
00478      * @stable ICU 2.0
00479      */
00480     virtual BreakIterator *  createBufferClone(void *stackBuffer,
00481                                                int32_t &BufferSize,
00482                                                UErrorCode &status);
00483 
00484 
00502     virtual const uint8_t *getBinaryRules(uint32_t &length);
00503 
00504 
00505 protected:
00506     //=======================================================================
00507     // implementation
00508     //=======================================================================
00517     virtual int32_t handleNext(void);
00518 
00527     virtual int32_t handlePrevious(void);
00528 
00535     virtual void reset(void);
00536 
00545     virtual UBool isDictionaryChar(UChar32);
00546 
00552     void init();
00553 
00554 private:
00555 
00565     int32_t handlePrevious(const RBBIStateTable *statetable);
00566 
00576     int32_t handleNext(const RBBIStateTable *statetable);
00577 
00581     void makeRuleStatusValid();
00582 
00583 };
00584 
00585 //------------------------------------------------------------------------------
00586 //
00587 //   Inline Functions Definitions ...
00588 //
00589 //------------------------------------------------------------------------------
00590 
00591 inline UBool RuleBasedBreakIterator::operator!=(const BreakIterator& that) const {
00592     return !operator==(that);
00593 }
00594 
00595 U_NAMESPACE_END
00596 
00597 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
00598 
00599 #endif

Generated on Tue Sep 13 11:03:25 2005 for ICU 3.4 by  doxygen 1.4.4