michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2005, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File schriter.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 05/05/99 stephen Cleaned up. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef SCHRITER_H michael@0: #define SCHRITER_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/chariter.h" michael@0: #include "unicode/uchriter.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: String Character Iterator michael@0: */ michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: /** michael@0: * A concrete subclass of CharacterIterator that iterates over the michael@0: * characters (code units or code points) in a UnicodeString. michael@0: * It's possible not only to create an michael@0: * iterator that iterates over an entire UnicodeString, but also to michael@0: * create one that iterates over only a subrange of a UnicodeString michael@0: * (iterators over different subranges of the same UnicodeString don't michael@0: * compare equal). michael@0: * @see CharacterIterator michael@0: * @see ForwardCharacterIterator michael@0: * @stable ICU 2.0 michael@0: */ michael@0: class U_COMMON_API StringCharacterIterator : public UCharCharacterIterator { michael@0: public: michael@0: /** michael@0: * Create an iterator over the UnicodeString referred to by "textStr". michael@0: * The UnicodeString object is copied. michael@0: * The iteration range is the whole string, and the starting position is 0. michael@0: * @param textStr The unicode string used to create an iterator michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator(const UnicodeString& textStr); michael@0: michael@0: /** michael@0: * Create an iterator over the UnicodeString referred to by "textStr". michael@0: * The iteration range is the whole string, and the starting michael@0: * position is specified by "textPos". If "textPos" is outside the valid michael@0: * iteration range, the behavior of this object is undefined. michael@0: * @param textStr The unicode string used to create an iterator michael@0: * @param textPos The starting position of the iteration michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator(const UnicodeString& textStr, michael@0: int32_t textPos); michael@0: michael@0: /** michael@0: * Create an iterator over the UnicodeString referred to by "textStr". michael@0: * The UnicodeString object is copied. michael@0: * The iteration range begins with the code unit specified by michael@0: * "textBegin" and ends with the code unit BEFORE the code unit specfied michael@0: * by "textEnd". The starting position is specified by "textPos". If michael@0: * "textBegin" and "textEnd" don't form a valid range on "text" (i.e., michael@0: * textBegin >= textEnd or either is negative or greater than text.size()), michael@0: * or "textPos" is outside the range defined by "textBegin" and "textEnd", michael@0: * the behavior of this iterator is undefined. michael@0: * @param textStr The unicode string used to create the StringCharacterIterator michael@0: * @param textBegin The begin position of the iteration range michael@0: * @param textEnd The end position of the iteration range michael@0: * @param textPos The starting position of the iteration michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator(const UnicodeString& textStr, michael@0: int32_t textBegin, michael@0: int32_t textEnd, michael@0: int32_t textPos); michael@0: michael@0: /** michael@0: * Copy constructor. The new iterator iterates over the same range michael@0: * of the same string as "that", and its initial position is the michael@0: * same as "that"'s current position. michael@0: * The UnicodeString object in "that" is copied. michael@0: * @param that The StringCharacterIterator to be copied michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator(const StringCharacterIterator& that); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~StringCharacterIterator(); michael@0: michael@0: /** michael@0: * Assignment operator. *this is altered to iterate over the same michael@0: * range of the same string as "that", and refers to the same michael@0: * character within that string as "that" does. michael@0: * @param that The object to be copied. michael@0: * @return the newly created object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator& michael@0: operator=(const StringCharacterIterator& that); michael@0: michael@0: /** michael@0: * Returns true if the iterators iterate over the same range of the michael@0: * same string and are pointing at the same character. michael@0: * @param that The ForwardCharacterIterator to be compared for equality michael@0: * @return true if the iterators iterate over the same range of the michael@0: * same string and are pointing at the same character. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const ForwardCharacterIterator& that) const; michael@0: michael@0: /** michael@0: * Returns a new StringCharacterIterator referring to the same michael@0: * character in the same range of the same string as this one. The michael@0: * caller must delete the new iterator. michael@0: * @return the newly cloned object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual CharacterIterator* clone(void) const; michael@0: michael@0: /** michael@0: * Sets the iterator to iterate over the provided string. michael@0: * @param newText The string to be iterated over michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setText(const UnicodeString& newText); michael@0: michael@0: /** michael@0: * Copies the UnicodeString under iteration into the UnicodeString michael@0: * referred to by "result". Even if this iterator iterates across michael@0: * only a part of this string, the whole string is copied. michael@0: * @param result Receives a copy of the text under iteration. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void getText(UnicodeString& result); michael@0: michael@0: /** michael@0: * Return a class ID for this object (not really public) michael@0: * @return a class ID for this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: michael@0: /** michael@0: * Return a class ID for this class (not really public) michael@0: * @return a class ID for this class michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: protected: michael@0: /** michael@0: * Default constructor, iteration over empty string. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: StringCharacterIterator(); michael@0: michael@0: /** michael@0: * Sets the iterator to iterate over the provided string. michael@0: * @param newText The string to be iterated over michael@0: * @param newTextLength The length of the String michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setText(const UChar* newText, int32_t newTextLength); michael@0: michael@0: /** michael@0: * Copy of the iterated string object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString text; michael@0: michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: #endif