sl@0: /* 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: * File schriter.h sl@0: * sl@0: * Modification History: sl@0: * sl@0: * Date Name Description sl@0: * 05/05/99 stephen Cleaned up. sl@0: ****************************************************************************** sl@0: */ sl@0: sl@0: #ifndef SCHRITER_H sl@0: #define SCHRITER_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/chariter.h" sl@0: #include "unicode/uchriter.h" sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C++ API: String Character Iterator sl@0: */ sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: /** sl@0: * A concrete subclass of CharacterIterator that iterates over the sl@0: * characters (code units or code points) in a UnicodeString. sl@0: * It's possible not only to create an sl@0: * iterator that iterates over an entire UnicodeString, but also to sl@0: * create one that iterates over only a subrange of a UnicodeString sl@0: * (iterators over different subranges of the same UnicodeString 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 StringCharacterIterator : public UCharCharacterIterator { sl@0: public: sl@0: /** sl@0: * Create an iterator over the UnicodeString referred to by "textStr". sl@0: * The UnicodeString object is copied. sl@0: * The iteration range is the whole string, and the starting position is 0. sl@0: * @param textStr The unicode string used to create an iterator sl@0: * @stable ICU 2.0 sl@0: */ sl@0: StringCharacterIterator(const UnicodeString& textStr); sl@0: sl@0: /** sl@0: * Create an iterator over the UnicodeString referred to by "textStr". sl@0: * The iteration range is the whole string, and the starting sl@0: * position is specified by "textPos". If "textPos" is outside the valid sl@0: * iteration range, the behavior of this object is undefined. sl@0: * @param textStr The unicode string used to create an iterator sl@0: * @param textPos The starting position of the iteration sl@0: * @stable ICU 2.0 sl@0: */ sl@0: StringCharacterIterator(const UnicodeString& textStr, sl@0: int32_t textPos); sl@0: sl@0: /** sl@0: * Create an iterator over the UnicodeString referred to by "textStr". sl@0: * The UnicodeString object is copied. sl@0: * The iteration range begins with the code unit specified by sl@0: * "textBegin" and ends with the code unit BEFORE the code unit specfied sl@0: * by "textEnd". The starting position is specified by "textPos". If sl@0: * "textBegin" and "textEnd" don't form a valid range on "text" (i.e., sl@0: * textBegin >= textEnd or either is negative or greater than text.size()), sl@0: * or "textPos" is outside the range defined by "textBegin" and "textEnd", sl@0: * the behavior of this iterator is undefined. sl@0: * @param textStr The unicode string used to create the StringCharacterIterator 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 textPos The starting position of the iteration sl@0: * @stable ICU 2.0 sl@0: */ sl@0: StringCharacterIterator(const UnicodeString& textStr, sl@0: int32_t textBegin, sl@0: int32_t textEnd, sl@0: int32_t textPos); 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: * The UnicodeString object in "that" is copied. sl@0: * @param that The StringCharacterIterator to be copied sl@0: * @stable ICU 2.0 sl@0: */ sl@0: StringCharacterIterator(const StringCharacterIterator& that); sl@0: sl@0: /** sl@0: * Destructor. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual ~StringCharacterIterator(); sl@0: sl@0: /** sl@0: * Assignment operator. *this is altered to iterate over the same 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: StringCharacterIterator& sl@0: operator=(const StringCharacterIterator& 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 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: * Returns a new StringCharacterIterator 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 newly cloned object. 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 iterate over the provided string. sl@0: * @param newText The string to be iterated over sl@0: * @stable ICU 2.0 sl@0: */ sl@0: void setText(const UnicodeString& newText); sl@0: sl@0: /** sl@0: * Copies the UnicodeString 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 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: /** 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: protected: sl@0: /** sl@0: * Default constructor, iteration over empty string. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: StringCharacterIterator(); sl@0: sl@0: /** sl@0: * Sets the iterator to iterate over the provided string. sl@0: * @param newText The string to be iterated over sl@0: * @param newTextLength The length of the String sl@0: * @stable ICU 2.0 sl@0: */ sl@0: void setText(const UChar* newText, int32_t newTextLength); sl@0: sl@0: /** sl@0: * Copy of the iterated string object. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeString text; sl@0: sl@0: }; sl@0: sl@0: U_NAMESPACE_END sl@0: #endif