1999-12-28 23:39:02 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2001-03-21 20:44:20 +00:00
|
|
|
* Copyright (C) 1998-2001, International Business Machines
|
1999-12-28 23:39:02 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UCHRITER_H
|
|
|
|
#define UCHRITER_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/chariter.h"
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
1999-12-28 23:39:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A concrete subclass of CharacterIterator that iterates over the
|
2000-04-12 19:36:30 +00:00
|
|
|
* characters (code units or code points) in a UChar array.
|
|
|
|
* It's possible not only to create an
|
|
|
|
* iterator that iterates over an entire UChar array, but also to
|
|
|
|
* create one that iterates over only a subrange of a UChar array
|
|
|
|
* (iterators over different subranges of the same UChar array don't
|
|
|
|
* compare equal).
|
2000-04-20 23:02:20 +00:00
|
|
|
* @see CharacterIterator
|
|
|
|
* @see ForwardCharacterIterator
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
|
|
|
|
public:
|
|
|
|
/**
|
2000-09-27 23:39:36 +00:00
|
|
|
* Create an iterator over the UChar array referred to by "textPtr".
|
|
|
|
* The iteration range is 0 to <code>length-1</code>.
|
2000-04-12 19:36:30 +00:00
|
|
|
* text is only aliased, not adopted (the
|
|
|
|
* destructor will not delete it).
|
2000-03-22 18:31:40 +00:00
|
|
|
* @stable
|
|
|
|
*/
|
2000-09-27 23:39:36 +00:00
|
|
|
UCharCharacterIterator(const UChar* textPtr, int32_t length);
|
1999-12-28 23:39:02 +00:00
|
|
|
|
2000-04-12 19:36:30 +00:00
|
|
|
/**
|
2000-09-27 23:39:36 +00:00
|
|
|
* Create an iterator over the UChar array referred to by "textPtr".
|
|
|
|
* The iteration range is 0 to <code>length-1</code>.
|
2000-04-12 19:36:30 +00:00
|
|
|
* text is only aliased, not adopted (the
|
|
|
|
* destructor will not delete it).
|
|
|
|
* The starting
|
2000-09-27 23:39:36 +00:00
|
|
|
* position is specified by "position". If "position" is outside the valid
|
2000-04-12 19:36:30 +00:00
|
|
|
* iteration range, the behavior of this object is undefined.
|
|
|
|
* @stable
|
|
|
|
*/
|
2000-09-27 23:39:36 +00:00
|
|
|
UCharCharacterIterator(const UChar* textPtr, int32_t length,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t position);
|
2000-04-12 19:36:30 +00:00
|
|
|
|
|
|
|
/**
|
2000-09-27 23:39:36 +00:00
|
|
|
* Create an iterator over the UChar array referred to by "textPtr".
|
2000-04-12 19:36:30 +00:00
|
|
|
* The iteration range is 0 to <code>end-1</code>.
|
|
|
|
* text is only aliased, not adopted (the
|
|
|
|
* destructor will not delete it).
|
|
|
|
* The starting
|
2000-09-27 23:39:36 +00:00
|
|
|
* position is specified by "position". If begin and end do not
|
|
|
|
* form a valid iteration range or "position" is outside the valid
|
2000-04-12 19:36:30 +00:00
|
|
|
* iteration range, the behavior of this object is undefined.
|
|
|
|
* @stable
|
|
|
|
*/
|
2000-09-27 23:39:36 +00:00
|
|
|
UCharCharacterIterator(const UChar* textPtr, int32_t length,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t textBegin,
|
|
|
|
int32_t textEnd,
|
|
|
|
int32_t position);
|
2000-04-12 19:36:30 +00:00
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
/**
|
|
|
|
* Copy constructor. The new iterator iterates over the same range
|
|
|
|
* of the same string as "that", and its initial position is the
|
2000-03-22 18:31:40 +00:00
|
|
|
* same as "that"'s current position.
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
UCharCharacterIterator(const UCharCharacterIterator& that);
|
|
|
|
|
|
|
|
/**
|
2000-03-22 18:31:40 +00:00
|
|
|
* Destructor.
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
~UCharCharacterIterator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator. *this is altered to iterate over the sane
|
|
|
|
* range of the same string as "that", and refers to the same
|
2000-03-22 18:31:40 +00:00
|
|
|
* character within that string as "that" does.
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
UCharCharacterIterator&
|
|
|
|
operator=(const UCharCharacterIterator& that);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the iterators iterate over the same range of the
|
2000-03-22 18:31:40 +00:00
|
|
|
* same string and are pointing at the same character.
|
|
|
|
* @stable
|
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool operator==(const ForwardCharacterIterator& that) const;
|
1999-12-28 23:39:02 +00:00
|
|
|
|
|
|
|
/**
|
2000-03-22 18:31:40 +00:00
|
|
|
* Generates a hash code for this iterator.
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual int32_t hashCode(void) const;
|
|
|
|
|
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Returns a new UCharCharacterIterator referring to the same
|
1999-12-28 23:39:02 +00:00
|
|
|
* character in the same range of the same string as this one. The
|
2000-03-22 18:31:40 +00:00
|
|
|
* caller must delete the new iterator.
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual CharacterIterator* clone(void) const;
|
|
|
|
|
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Sets the iterator to refer to the first code unit in its
|
2000-04-20 23:02:20 +00:00
|
|
|
* iteration range, and returns that code unit.
|
|
|
|
* This can be used to begin an iteration with next().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UChar first(void);
|
|
|
|
|
2000-04-20 23:02:20 +00:00
|
|
|
/**
|
|
|
|
* Sets the iterator to refer to the first code unit in its
|
|
|
|
* iteration range, returns that code unit, and moves the position
|
|
|
|
* to the second code unit. This is an alternative to setToStart()
|
|
|
|
* for forward iteration with nextPostInc().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-20 23:02:20 +00:00
|
|
|
*/
|
|
|
|
virtual UChar firstPostInc(void);
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Sets the iterator to refer to the first code point in its
|
2000-04-20 23:02:20 +00:00
|
|
|
* iteration range, and returns that code unit,
|
|
|
|
* This can be used to begin an iteration with next32().
|
|
|
|
* Note that an iteration with next32PostInc(), beginning with,
|
|
|
|
* e.g., setToStart() or firstPostInc(), is more efficient.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 first32(void);
|
|
|
|
|
2000-04-20 23:02:20 +00:00
|
|
|
/**
|
|
|
|
* Sets the iterator to refer to the first code point in its
|
|
|
|
* iteration range, returns that code point, and moves the position
|
|
|
|
* to the second code point. This is an alternative to setToStart()
|
|
|
|
* for forward iteration with next32PostInc().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-20 23:02:20 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 first32PostInc(void);
|
2000-04-12 19:36:30 +00:00
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Sets the iterator to refer to the last code unit in its
|
|
|
|
* iteration range, and returns that code unit.
|
|
|
|
* This can be used to begin an iteration with previous().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UChar last(void);
|
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Sets the iterator to refer to the last code point in its
|
|
|
|
* iteration range, and returns that code unit.
|
|
|
|
* This can be used to begin an iteration with previous32().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 last32(void);
|
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Sets the iterator to refer to the "position"-th code unit
|
|
|
|
* in the text-storage object the iterator refers to, and
|
|
|
|
* returns that code unit.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
virtual UChar setIndex(int32_t position);
|
1999-12-28 23:39:02 +00:00
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Sets the iterator to refer to the beginning of the code point
|
|
|
|
* that contains the "position"-th code unit
|
|
|
|
* in the text-storage object the iterator refers to, and
|
|
|
|
* returns that code point.
|
|
|
|
* The current position is adjusted to the beginning of the code point
|
|
|
|
* (its first code unit).
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
virtual UChar32 setIndex32(int32_t position);
|
2000-04-12 19:36:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the code unit the iterator currently refers to.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UChar current(void) const;
|
|
|
|
|
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Returns the code point the iterator currently refers to.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 current32(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances to the next code unit in the iteration range (toward
|
2000-04-20 23:02:20 +00:00
|
|
|
* endIndex()), and returns that code unit. If there are no more
|
2000-04-12 19:36:30 +00:00
|
|
|
* code units to return, returns DONE.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UChar next(void);
|
|
|
|
|
2000-04-20 23:02:20 +00:00
|
|
|
/**
|
|
|
|
* Gets the current code unit for returning and advances to the next code unit
|
|
|
|
* in the iteration range
|
|
|
|
* (toward endIndex()). If there are
|
|
|
|
* no more code units to return, returns DONE.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-20 23:02:20 +00:00
|
|
|
*/
|
2000-04-12 19:36:30 +00:00
|
|
|
virtual UChar nextPostInc(void);
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Advances to the next code point in the iteration range (toward
|
2000-04-20 23:02:20 +00:00
|
|
|
* endIndex()), and returns that code point. If there are no more
|
2000-04-12 19:36:30 +00:00
|
|
|
* code points to return, returns DONE.
|
2000-04-20 23:02:20 +00:00
|
|
|
* Note that iteration with "pre-increment" semantics is less
|
|
|
|
* efficient than iteration with "post-increment" semantics
|
|
|
|
* that is provided by next32PostInc().
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 next32(void);
|
|
|
|
|
2000-04-20 23:02:20 +00:00
|
|
|
/**
|
|
|
|
* Gets the current code point for returning and advances to the next code point
|
|
|
|
* in the iteration range
|
|
|
|
* (toward endIndex()). If there are
|
|
|
|
* no more code points to return, returns DONE.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-20 23:02:20 +00:00
|
|
|
*/
|
2000-04-12 19:36:30 +00:00
|
|
|
virtual UChar32 next32PostInc(void);
|
|
|
|
|
2000-04-20 23:02:20 +00:00
|
|
|
/**
|
|
|
|
* Returns FALSE if there are no more code units or code points
|
|
|
|
* at or after the current position in the iteration range.
|
|
|
|
* This is used with nextPostInc() or next32PostInc() in forward
|
|
|
|
* iteration.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-20 23:02:20 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool hasNext();
|
2000-04-12 19:36:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances to the previous code unit in the iteration rance (toward
|
2000-04-20 23:02:20 +00:00
|
|
|
* startIndex()), and returns that code unit. If there are no more
|
2000-04-12 19:36:30 +00:00
|
|
|
* code units to return, returns DONE.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UChar previous(void);
|
|
|
|
|
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Advances to the previous code point in the iteration rance (toward
|
2000-04-20 23:02:20 +00:00
|
|
|
* startIndex()), and returns that code point. If there are no more
|
2000-04-12 19:36:30 +00:00
|
|
|
* code points to return, returns DONE.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-04-12 19:36:30 +00:00
|
|
|
*/
|
|
|
|
virtual UChar32 previous32(void);
|
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Returns FALSE if there are no more code units or code points
|
|
|
|
* before the current position in the iteration range.
|
|
|
|
* This is used with previous() or previous32() in backward
|
|
|
|
* iteration.
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool hasPrevious();
|
1999-12-28 23:39:02 +00:00
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Moves the current position relative to the start or end of the
|
|
|
|
* iteration range, or relative to the current position itself.
|
|
|
|
* The movement is expressed in numbers of code units forward
|
|
|
|
* or backward by specifying a positive or negative delta.
|
|
|
|
* @return the new position
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
virtual int32_t move(int32_t delta, EOrigin origin);
|
1999-12-28 23:39:02 +00:00
|
|
|
|
|
|
|
/**
|
2000-04-20 23:02:20 +00:00
|
|
|
* Moves the current position relative to the start or end of the
|
|
|
|
* iteration range, or relative to the current position itself.
|
|
|
|
* The movement is expressed in numbers of code points forward
|
|
|
|
* or backward by specifying a positive or negative delta.
|
|
|
|
* @return the new position
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-03-22 18:31:40 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
virtual int32_t move32(int32_t delta, EOrigin origin);
|
1999-12-28 23:39:02 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
/**
|
|
|
|
* Sets the iterator to iterate over a new range of text
|
2001-11-13 22:47:47 +00:00
|
|
|
* @stable
|
2000-01-08 02:05:05 +00:00
|
|
|
*/
|
2000-04-12 19:36:30 +00:00
|
|
|
void setText(const UChar* newText, int32_t newTextLength);
|
2000-01-08 02:05:05 +00:00
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
/**
|
2000-04-12 19:36:30 +00:00
|
|
|
* Copies the UChar array under iteration into the UnicodeString
|
1999-12-28 23:39:02 +00:00
|
|
|
* referred to by "result". Even if this iterator iterates across
|
2000-04-20 23:02:20 +00:00
|
|
|
* only a part of this string, the whole string is copied.
|
|
|
|
* @param result Receives a copy of the text under iteration.
|
2000-03-22 18:31:40 +00:00
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual void getText(UnicodeString& result);
|
|
|
|
|
|
|
|
/**
|
2000-03-22 18:31:40 +00:00
|
|
|
* Return a class ID for this object (not really public)
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
virtual UClassID getDynamicClassID(void) const
|
|
|
|
{ return getStaticClassID(); }
|
|
|
|
|
|
|
|
/**
|
2000-03-22 18:31:40 +00:00
|
|
|
* Return a class ID for this class (not really public)
|
|
|
|
* @stable
|
|
|
|
*/
|
1999-12-28 23:39:02 +00:00
|
|
|
static UClassID getStaticClassID(void)
|
|
|
|
{ return (UClassID)(&fgClassID); }
|
|
|
|
|
2000-04-12 19:36:30 +00:00
|
|
|
protected:
|
1999-12-28 23:39:02 +00:00
|
|
|
UCharCharacterIterator();
|
|
|
|
|
|
|
|
const UChar* text;
|
|
|
|
|
2001-08-29 18:14:28 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
1999-12-28 23:39:02 +00:00
|
|
|
};
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
1999-12-28 23:39:02 +00:00
|
|
|
#endif
|