00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef CHARITER_H
00011 #define CHARITER_H
00012
00013 #include "unicode/utypes.h"
00014 #include "unicode/unistr.h"
00015
00016 U_NAMESPACE_BEGIN
00084 class U_COMMON_API ForwardCharacterIterator {
00085 public:
00091 enum { DONE = 0xffff };
00092
00097 virtual ~ForwardCharacterIterator() {}
00098
00104 virtual UBool operator==(const ForwardCharacterIterator& that) const = 0;
00105
00112 inline UBool operator!=(const ForwardCharacterIterator& that) const;
00113
00118 virtual int32_t hashCode(void) const = 0;
00119
00126 virtual UClassID getDynamicClassID(void) const = 0;
00127
00135 virtual UChar nextPostInc(void) = 0;
00136
00144 virtual UChar32 next32PostInc(void) = 0;
00145
00153 virtual UBool hasNext() = 0;
00154
00155 protected:
00156 ForwardCharacterIterator() {}
00157 ForwardCharacterIterator(const ForwardCharacterIterator&) {}
00158 ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; }
00159 };
00160
00330 class U_COMMON_API CharacterIterator : public ForwardCharacterIterator {
00331 public:
00336 enum EOrigin { kStart, kCurrent, kEnd };
00337
00345 virtual CharacterIterator* clone(void) const = 0;
00346
00353 virtual UChar first(void) = 0;
00354
00362 virtual UChar firstPostInc(void);
00363
00372 virtual UChar32 first32(void) = 0;
00373
00381 virtual UChar32 first32PostInc(void);
00382
00390 inline UTextOffset setToStart();
00391
00398 virtual UChar last(void) = 0;
00399
00406 virtual UChar32 last32(void) = 0;
00407
00415 inline UTextOffset setToEnd();
00416
00423 virtual UChar setIndex(UTextOffset position) = 0;
00424
00434 virtual UChar32 setIndex32(UTextOffset position) = 0;
00435
00440 virtual UChar current(void) const = 0;
00441
00446 virtual UChar32 current32(void) const = 0;
00447
00454 virtual UChar next(void) = 0;
00455
00465 virtual UChar32 next32(void) = 0;
00466
00473 virtual UChar previous(void) = 0;
00474
00481 virtual UChar32 previous32(void) = 0;
00482
00490 virtual UBool hasPrevious() = 0;
00491
00500 inline UTextOffset startIndex(void) const;
00501
00508 inline UTextOffset endIndex(void) const;
00509
00516 inline UTextOffset getIndex(void) const;
00517
00523 inline int32_t getLength() const;
00524
00533 virtual UTextOffset move(int32_t delta, EOrigin origin) = 0;
00534
00543 virtual UTextOffset move32(int32_t delta, EOrigin origin) = 0;
00544
00551 virtual void getText(UnicodeString& result) = 0;
00552
00553 protected:
00554 CharacterIterator() {}
00555 CharacterIterator(int32_t length);
00556 CharacterIterator(int32_t length, UTextOffset position);
00557 CharacterIterator(int32_t length, UTextOffset textBegin, UTextOffset textEnd, UTextOffset position);
00558 CharacterIterator(const CharacterIterator &that);
00559
00560 CharacterIterator &operator=(const CharacterIterator &that);
00561
00562 int32_t textLength;
00563 UTextOffset pos;
00564 UTextOffset begin;
00565 UTextOffset end;
00566 };
00567
00568 inline UBool
00569 ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const {
00570 return !operator==(that);
00571 }
00572
00573 inline UTextOffset
00574 CharacterIterator::setToStart() {
00575 return move(0, kStart);
00576 }
00577
00578 inline UTextOffset
00579 CharacterIterator::setToEnd() {
00580 return move(0, kEnd);
00581 }
00582
00583 inline UTextOffset
00584 CharacterIterator::startIndex(void) const {
00585 return begin;
00586 }
00587
00588 inline UTextOffset
00589 CharacterIterator::endIndex(void) const {
00590 return end;
00591 }
00592
00593 inline UTextOffset
00594 CharacterIterator::getIndex(void) const {
00595 return pos;
00596 }
00597
00598 inline int32_t
00599 CharacterIterator::getLength(void) const {
00600 return textLength;
00601 }
00602
00603 U_NAMESPACE_END
00604 #endif