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