c++-gtk-utils
Public Types | Public Member Functions | List of all members
Cgu::Utf8::ReverseIterator Class Reference

A class which will iterate in reverse through a std::string object by reference to unicode characters rather than by bytes. More...

#include <c++-gtk-utils/convert.h>

Public Types

typedef gunichar value_type
 
typedef gunichar reference
 
typedef void pointer
 
typedef std::string::difference_type difference_type
 
typedef std::bidirectional_iterator_tag iterator_category
 

Public Member Functions

ReverseIteratoroperator++ ()
 
ReverseIterator operator++ (int)
 
ReverseIteratoroperator-- ()
 
ReverseIterator operator-- (int)
 
ReverseIteratoroperator= (const std::string::const_reverse_iterator &iter)
 
ReverseIteratoroperator= (const std::string::reverse_iterator &iter)
 
ReverseIteratoroperator= (const ReverseIterator &iter)
 
ReverseIteratoroperator= (const Iterator &iter)
 
ReverseIterator::value_type operator* () const
 
std::string::const_iterator base () const
 
 ReverseIterator (const std::string::const_reverse_iterator &iter)
 
 ReverseIterator (const std::string::reverse_iterator &iter)
 
 ReverseIterator (const ReverseIterator &iter)
 
 ReverseIterator (const Iterator &iter)
 
 ReverseIterator ()
 

Detailed Description

A class which will iterate in reverse through a std::string object by reference to unicode characters rather than by bytes.

See also
Cgu::Utf8::Iterator

The Cgu::Utf8::ReverseIterator class does the same as std::string::const_reverse_iterator, except that when iterating through a std::string object using the ++ and - - postfix and prefix operators, it iterates by increments of whole unicode code points rather than by reference to bytes. In addition, the dereferencing operator returns the whole unicode code point (a UCS-4 gunichar type) rather than a char type.

Before use, the Cgu::Utf8::ReverseIterator object must be initialized by a std::string::const_reverse_iterator or std::string::reverse_iterator object representing the first byte of a valid UTF-8 character in the string (or by another Cgu::Utf8::ReverseIterator object or by a Cgu::Utf8::Iterator object): so assuming the string contains valid UTF-8 text, it is always valid to initialise a Cgu::Utf8::ReverseIterator with std::string::rbegin(). Initialization by std::string::rend() is also valid if the first interation is backwards with the -- operator. This initialization can be done either in the constructor or by assignment. Comparison operators ==, !=, <, <=, > and >= are provided enabling the position of Cgu::Utf8::ReverseIterator objects to be compared with each other or with std::string::const_reverse_iterator and std::string::reverse_iterator objects.

This is an example:

using namespace Cgu;
std::wstring wide_str(L"ßøǿón");
std::string narrow_str(Utf8::uniwide_to_utf8(wide_str));
for (iter = narrow_str.rbegin();
iter != narrow_str.rend();
++iter)
std::wcout << static_cast<wchar_t>(*iter) << std::endl;

For further information on its use, see the Utf8::Iterator documentation.

Member Typedef Documentation

◆ difference_type

typedef std::string::difference_type Cgu::Utf8::ReverseIterator::difference_type

◆ iterator_category

typedef std::bidirectional_iterator_tag Cgu::Utf8::ReverseIterator::iterator_category

◆ pointer

◆ reference

◆ value_type

Constructor & Destructor Documentation

◆ ReverseIterator() [1/5]

Cgu::Utf8::ReverseIterator::ReverseIterator ( const std::string::const_reverse_iterator &  iter)
inline

Constructs this iterator and initialises it with a std::string::const_reverse_iterator object. It should represent the beginning of a UTF-8 character (eg std::string::rbegin()) or comprise std::string::rend(). It will not throw provided that copy constructing a std::string::const_iterator object does not throw, as it will not in any sane implementation. This is a type conversion constructor (it is not marked explicit) so that it can be used with Cgu::Utf8::ReverseIterator comparison operators to compare the position of Cgu::Utf8::ReverseIterator with std::string::const_reverse_iterator objects.

Parameters
iterThe const_reverse_iterator.

◆ ReverseIterator() [2/5]

Cgu::Utf8::ReverseIterator::ReverseIterator ( const std::string::reverse_iterator &  iter)
inline

Constructs this iterator and initialises it with a std::string::reverse_iterator object. It should represent the beginning of a UTF-8 character (eg std::string::rbegin()) or comprise std::string::rend(). It will not throw provided that copy constructing a std::string::const_iterator object does not throw, as it will not in any sane implementation. This is a type conversion constructor (it is not marked explicit) so that it can be used with Cgu::Utf8::ReverseIterator comparison operators to compare the position of Cgu::Utf8::ReverseIterator with std::string::reverse_iterator objects.

Parameters
iterThe reverse_iterator.

◆ ReverseIterator() [3/5]

Cgu::Utf8::ReverseIterator::ReverseIterator ( const ReverseIterator iter)
inline

Constructs this iterator and initialises it with another Cgu::Utf8::ReverseIterator object. It will not throw provided that copy constructing a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe iterator.

◆ ReverseIterator() [4/5]

Cgu::Utf8::ReverseIterator::ReverseIterator ( const Iterator iter)
inlineexplicit

Constructs this iterator and initialises it with a Cgu::Utf8::Iterator object, so that this iterator adopts the same physical position (but the logical position will be offset to the previous UTF-8 character in the std::string object concerned). It will not throw provided that copy constructing a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe iterator.

◆ ReverseIterator() [5/5]

Cgu::Utf8::ReverseIterator::ReverseIterator ( )
inline

The default constructor will not throw.

Member Function Documentation

◆ base()

std::string::const_iterator Cgu::Utf8::ReverseIterator::base ( ) const
inline
Returns
The current underlying std::string::const_iterator kept by this iterator. Once this iterator has been correctly initialized, that will point to the beginning of the UTF-8 character after the one currently represented by this iterator or to std::string::end(). It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

◆ operator*()

ReverseIterator::value_type Cgu::Utf8::ReverseIterator::operator* ( ) const
inline

The dereference operator. Note that although this method is const, it is not thread safe for concurrent reads without external synchronization because it writes to an internal cache.

Returns
A 32-bit gunichar object containing the whole unicode code point which is currently represented by this iterator. It will not throw.

◆ operator++() [1/2]

ReverseIterator & Cgu::Utf8::ReverseIterator::operator++ ( )
inline

Increments the iterator in the reverse direction so that it moves from the beginning of the current UTF-8 character to the beginning of the previous UTF-8 character in the std::string object concerned. It is a prefix operator. It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Returns
A reference to the iterator in its new position

◆ operator++() [2/2]

ReverseIterator Cgu::Utf8::ReverseIterator::operator++ ( int  )
inline

Increments the iterator in the reverse direction so that it moves from the beginning of the current UTF-8 character to the beginning of the previous UTF-8 character in the std::string object concerned. It is a postfix operator. It will not throw provided that copy constructing and assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Returns
A copy of the iterator in its former position

◆ operator--() [1/2]

ReverseIterator & Cgu::Utf8::ReverseIterator::operator-- ( )
inline

Decrements the iterator in the reverse direction so that it moves from the beginning of the current UTF-8 character to the beginning of the following UTF-8 character in the std::string object concerned. It is a prefix operator. It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Returns
A reference to the iterator in its new position

◆ operator--() [2/2]

ReverseIterator Cgu::Utf8::ReverseIterator::operator-- ( int  )
inline

Decrements the iterator in the reverse direction so that it moves from the beginning of the current UTF-8 character to the beginning of the following UTF-8 character in the std::string object concerned. It is a postfix operator. It will not throw provided that copy constructing and assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Returns
A copy of the iterator in its former position

◆ operator=() [1/4]

ReverseIterator& Cgu::Utf8::ReverseIterator::operator= ( const Iterator iter)
inline

Assigns a Cgu::Utf8::Iterator object to this object, so that this iterator adopts the same physical position (but the logical position will be offset to the previous UTF-8 character in the std::string object concerned). It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe iterator.
Returns
A reference to this Cgu::Utf8::ReverseIterator object after assignment.

◆ operator=() [2/4]

ReverseIterator& Cgu::Utf8::ReverseIterator::operator= ( const ReverseIterator iter)
inline

Assigns a Cgu::Utf8::ReverseIterator object to this object. It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe iterator.
Returns
A reference to this Cgu::Utf8::ReverseIterator object after assignment.

◆ operator=() [3/4]

ReverseIterator& Cgu::Utf8::ReverseIterator::operator= ( const std::string::const_reverse_iterator &  iter)
inline

Assigns a std::string::const_reverse_iterator object to this object. It should represent the beginning of a UTF-8 character (eg std::string::rbegin()) or comprise std::string::rend(). It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe const_reverse_iterator.
Returns
A reference to this Cgu::Utf8::ReverseIterator object after assignment.

◆ operator=() [4/4]

ReverseIterator& Cgu::Utf8::ReverseIterator::operator= ( const std::string::reverse_iterator &  iter)
inline

Assigns a std::string::reverse_iterator object to this object. It should represent the beginning of a UTF-8 character (eg std::string::rbegin()) or comprise std::string::rend(). It will not throw provided assigning a std::string::const_iterator object does not throw, as it will not in any sane implementation.

Parameters
iterThe reverse_iterator.
Returns
A reference to this Cgu::Utf8::ReverseIterator object after assignment.

The documentation for this class was generated from the following file:
Cgu
Definition: application.h:44
Cgu::Utf8::ReverseIterator
A class which will iterate in reverse through a std::string object by reference to unicode characters...
Definition: convert.h:697
Cgu::Utf8::uniwide_to_utf8
std::string uniwide_to_utf8(const std::wstring &input)