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