/* ******************************************************************** * * Copyright (C) 1997-1999, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************** */ #ifndef CHARITER_H #define CHARITER_H #include "unicode/utypes.h" #include "unicode/unistr.h" class U_COMMON_API ForwardCharacterIterator { public: enum { DONE = 0xffff }; virtual ~ForwardCharacterIterator() {} virtual UBool operator==(const ForwardCharacterIterator& that) const = 0; inline UBool operator!=(const ForwardCharacterIterator& that) const; virtual int32_t hashCode(void) const = 0; virtual UClassID getDynamicClassID(void) const = 0; virtual UChar nextPostInc(void) = 0; virtual UChar32 next32PostInc(void) = 0; virtual UBool hasNext() = 0; protected: ForwardCharacterIterator() {} ForwardCharacterIterator(const ForwardCharacterIterator&) {} ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; } }; class U_COMMON_API CharacterIterator : public ForwardCharacterIterator { public: enum EOrigin { kStart, kCurrent, kEnd }; virtual CharacterIterator* clone(void) const = 0; virtual UChar first(void) = 0; virtual UChar firstPostInc(void); virtual UChar32 first32(void) = 0; virtual UChar32 first32PostInc(void); inline UTextOffset setToStart(); virtual UChar last(void) = 0; virtual UChar32 last32(void) = 0; inline UTextOffset setToEnd(); virtual UChar setIndex(UTextOffset position) = 0; virtual UChar32 setIndex32(UTextOffset position) = 0; virtual UChar current(void) const = 0; virtual UChar32 current32(void) const = 0; virtual UChar next(void) = 0; virtual UChar32 next32(void) = 0; virtual UChar previous(void) = 0; virtual UChar32 previous32(void) = 0; virtual UBool hasPrevious() = 0; inline UTextOffset startIndex(void) const; inline UTextOffset endIndex(void) const; inline UTextOffset getIndex(void) const; inline int32_t getLength() const; virtual UTextOffset move(int32_t delta, EOrigin origin) = 0; virtual UTextOffset move32(int32_t delta, EOrigin origin) = 0; virtual void getText(UnicodeString& result) = 0; protected: CharacterIterator() {} CharacterIterator(int32_t length); CharacterIterator(int32_t length, UTextOffset position); CharacterIterator(int32_t length, UTextOffset begin, UTextOffset end, UTextOffset position); CharacterIterator(const CharacterIterator &that); CharacterIterator &operator=(const CharacterIterator &that); int32_t textLength; // need this for correct getText() and hashCode() UTextOffset pos; UTextOffset begin; UTextOffset end; }; inline UBool ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const { return !operator==(that); } inline UTextOffset CharacterIterator::setToStart() { return move(0, kStart); } inline UTextOffset CharacterIterator::setToEnd() { return move(0, kEnd); } inline UTextOffset CharacterIterator::startIndex(void) const { return begin; } inline UTextOffset CharacterIterator::endIndex(void) const { return end; } inline UTextOffset CharacterIterator::getIndex(void) const { return pos; } inline int32_t CharacterIterator::getLength(void) const { return textLength; } #endif