E-MailRelay
Public Types | Public Member Functions | List of all members
G::StringTokenT< T > Class Template Reference

A zero-copy string token iterator where the token separators are runs of whitespace characters, with no support for escape characters. More...

#include <gstringtoken.h>

Public Types

using char_type = typename T::value_type
 

Public Member Functions

 StringTokenT (const T &s, const char_type *ws, std::size_t wsn) noexcept
 Constructor. More...
 
 StringTokenT (const T &s, std::string_view ws) noexcept
 Constructor. More...
 
bool valid () const noexcept
 Returns true if a valid token position. More...
 
 operator bool () const noexcept
 Returns true if a valid token. More...
 
const char_type * data () const noexcept
 Returns the current token pointer. More...
 
std::size_t size () const noexcept
 Returns the current token size. More...
 
std::size_t pos () const noexcept
 Returns the offset of data(). More...
 
operator() () const noexcept(std::is_same< T, std::string_view >::value)
 Returns the current token substring or T() if not valid(). More...
 
StringTokenT< T > & operator++ () noexcept
 Moves to the next token. More...
 
StringTokenT< T > & next () noexcept
 Moves to the next token. More...
 
 StringTokenT (T &&s, const char_type *, std::size_t)=delete
 
 StringTokenT (T &&s, std::string_view)=delete
 
 StringTokenT (const StringTokenT< T > &)=delete
 
 StringTokenT (StringTokenT< T > &&)=delete
 
StringTokenT< T > & operator= (const StringTokenT< T > &)=delete
 
StringTokenT< T > & operator= (StringTokenT< T > &&)=delete
 

Detailed Description

template<typename T>
class G::StringTokenT< T >

A zero-copy string token iterator where the token separators are runs of whitespace characters, with no support for escape characters.

Leading and trailing whitespace are not significant. Empty whitespace yields a single token. Stepping beyond the last token is allowed.

for( StringToken t(s," \t",2U) ; t ; ++t )
std::cout << t() << "\n" ;
See also
G::Str::splitIntoTokens()

Definition at line 53 of file gstringtoken.h.

Member Typedef Documentation

◆ char_type

template<typename T >
using G::StringTokenT< T >::char_type = typename T::value_type

Definition at line 56 of file gstringtoken.h.

Constructor & Destructor Documentation

◆ StringTokenT() [1/2]

template<typename T >
G::StringTokenT< T >::StringTokenT ( const T &  s,
const char_type *  ws,
std::size_t  wsn 
)
noexcept

Constructor.

The parameters must stay valid for the object lifefime.

The rvalue overload is deleted to avoid passing a temporary T that has been implicitly constructed from something else. Temporary std::string_views constructed from a string would be safe, but might be unsafe for other types.

Definition at line 133 of file gstringtoken.h.

◆ StringTokenT() [2/2]

template<typename T >
G::StringTokenT< T >::StringTokenT ( const T &  s,
std::string_view  ws 
)
noexcept

Constructor.

The parameters must stay valid for the object lifefime.

Definition at line 146 of file gstringtoken.h.

Member Function Documentation

◆ data()

template<typename T >
const T::value_type * G::StringTokenT< T >::data
noexcept

Returns the current token pointer.

Definition at line 156 of file gstringtoken.h.

◆ next()

template<typename T >
G::StringTokenT< T > & G::StringTokenT< T >::next
noexcept

Moves to the next token.

Definition at line 205 of file gstringtoken.h.

◆ operator bool()

template<typename T >
G::StringTokenT< T >::operator bool
explicitnoexcept

Returns true if a valid token.

Definition at line 175 of file gstringtoken.h.

◆ operator()()

template<typename T >
T G::StringTokenT< T >::operator()
noexcept

Returns the current token substring or T() if not valid().

Definition at line 187 of file gstringtoken.h.

◆ operator++()

template<typename T >
G::StringTokenT< T > & G::StringTokenT< T >::operator++
noexcept

Moves to the next token.

Definition at line 194 of file gstringtoken.h.

◆ pos()

template<typename T >
std::size_t G::StringTokenT< T >::pos
noexcept

Returns the offset of data().

Definition at line 169 of file gstringtoken.h.

◆ size()

template<typename T >
std::size_t G::StringTokenT< T >::size
noexcept

Returns the current token size.

Definition at line 163 of file gstringtoken.h.

◆ valid()

template<typename T >
bool G::StringTokenT< T >::valid
noexcept

Returns true if a valid token position.

Definition at line 181 of file gstringtoken.h.


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