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

A zero-copy string field iterator where the field separators are short fixed strings. More...

#include <gstringfield.h>

Public Types

using char_type = typename T::value_type
 

Public Member Functions

 StringFieldT (const T &s, const char_type *sep, std::size_t sepn) noexcept
 Constructor. More...
 
 StringFieldT (const T &s, char_type sep) noexcept
 Constructor. More...
 
 operator bool () const noexcept
 Returns true if a valid field. More...
 
bool valid () const noexcept
 Returns true if a valid field. More...
 
operator() () const noexcept(deref_operator_noexcept)
 Returns the current field substring. More...
 
StringFieldT< T > & operator++ () noexcept
 Moves to the next field. More...
 
const char_type * data () const noexcept
 Returns the current field pointer. More...
 
std::size_t size () const noexcept
 Returns the current field size. More...
 
bool first () const noexcept
 Returns true if the current field is the first. More...
 
bool last () const noexcept
 Returns true if the current field is the last. More...
 
std::size_t count () const noexcept
 Returns the number of fields. More...
 
 StringFieldT (T &&s, const char *, std::size_t)=delete
 
 StringFieldT (T &&s, char)=delete
 
 StringFieldT (const StringFieldT< T > &)=delete
 
 StringFieldT (StringFieldT< T > &&)=delete
 
StringFieldT< T > & operator= (const StringFieldT< T > &)=delete
 
StringFieldT< T > & operator= (StringFieldT< T > &&)=delete
 

Static Public Attributes

static constexpr bool deref_operator_noexcept = std::is_same<T,std::string_view>::value
 

Detailed Description

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

A zero-copy string field iterator where the field separators are short fixed strings.

for( StringField f(s,"\r\n",2U) ; f ; ++f )
std::cout << std::string_view(f.data(),f.size()) << "\n" ;
See also
G::Str::splitIntoFields(), G::SubString

Definition at line 52 of file gstringfield.h.

Member Typedef Documentation

◆ char_type

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

Definition at line 55 of file gstringfield.h.

Constructor & Destructor Documentation

◆ StringFieldT() [1/2]

template<typename T >
G::StringFieldT< T >::StringFieldT ( const T &  s,
const char_type *  sep,
std::size_t  sepn 
)
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 164 of file gstringfield.h.

◆ StringFieldT() [2/2]

template<typename T >
G::StringFieldT< T >::StringFieldT ( const T &  s,
char_type  sep 
)
noexcept

Constructor.

The parameters must stay valid for the object lifefime.

Definition at line 175 of file gstringfield.h.

Member Function Documentation

◆ count()

template<typename T >
std::size_t G::StringFieldT< T >::count
noexcept

Returns the number of fields.

Definition at line 243 of file gstringfield.h.

◆ data()

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

Returns the current field pointer.

Definition at line 186 of file gstringfield.h.

◆ first()

template<typename T >
bool G::StringFieldT< T >::first
noexcept

Returns true if the current field is the first.

Definition at line 231 of file gstringfield.h.

◆ last()

template<typename T >
bool G::StringFieldT< T >::last
noexcept

Returns true if the current field is the last.

Definition at line 237 of file gstringfield.h.

◆ operator bool()

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

Returns true if a valid field.

Definition at line 200 of file gstringfield.h.

◆ operator()()

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

Returns the current field substring.

Prefer data() and size() to avoid copying.

Definition at line 212 of file gstringfield.h.

◆ operator++()

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

Moves to the next field.

Definition at line 219 of file gstringfield.h.

◆ size()

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

Returns the current field size.

Definition at line 193 of file gstringfield.h.

◆ valid()

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

Returns true if a valid field.

Definition at line 206 of file gstringfield.h.

Member Data Documentation

◆ deref_operator_noexcept

template<typename T >
constexpr bool G::StringFieldT< T >::deref_operator_noexcept = std::is_same<T,std::string_view>::value
staticconstexpr

Definition at line 77 of file gstringfield.h.


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