sl@0: /*
sl@0: **********************************************************************
sl@0: * Copyright (C) 1998-2005, International Business Machines
sl@0: * Corporation and others. All Rights Reserved.
sl@0: **********************************************************************
sl@0: */
sl@0:
sl@0: #ifndef UCHRITER_H
sl@0: #define UCHRITER_H
sl@0:
sl@0: #include "unicode/utypes.h"
sl@0: #include "unicode/chariter.h"
sl@0:
sl@0: /**
sl@0: * \file
sl@0: * \brief C++ API: UChar Character Iterator
sl@0: */
sl@0:
sl@0: U_NAMESPACE_BEGIN
sl@0:
sl@0: /**
sl@0: * A concrete subclass of CharacterIterator that iterates over the
sl@0: * characters (code units or code points) in a UChar array.
sl@0: * It's possible not only to create an
sl@0: * iterator that iterates over an entire UChar array, but also to
sl@0: * create one that iterates over only a subrange of a UChar array
sl@0: * (iterators over different subranges of the same UChar array don't
sl@0: * compare equal).
sl@0: * @see CharacterIterator
sl@0: * @see ForwardCharacterIterator
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
sl@0: public:
sl@0: /**
sl@0: * Create an iterator over the UChar array referred to by "textPtr".
sl@0: * The iteration range is 0 to length-1
.
sl@0: * text is only aliased, not adopted (the
sl@0: * destructor will not delete it).
sl@0: * @param textPtr The UChar array to be iterated over
sl@0: * @param length The length of the UChar array
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator(const UChar* textPtr, int32_t length);
sl@0:
sl@0: /**
sl@0: * Create an iterator over the UChar array referred to by "textPtr".
sl@0: * The iteration range is 0 to length-1
.
sl@0: * text is only aliased, not adopted (the
sl@0: * destructor will not delete it).
sl@0: * The starting
sl@0: * position is specified by "position". If "position" is outside the valid
sl@0: * iteration range, the behavior of this object is undefined.
sl@0: * @param textPtr The UChar array to be iteratd over
sl@0: * @param length The length of the UChar array
sl@0: * @param position The starting position of the iteration
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator(const UChar* textPtr, int32_t length,
sl@0: int32_t position);
sl@0:
sl@0: /**
sl@0: * Create an iterator over the UChar array referred to by "textPtr".
sl@0: * The iteration range is 0 to end-1
.
sl@0: * text is only aliased, not adopted (the
sl@0: * destructor will not delete it).
sl@0: * The starting
sl@0: * position is specified by "position". If begin and end do not
sl@0: * form a valid iteration range or "position" is outside the valid
sl@0: * iteration range, the behavior of this object is undefined.
sl@0: * @param textPtr The UChar array to be iterated over
sl@0: * @param length The length of the UChar array
sl@0: * @param textBegin The begin position of the iteration range
sl@0: * @param textEnd The end position of the iteration range
sl@0: * @param position The starting position of the iteration
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator(const UChar* textPtr, int32_t length,
sl@0: int32_t textBegin,
sl@0: int32_t textEnd,
sl@0: int32_t position);
sl@0:
sl@0: /**
sl@0: * Copy constructor. The new iterator iterates over the same range
sl@0: * of the same string as "that", and its initial position is the
sl@0: * same as "that"'s current position.
sl@0: * @param that The UCharCharacterIterator to be copied
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator(const UCharCharacterIterator& that);
sl@0:
sl@0: /**
sl@0: * Destructor.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual ~UCharCharacterIterator();
sl@0:
sl@0: /**
sl@0: * Assignment operator. *this is altered to iterate over the sane
sl@0: * range of the same string as "that", and refers to the same
sl@0: * character within that string as "that" does.
sl@0: * @param that The object to be copied
sl@0: * @return the newly created object
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator&
sl@0: operator=(const UCharCharacterIterator& that);
sl@0:
sl@0: /**
sl@0: * Returns true if the iterators iterate over the same range of the
sl@0: * same string and are pointing at the same character.
sl@0: * @param that The ForwardCharacterIterator used to be compared for equality
sl@0: * @return true if the iterators iterate over the same range of the
sl@0: * same string and are pointing at the same character.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UBool operator==(const ForwardCharacterIterator& that) const;
sl@0:
sl@0: /**
sl@0: * Generates a hash code for this iterator.
sl@0: * @return the hash code.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual int32_t hashCode(void) const;
sl@0:
sl@0: /**
sl@0: * Returns a new UCharCharacterIterator referring to the same
sl@0: * character in the same range of the same string as this one. The
sl@0: * caller must delete the new iterator.
sl@0: * @return the CharacterIterator newly created
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual CharacterIterator* clone(void) const;
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the first code unit in its
sl@0: * iteration range, and returns that code unit.
sl@0: * This can be used to begin an iteration with next().
sl@0: * @return the first code unit in its iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar first(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the first code unit in its
sl@0: * iteration range, returns that code unit, and moves the position
sl@0: * to the second code unit. This is an alternative to setToStart()
sl@0: * for forward iteration with nextPostInc().
sl@0: * @return the first code unit in its iteration range
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar firstPostInc(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the first code point in its
sl@0: * iteration range, and returns that code unit,
sl@0: * This can be used to begin an iteration with next32().
sl@0: * Note that an iteration with next32PostInc(), beginning with,
sl@0: * e.g., setToStart() or firstPostInc(), is more efficient.
sl@0: * @return the first code point in its iteration range
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 first32(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the first code point in its
sl@0: * iteration range, returns that code point, and moves the position
sl@0: * to the second code point. This is an alternative to setToStart()
sl@0: * for forward iteration with next32PostInc().
sl@0: * @return the first code point in its iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 first32PostInc(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the last code unit in its
sl@0: * iteration range, and returns that code unit.
sl@0: * This can be used to begin an iteration with previous().
sl@0: * @return the last code unit in its iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar last(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the last code point in its
sl@0: * iteration range, and returns that code unit.
sl@0: * This can be used to begin an iteration with previous32().
sl@0: * @return the last code point in its iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 last32(void);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the "position"-th code unit
sl@0: * in the text-storage object the iterator refers to, and
sl@0: * returns that code unit.
sl@0: * @param position the position within the text-storage object
sl@0: * @return the code unit
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar setIndex(int32_t position);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to refer to the beginning of the code point
sl@0: * that contains the "position"-th code unit
sl@0: * in the text-storage object the iterator refers to, and
sl@0: * returns that code point.
sl@0: * The current position is adjusted to the beginning of the code point
sl@0: * (its first code unit).
sl@0: * @param position the position within the text-storage object
sl@0: * @return the code unit
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 setIndex32(int32_t position);
sl@0:
sl@0: /**
sl@0: * Returns the code unit the iterator currently refers to.
sl@0: * @return the code unit the iterator currently refers to.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar current(void) const;
sl@0:
sl@0: /**
sl@0: * Returns the code point the iterator currently refers to.
sl@0: * @return the code point the iterator currently refers to.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 current32(void) const;
sl@0:
sl@0: /**
sl@0: * Advances to the next code unit in the iteration range (toward
sl@0: * endIndex()), and returns that code unit. If there are no more
sl@0: * code units to return, returns DONE.
sl@0: * @return the next code unit in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar next(void);
sl@0:
sl@0: /**
sl@0: * Gets the current code unit for returning and advances to the next code unit
sl@0: * in the iteration range
sl@0: * (toward endIndex()). If there are
sl@0: * no more code units to return, returns DONE.
sl@0: * @return the current code unit.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar nextPostInc(void);
sl@0:
sl@0: /**
sl@0: * Advances to the next code point in the iteration range (toward
sl@0: * endIndex()), and returns that code point. If there are no more
sl@0: * code points to return, returns DONE.
sl@0: * Note that iteration with "pre-increment" semantics is less
sl@0: * efficient than iteration with "post-increment" semantics
sl@0: * that is provided by next32PostInc().
sl@0: * @return the next code point in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 next32(void);
sl@0:
sl@0: /**
sl@0: * Gets the current code point for returning and advances to the next code point
sl@0: * in the iteration range
sl@0: * (toward endIndex()). If there are
sl@0: * no more code points to return, returns DONE.
sl@0: * @return the current point.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 next32PostInc(void);
sl@0:
sl@0: /**
sl@0: * Returns FALSE if there are no more code units or code points
sl@0: * at or after the current position in the iteration range.
sl@0: * This is used with nextPostInc() or next32PostInc() in forward
sl@0: * iteration.
sl@0: * @return FALSE if there are no more code units or code points
sl@0: * at or after the current position in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UBool hasNext();
sl@0:
sl@0: /**
sl@0: * Advances to the previous code unit in the iteration range (toward
sl@0: * startIndex()), and returns that code unit. If there are no more
sl@0: * code units to return, returns DONE.
sl@0: * @return the previous code unit in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar previous(void);
sl@0:
sl@0: /**
sl@0: * Advances to the previous code point in the iteration range (toward
sl@0: * startIndex()), and returns that code point. If there are no more
sl@0: * code points to return, returns DONE.
sl@0: * @return the previous code point in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UChar32 previous32(void);
sl@0:
sl@0: /**
sl@0: * Returns FALSE if there are no more code units or code points
sl@0: * before the current position in the iteration range.
sl@0: * This is used with previous() or previous32() in backward
sl@0: * iteration.
sl@0: * @return FALSE if there are no more code units or code points
sl@0: * before the current position in the iteration range.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UBool hasPrevious();
sl@0:
sl@0: /**
sl@0: * Moves the current position relative to the start or end of the
sl@0: * iteration range, or relative to the current position itself.
sl@0: * The movement is expressed in numbers of code units forward
sl@0: * or backward by specifying a positive or negative delta.
sl@0: * @param delta the position relative to origin. A positive delta means forward;
sl@0: * a negative delta means backward.
sl@0: * @param origin Origin enumeration {kStart, kCurrent, kEnd}
sl@0: * @return the new position
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual int32_t move(int32_t delta, EOrigin origin);
sl@0:
sl@0: /**
sl@0: * Moves the current position relative to the start or end of the
sl@0: * iteration range, or relative to the current position itself.
sl@0: * The movement is expressed in numbers of code points forward
sl@0: * or backward by specifying a positive or negative delta.
sl@0: * @param delta the position relative to origin. A positive delta means forward;
sl@0: * a negative delta means backward.
sl@0: * @param origin Origin enumeration {kStart, kCurrent, kEnd}
sl@0: * @return the new position
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual int32_t move32(int32_t delta, EOrigin origin);
sl@0:
sl@0: /**
sl@0: * Sets the iterator to iterate over a new range of text
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: void setText(const UChar* newText, int32_t newTextLength);
sl@0:
sl@0: /**
sl@0: * Copies the UChar array under iteration into the UnicodeString
sl@0: * referred to by "result". Even if this iterator iterates across
sl@0: * only a part of this string, the whole string is copied.
sl@0: * @param result Receives a copy of the text under iteration.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual void getText(UnicodeString& result);
sl@0:
sl@0: /**
sl@0: * Return a class ID for this class (not really public)
sl@0: * @return a class ID for this class
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: static UClassID U_EXPORT2 getStaticClassID(void);
sl@0:
sl@0: /**
sl@0: * Return a class ID for this object (not really public)
sl@0: * @return a class ID for this object.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual UClassID getDynamicClassID(void) const;
sl@0:
sl@0: protected:
sl@0: /**
sl@0: * Protected constructor
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UCharCharacterIterator();
sl@0: /**
sl@0: * Protected member text
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: const UChar* text;
sl@0:
sl@0: };
sl@0:
sl@0: U_NAMESPACE_END
sl@0: #endif