glibmm 2.80.0
Public Types | Public Member Functions | Related Functions | List of all members
Glib::ustring_Iterator< T > Class Template Reference

The iterator type of Glib::ustring. More...

#include <glibmm/ustring.h>

Public Types

using iterator_category = std::bidirectional_iterator_tag
 
using value_type = gunichar
 
using difference_type = std::string::difference_type
 
using reference = value_type
 
using pointer = void
 

Public Member Functions

 ustring_Iterator ()
 
 ustring_Iterator (const ustring_Iterator< std::string::iterator > & other)
 
ustring_Iteratoroperator= (const ustring_Iterator & other)=default
 
value_type operator* () const
 
ustring_Iterator< T > & operator++ ()
 
const ustring_Iterator< T > operator++ (int)
 
ustring_Iterator< T > & operator-- ()
 
const ustring_Iterator< T > operator-- (int)
 
 ustring_Iterator (T pos)
 
base () const
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 
bool operator!= (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 
bool operator< (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 
bool operator> (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 
bool operator<= (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 
bool operator>= (const Glib::ustring::const_iterator & lhs, const Glib::ustring::const_iterator & rhs)
 

Detailed Description

template<class T>
class Glib::ustring_Iterator< T >

The iterator type of Glib::ustring.

Note this is not a random access iterator but a bidirectional one, since all index operations need to iterate over the UTF-8 data. Use std::advance() to move to a certain position. However, all of the relational operators are available: == != < > <= >=

A writeable iterator isn't provided because: The number of bytes of the old UTF-8 character and the new one to write could be different. Therefore, any write operation would invalidate all other iterators pointing into the same string.

The Glib::ustring iterated over must contain only valid UTF-8 data. If it does not, operator++(), operator--() and operator*() may make accesses outside the bounds of the string. A loop such as the following one would not stop at the end of the string.

// Bad code! Don't do this!
const char not_utf8[] = { '\x80', '\xef', '\x80', '\x80', '\xef', '\x80' };
const Glib::ustring s(not_utf8, not_utf8 + sizeof not_utf8);
for (Glib::ustring::const_iterator it = s.begin(); it != s.end(); ++it)
std::cout << *it << std::endl;
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
The iterator type of Glib::ustring.
Definition: ustring.h:193
Glib::ustring has much the same interface as std::string, but contains Unicode characters encoded as ...
Definition: ustring.h:336
Template Parameters
Tstd::string::iterator or std::string::const_iterator

Member Typedef Documentation

◆ difference_type

template <class T >
using Glib::ustring_Iterator< T >::difference_type = std::string::difference_type

◆ iterator_category

template <class T >
using Glib::ustring_Iterator< T >::iterator_category = std::bidirectional_iterator_tag

◆ pointer

template <class T >
using Glib::ustring_Iterator< T >::pointer = void

◆ reference

template <class T >
using Glib::ustring_Iterator< T >::reference = value_type

◆ value_type

template <class T >
using Glib::ustring_Iterator< T >::value_type = gunichar

Constructor & Destructor Documentation

◆ ustring_Iterator() [1/3]

template <class T >
Glib::ustring_Iterator< T >::ustring_Iterator ( )
inline

◆ ustring_Iterator() [2/3]

template <class T >
Glib::ustring_Iterator< T >::ustring_Iterator ( const ustring_Iterator< std::string::iterator > &  other)
inline

◆ ustring_Iterator() [3/3]

template <class T >
Glib::ustring_Iterator< T >::ustring_Iterator ( pos)
inlineexplicit

Member Function Documentation

◆ base()

template <class T >
T Glib::ustring_Iterator< T >::base ( ) const
inline

◆ operator*()

template <class T >
value_type Glib::ustring_Iterator< T >::operator* ( ) const
inline

◆ operator++() [1/2]

template <class T >
ustring_Iterator< T > & Glib::ustring_Iterator< T >::operator++ ( )
inline

◆ operator++() [2/2]

template <class T >
const ustring_Iterator< T > Glib::ustring_Iterator< T >::operator++ ( int  )
inline

◆ operator--() [1/2]

template <class T >
ustring_Iterator< T > & Glib::ustring_Iterator< T >::operator-- ( )
inline

◆ operator--() [2/2]

template <class T >
const ustring_Iterator< T > Glib::ustring_Iterator< T >::operator-- ( int  )
inline

◆ operator=()

template <class T >
ustring_Iterator & Glib::ustring_Iterator< T >::operator= ( const ustring_Iterator< T > &  other)
default

Friends And Related Function Documentation

◆ operator!=()

template <class T >
bool operator!= ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related

◆ operator<()

template <class T >
bool operator< ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related

◆ operator<=()

template <class T >
bool operator<= ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related

◆ operator==()

template <class T >
bool operator== ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related

◆ operator>()

template <class T >
bool operator> ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related

◆ operator>=()

template <class T >
bool operator>= ( const Glib::ustring::const_iterator lhs,
const Glib::ustring::const_iterator rhs 
)
related