00001 /* 00002 ******************************************************************** 00003 * 00004 * Copyright (C) 1997-1999, International Business Machines 00005 * Corporation and others. All Rights Reserved. 00006 * 00007 ******************************************************************** 00008 */ 00009 00010 #ifndef CHARITER_H 00011 #define CHARITER_H 00012 00013 #include "unicode/utypes.h" 00014 #include "unicode/unistr.h" 00015 00080 class U_COMMON_API ForwardCharacterIterator { 00081 public: 00085 enum { DONE = 0xffff }; 00086 00091 virtual ~ForwardCharacterIterator() {} 00092 00098 virtual UBool operator==(const ForwardCharacterIterator& that) const = 0; 00099 00106 inline UBool operator!=(const ForwardCharacterIterator& that) const; 00107 00112 virtual int32_t hashCode(void) const = 0; 00113 00120 virtual UClassID getDynamicClassID(void) const = 0; 00121 00129 virtual UChar nextPostInc(void) = 0; 00130 00138 virtual UChar32 next32PostInc(void) = 0; 00139 00146 virtual UBool hasNext() = 0; 00147 00148 protected: 00149 ForwardCharacterIterator() {} 00150 ForwardCharacterIterator(const ForwardCharacterIterator&) {} 00151 ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; } 00152 }; 00153 00304 class U_COMMON_API CharacterIterator : public ForwardCharacterIterator { 00305 public: 00309 enum EOrigin { kStart, kCurrent, kEnd }; 00310 00318 virtual CharacterIterator* clone(void) const = 0; 00319 00326 virtual UChar first(void) = 0; 00327 00335 virtual UChar firstPostInc(void); 00336 00345 virtual UChar32 first32(void) = 0; 00346 00354 virtual UChar32 first32PostInc(void); 00355 00363 inline UTextOffset setToStart(); 00364 00371 virtual UChar last(void) = 0; 00372 00379 virtual UChar32 last32(void) = 0; 00380 00388 inline UTextOffset setToEnd(); 00389 00396 virtual UChar setIndex(UTextOffset position) = 0; 00397 00407 virtual UChar32 setIndex32(UTextOffset position) = 0; 00408 00413 virtual UChar current(void) const = 0; 00414 00419 virtual UChar32 current32(void) const = 0; 00420 00427 virtual UChar next(void) = 0; 00428 00438 virtual UChar32 next32(void) = 0; 00439 00446 virtual UChar previous(void) = 0; 00447 00454 virtual UChar32 previous32(void) = 0; 00455 00462 virtual UBool hasPrevious() = 0; 00463 00472 inline UTextOffset startIndex(void) const; 00473 00480 inline UTextOffset endIndex(void) const; 00481 00488 inline UTextOffset getIndex(void) const; 00489 00494 inline int32_t getLength() const; 00495 00503 virtual UTextOffset move(int32_t delta, EOrigin origin) = 0; 00504 00512 virtual UTextOffset move32(int32_t delta, EOrigin origin) = 0; 00513 00520 virtual void getText(UnicodeString& result) = 0; 00521 00522 protected: 00523 CharacterIterator() {} 00524 CharacterIterator(int32_t length); 00525 CharacterIterator(int32_t length, UTextOffset position); 00526 CharacterIterator(int32_t length, UTextOffset begin, UTextOffset end, UTextOffset position); 00527 CharacterIterator(const CharacterIterator &that); 00528 00529 CharacterIterator &operator=(const CharacterIterator &that); 00530 00531 int32_t textLength; // need this for correct getText() and hashCode() 00532 UTextOffset pos; 00533 UTextOffset begin; 00534 UTextOffset end; 00535 }; 00536 00537 inline UBool 00538 ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const { 00539 return !operator==(that); 00540 } 00541 00542 inline UTextOffset 00543 CharacterIterator::setToStart() { 00544 return move(0, kStart); 00545 } 00546 00547 inline UTextOffset 00548 CharacterIterator::setToEnd() { 00549 return move(0, kEnd); 00550 } 00551 00552 inline UTextOffset 00553 CharacterIterator::startIndex(void) const { 00554 return begin; 00555 } 00556 00557 inline UTextOffset 00558 CharacterIterator::endIndex(void) const { 00559 return end; 00560 } 00561 00562 inline UTextOffset 00563 CharacterIterator::getIndex(void) const { 00564 return pos; 00565 } 00566 00567 inline int32_t 00568 CharacterIterator::getLength(void) const { 00569 return textLength; 00570 } 00571 00572 #endif