UtfString
Public Member Functions | List of all members
UtfString::UnicodeString::iterator Class Reference

An iterator that iterates through the code points in a Unicode string. More...

#include <UnicodeString.h>

Inherits iterator< std::random_access_iterator_tag, UnicodeChar >.

Public Member Functions

 iterator ()
 Creates an empty iterator. More...
 
 iterator (const Utf8String::iterator &utf8StringIterator)
 Constructs an iterator for UnicodeString using a Utf8String iterator. More...
 
 iterator (const Utf16String::iterator &utf16StringIterator)
 Constructs an iterator for UnicodeString using a Utf16String iterator. More...
 
 iterator (const UnicodeString::iterator &otherIterator)
 Constructs an iterator for UnicodeString using another iterator. More...
 
 iterator (const UnicodeString::reverse_iterator &reverseIterator)
 Constructs an iterator for UnicodeString using a reverse iterator. More...
 
 ~iterator ()
 Cleans up before the iterator is destroyed.
 
bool empty () const
 Indicates whether this iterator is an empty iterator. More...
 
iteratoroperator= (const UnicodeString::iterator &otherIterator)
 Assigns the value of another iterator to this iterator. More...
 
bool operator== (const iterator &otherIterator) const
 Compares this iterator with another iterator and tests for equality. More...
 
bool operator!= (const iterator &otherIterator) const
 Compares this iterator with another iterator and tests for inequality. More...
 
bool operator< (const iterator &otherIterator)
 Compares this iterator to another iterator and tests whether this iterator comes before the other iterator in the string. More...
 
bool operator<= (const iterator &otherIterator)
 Compares this iterator to another iterator and tests whether this iterator comes before or is at the same position the other iterator in the string. More...
 
bool operator> (const iterator &otherIterator)
 Compares this iterator to another iterator and tests whether this iterator comes after the other iterator in the string. More...
 
bool operator>= (const iterator &otherIterator)
 Compares this iterator to another iterator and tests whether this iterator comes after or is at the same position the other iterator in the string. More...
 
iteratoroperator++ ()
 Increments this iterator to the next position in the UnicodeString. More...
 
iterator operator++ (int)
 Increments this iterator to the next position in the UnicodeString. More...
 
iteratoroperator+= (size_t offset)
 Increments this iterator by a specific offset. More...
 
iterator operator+ (size_t offset)
 Creates an iterator that has the position of this iterator incremented by a specific offset. More...
 
iteratoroperator-- ()
 Decrements this iterator to the previous position in the UnicodeString. More...
 
iterator operator-- (int)
 Decrements this iterator to the previous position in the UnicodeString. More...
 
iteratoroperator-= (size_t offset)
 Decrements this iterator by a specific offset. More...
 
iterator operator- (size_t offset)
 Creates an iterator that has the position of this iterator decremented by a specific offset. More...
 
UnicodeCharReference operator* ()
 Gets the character at the position of this iterator. More...
 
UnicodeCharReferenceoperator-> ()
 Gets a pointer to the character at the position of this iterator. More...
 

Detailed Description

An iterator that iterates through the code points in a Unicode string.

This iterator assumes that the Unicode string being iterated over is a valid Unicode string.

There is also the concept of an "empty" iterator. An empty iterator is one that is created when begin() or end() is called on an empty UnicodeString. Attempting to change the position of an empty iterator using unary operator (such as "+=") will only result in nothing happening. Attempting to get an iterator for another position using a binary operator (such as "+") will result in another empty iterator being created. Dereferencing an iterator via the "*" or "->" operators will result in an assertion failure in a debug build or undefined behavior in a release build. Empty iterators are always equal to each other.

Constructor & Destructor Documentation

UtfString::UnicodeString::iterator::iterator ( )

Creates an empty iterator.

For a description of an empty iterator, see the class description

See Also
UnicodeString::iterator
UtfString::UnicodeString::iterator::iterator ( const Utf8String::iterator utf8StringIterator)

Constructs an iterator for UnicodeString using a Utf8String iterator.

This function assumes that utf8StringIterator is a valid iterator

Parameters
[in]utf8StringIteratorThe Utf8String iterator to use in constructing this iterator
UtfString::UnicodeString::iterator::iterator ( const Utf16String::iterator utf16StringIterator)

Constructs an iterator for UnicodeString using a Utf16String iterator.

This function assumes that utf16StringIterator is a valid iterator

Parameters
[in]utf16StringIteratorThe Utf16String iterator to use in constructing this iterator
UtfString::UnicodeString::iterator::iterator ( const UnicodeString::iterator otherIterator)

Constructs an iterator for UnicodeString using another iterator.

This iterator will take on the same characteristics and position as the other iterator

Parameters
[in]otherIteratorThe other iterator to use in constructing this iterator
UtfString::UnicodeString::iterator::iterator ( const UnicodeString::reverse_iterator reverseIterator)

Constructs an iterator for UnicodeString using a reverse iterator.

This iterator will take on the same position as the reverse iterator.

Parameters
[in]reverseIteratorThe reverse iterator to use in constructing this iterator

Member Function Documentation

bool UtfString::UnicodeString::iterator::empty ( ) const

Indicates whether this iterator is an empty iterator.

This is mainly for informational purposes. If you use iterators properly, comparing the begin iterator to the end iterator, you won't even need to know when an empty iterator appears. In case want to know whether an iterator is empty (as opposed to an non-empty iterator that has been incremented/decremented beyond the boundaries of a string), you can use this function.

bool UtfString::UnicodeString::iterator::operator!= ( const iterator otherIterator) const

Compares this iterator with another iterator and tests for inequality.

Empty iterators are always equal to other empty iterators and are always unequal to non-empty iterators.

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
false if otherIterator is pointing to the same position as this iterator, otherwise true
UnicodeCharReference UtfString::UnicodeString::iterator::operator* ( )

Gets the character at the position of this iterator.

If this iterator is not pointing to a position in a UnicodeString, the result will be undefined.

The reference returned by this function will be invalidated if the iterator is changed in any way. Changing the value of the returned object will not change the string.

If this iterator is an empty iterator, using this operator will result in an assertion failure in a debug build and undefined behavior (most likely a crash) in a release build.

See Also
UnicodeString::iterator::empty()
Returns
A reference to the the character being pointed to by this iterator
iterator UtfString::UnicodeString::iterator::operator+ ( size_t  offset)

Creates an iterator that has the position of this iterator incremented by a specific offset.

Note that since a Unicode string contains variable-width characters, we have to iterate over the code units. As a result, this operator has a performance of O(N). Hence, this operator should be used with care.

Parameters
[in]offsetThe offset to be used when incrementing this position of this iterator
Returns
An iterator that points to the offset position
iterator& UtfString::UnicodeString::iterator::operator++ ( )

Increments this iterator to the next position in the UnicodeString.

This is the prefix operator.

Returns
A reference to this object after the position has been incremented
iterator UtfString::UnicodeString::iterator::operator++ ( int  )

Increments this iterator to the next position in the UnicodeString.

This is a postfix operator.

Returns
A copy of this object before the position was incremented
iterator& UtfString::UnicodeString::iterator::operator+= ( size_t  offset)

Increments this iterator by a specific offset.

Note that since a Unicode string contains variable-width characters, we have to iterate over the code units. As a result, this operator has a performance of O(N). Hence, this operator should be used with care.

Parameters
[in]offsetThe offset to use in incrementing this iterator
Returns
A reference to this iterator
iterator UtfString::UnicodeString::iterator::operator- ( size_t  offset)

Creates an iterator that has the position of this iterator decremented by a specific offset.

Note that since a Unicode string contains variable-width characters, we have to iterate over the code units. As a result, this operator has a performance of O(N). Hence, this operator should be used with care.

Parameters
[in]offsetThe offset to use in decrementing the position of this iterator
Returns
An iterator that points to the offset position
iterator& UtfString::UnicodeString::iterator::operator-- ( )

Decrements this iterator to the previous position in the UnicodeString.

This is a prefix operator.

Returns
A reference to this object after the position has been decremented
iterator UtfString::UnicodeString::iterator::operator-- ( int  )

Decrements this iterator to the previous position in the UnicodeString.

This is a postfix operator.

Returns
A copy of this object before the position was decremented
iterator& UtfString::UnicodeString::iterator::operator-= ( size_t  offset)

Decrements this iterator by a specific offset.

Note that since a UTF-16 string contains variable-width characters, we have to iterate over the code units. As a result, this operator has a performance of O(N). Hence, this operator should be used with care.

Parameters
[in]offsetThe offset to use in decrementing this iterator
Returns
A reference to this iterator
UnicodeCharReference* UtfString::UnicodeString::iterator::operator-> ( )

Gets a pointer to the character at the position of this iterator.

If this iterator is not pointing to a position in a UnicodeString, the result will be undefined.

The pointer returned by this function will be invalidated if the iterator is changed in any way.

If this iterator is an empty iterator, using this operator will result in an assertion failure in a debug build and undefined behavior (most likely a crash) in a release build.

See Also
UnicodeString::iterator::empty()
Returns
A pointer to the character being pointed to by this iterator
bool UtfString::UnicodeString::iterator::operator< ( const iterator otherIterator)

Compares this iterator to another iterator and tests whether this iterator comes before the other iterator in the string.

Empty iterators are considered to be less than non-empty iterators. If the two iterators are pointing

This operator has a performance of O(1).

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
true if this iterator comes before the other iterator in a string, otherwise false
bool UtfString::UnicodeString::iterator::operator<= ( const iterator otherIterator)

Compares this iterator to another iterator and tests whether this iterator comes before or is at the same position the other iterator in the string.

Empty iterators are considered to be less than non-empty iterators.

This operator has a performance of O(1).

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
true if this iterator comes before or is at the same position the other iterator in a string, otherwise false
iterator& UtfString::UnicodeString::iterator::operator= ( const UnicodeString::iterator otherIterator)

Assigns the value of another iterator to this iterator.

This iterator will take on the same characteristics and position as the other iterator

Parameters
[in]otherIteratorThe other iterator to be assigned to this iterator
Returns
A reference to this object after the assignment has been completed
bool UtfString::UnicodeString::iterator::operator== ( const iterator otherIterator) const

Compares this iterator with another iterator and tests for equality.

Empty iterators are always equal to other empty iterators and are always unequal to non-empty iterators.

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
true if otherIterator is pointing to the same position as this iterator, otherwise false
bool UtfString::UnicodeString::iterator::operator> ( const iterator otherIterator)

Compares this iterator to another iterator and tests whether this iterator comes after the other iterator in the string.

Non-Empty iterators are considered to be greater than than empty iterators.

This operator has a performance of O(1).

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
true if this iterator comes after the other iterator in a string, otherwise false
bool UtfString::UnicodeString::iterator::operator>= ( const iterator otherIterator)

Compares this iterator to another iterator and tests whether this iterator comes after or is at the same position the other iterator in the string.

Non-Empty iterators are considered to be greater than than empty iterators.

This operator has a performance of O(1).

Parameters
[in]otherIteratorThe other iterator to be compared with this iterator
Returns
true if this iterator comes after or is at the same position the other iterator in a string, otherwise false

The documentation for this class was generated from the following file: