NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
StringView Class Reference

This class is the immutable (const) version of a string view. It can be constructed from a MutableStringView, but cannot be used to construct a mutable version. More...

#include <structures.hpp>

Inheritance diagram for StringView:
Collaboration diagram for StringView:

Public Member Functions

 StringView ()
 StringView default constructor. More...
 
 StringView (const std::string *data)
 StringView constructor from a const std::string pointer. More...
 
 StringView (const std::string &data)
 StringView constructor from a const std::string reference. More...
 
 StringView (const std::string &data, size_t start, size_t len=std::string::npos)
 StringView constructor from a const std::string reference, a start and a length. More...
 
 StringView (const StringView &view)
 StringView copy constructor. More...
 
 StringView (const MutableStringView &view)
 StringView constructor from a MutableStringView class instance. More...
 
 StringView (StringView &&view)
 StringView move constructor. More...
 
StringViewoperator= (const StringView &view)
 Assignment operator for another StringView instance. More...
 
StringViewoperator= (const MutableStringView &view)
 Assignment operator for a MutableStringView class instance. More...
 
StringViewoperator= (const std::string *data)
 Assignment operator for a const std::string pointer. More...
 
StringViewoperator= (const std::string &data)
 Assignment operator for a const std::string reference. More...
 
const char & operator[] (size_t pos) const
 Random access operator, returning a const char reference. More...
 
StringView subview (size_t pos=0, size_t len=std::string::npos) const
 This member function creates a new StringView class instance using the selected position and length as a new viewed part. The position has to be part of the viewed section of this instance. This function can be used to replace std::string::substr. More...
 
MutableStringView make_mutable () const
 This member function returns a MutableStringView instance with the data of this instance. More...
 
- Public Member Functions inherited from StringViewBase
 StringViewBase ()
 StringViewBase default constructor. More...
 
virtual const std::string * getData () const
 This member function returns a const pointer to the viewed string. Is only used internally. More...
 
bool operator== (const StringViewBase &view) const
 This member function is an overload for the equality operator using another StringViewBase instance. More...
 
bool operator== (const std::string &sString) const
 This member function is an overload for the equality operator using a const std::string instance. More...
 
bool operator== (const char *sString) const
 This member function is an overload for the equality operator using a const char*. More...
 
bool operator!= (const StringViewBase &view) const
 This member function is an overload for the inequality operator using another StringViewBase instance. More...
 
bool operator!= (const std::string &sString) const
 This member function is an overload for the inequality operator using a const std::string instance. More...
 
bool operator!= (const char *sString) const
 This member function is an overload for the inequality operator using a const char*. More...
 
bool operator< (const StringViewBase &view) const
 This member function is an overload for the less operator using another StringViewBase instance. More...
 
bool operator< (const std::string &sString) const
 This member function is an overload for the less operator using a const std::string instance. More...
 
bool operator<= (const StringViewBase &view) const
 This member function is an overload for the less-equal operator using another StringViewBase instance. More...
 
bool operator<= (const std::string &sString) const
 This member function is an overload for the less-equal operator using a const std::string instance. More...
 
bool operator> (const StringViewBase &view) const
 This member function is an overload for the greater operator using another StringViewBase instance. More...
 
bool operator> (const std::string &sString) const
 This member function is an overload for the greater operator using a const std::string instance. More...
 
bool operator>= (const StringViewBase &view) const
 This member function is an overload for the greater-equal operator using another StringViewBase instance. More...
 
bool operator>= (const std::string &sString) const
 This member function is an overload for the greater-equal operator using a const std::string instance. More...
 
std::string operator+ (const StringViewBase &view) const
 This member function is an overload for the concatenation operator using another StringViewBase instance. More...
 
std::string operator+ (const std::string &sString) const
 This member function is an overload for the concatenation operator using a const std::string instance. More...
 
const char & front () const
 This member function provides a const char reference to the first character in the viewed section. More...
 
const char & back () const
 This member function provides a const char reference to the last character in the viewed section. More...
 
std::string::const_iterator begin () const
 This member function provides an iterator to the beginning of the viewed section of the internal string. More...
 
std::string::const_iterator end () const
 This member function provides an iterator to the end of the viewed section of the internal string. More...
 
void trim_front (size_t len)
 This member function can be used to remove characters from the front of the viewed section. More...
 
void trim_back (size_t len)
 This member function can be used to remove characters from the back of the viewed section. More...
 
void strip ()
 This member function shrinks the viewed section to remove all leading or trailing whitespace characters. This is the corresponding member function to StripSpaces(std::string&). More...
 
size_t length () const
 This member function simply returns the length of the viewed section. More...
 
std::string to_string () const
 This member function returns a copy of the viewed section of the string (via std::string::substr). Note that this is an inefficient operation. More...
 
size_t find (const std::string &findstr, size_t pos=0) const
 Wrapper member function for std::string::find() More...
 
size_t find (char c, size_t pos=0) const
 Wrapper member function for std::string::find() More...
 
size_t rfind (const std::string &findstr, size_t pos=std::string::npos) const
 Wrapper member function for std::string::rfind() More...
 
size_t rfind (char c, size_t pos=std::string::npos) const
 Wrapper member function for std::string::rfind() More...
 
size_t find_first_of (const std::string &findstr, size_t pos=0) const
 Wrapper member function for std::string::find_first_of() More...
 
size_t find_first_of (char c, size_t pos=0) const
 Wrapper member function for std::string::find_first_of() More...
 
size_t find_first_not_of (const std::string &findstr, size_t pos=0) const
 Wrapper member function for std::string::find_first_not_of() More...
 
size_t find_first_not_of (char c, size_t pos=0) const
 Wrapper member function for std::string::find_first_not_of() More...
 
size_t find_last_of (const std::string &findstr, size_t pos=std::string::npos) const
 Wrapper member function for std::string::find_last_of() More...
 
size_t find_last_of (char c, size_t pos=std::string::npos) const
 Wrapper member function for std::string::find_last_of() More...
 
size_t find_last_not_of (const std::string &findstr, size_t pos=std::string::npos) const
 Wrapper member function for std::string::find_last_not_of() More...
 
size_t find_last_not_of (char c, size_t pos=std::string::npos) const
 Wrapper member function for std::string::find_last_not_of() More...
 

Protected Member Functions

virtual const std::string * getData () const override
 Override to return a pointer to the internal string. More...
 
void assign (const StringView &view)
 Assignment member function from another StringView instance. More...
 
void assign (const MutableStringView &view)
 Assignment member function from a MutableStringView instance. More...
 
void assign (const std::string *data)
 Assignment member function from a const std::string pointer. More...
 
virtual void clear () override
 Override to clear the internal pointer as well. More...
 
- Protected Member Functions inherited from StringViewBase
size_t validizeLength (size_t pos, size_t len) const
 This private member function evaluates, whether the passed length is part of the viewed section and adapts the length correspondingly. More...
 
virtual void clear ()
 Reset function. More...
 
bool validAbsolutePosition (size_t pos) const
 This member function checks, whether the passed (absolute) position is part of the viewed string section. Is mostly used in string find operations. More...
 

Private Member Functions

 StringView (const std::string *data, size_t start, size_t len)
 Private constructor used by the subview member function. More...
 

Private Attributes

const std::string * m_data
 

Additional Inherited Members

- Protected Attributes inherited from StringViewBase
size_t m_start
 
size_t m_len
 

Detailed Description

This class is the immutable (const) version of a string view. It can be constructed from a MutableStringView, but cannot be used to construct a mutable version.

Definition at line 2034 of file structures.hpp.

Constructor & Destructor Documentation

◆ StringView() [1/8]

StringView::StringView ( const std::string *  data,
size_t  start,
size_t  len 
)
inlineprivate

Private constructor used by the subview member function.

Parameters
datastd::string* const
startsize_t
lensize_t

Definition at line 2048 of file structures.hpp.

References StringViewBase::m_len, and StringViewBase::m_start.

◆ StringView() [2/8]

StringView::StringView ( )
inline

StringView default constructor.

Definition at line 2133 of file structures.hpp.

Referenced by subview().

◆ StringView() [3/8]

StringView::StringView ( const std::string *  data)
inline

StringView constructor from a const std::string pointer.

Parameters
dataconst std::string*

Definition at line 2142 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ StringView() [4/8]

StringView::StringView ( const std::string &  data)
inline

StringView constructor from a const std::string reference.

Parameters
dataconst std::string&

Definition at line 2154 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ StringView() [5/8]

StringView::StringView ( const std::string &  data,
size_t  start,
size_t  len = std::string::npos 
)
inline

StringView constructor from a const std::string reference, a start and a length.

Parameters
dataconst std::string&
startsize_t
lensize_t

Definition at line 2168 of file structures.hpp.

References assign(), m_data, StringViewBase::m_len, StringViewBase::m_start, and StringViewBase::validizeLength().

Here is the call graph for this function:

◆ StringView() [6/8]

StringView::StringView ( const StringView view)
inline

StringView copy constructor.

Parameters
viewconst StringView&

Definition at line 2186 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ StringView() [7/8]

StringView::StringView ( const MutableStringView view)
inline

StringView constructor from a MutableStringView class instance.

Parameters
viewconst MutableStringView&

Definition at line 2198 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ StringView() [8/8]

StringView::StringView ( StringView &&  view)
inline

StringView move constructor.

Parameters
viewStringView&&

Definition at line 2209 of file structures.hpp.

References m_data, StringViewBase::m_len, and StringViewBase::m_start.

Member Function Documentation

◆ assign() [1/3]

void StringView::assign ( const MutableStringView view)
inlineprotected

Assignment member function from a MutableStringView instance.

Parameters
viewconst MutableStringView&
Returns
void

Definition at line 2090 of file structures.hpp.

References MutableStringView::m_data, m_data, StringViewBase::m_len, and StringViewBase::m_start.

◆ assign() [2/3]

void StringView::assign ( const std::string *  data)
inlineprotected

Assignment member function from a const std::string pointer.

Parameters
dataconst std::string*
Returns
void

Definition at line 2105 of file structures.hpp.

References m_data, StringViewBase::m_len, and StringViewBase::m_start.

◆ assign() [3/3]

void StringView::assign ( const StringView view)
inlineprotected

Assignment member function from another StringView instance.

Parameters
viewconst StringView&
Returns
void

Definition at line 2075 of file structures.hpp.

References m_data, StringViewBase::m_len, and StringViewBase::m_start.

Referenced by operator=(), and StringView().

◆ clear()

virtual void StringView::clear ( )
inlineoverrideprotectedvirtual

Override to clear the internal pointer as well.

Returns
virtual void

Reimplemented from StringViewBase.

Definition at line 2122 of file structures.hpp.

References m_data, StringViewBase::m_len, and StringViewBase::m_start.

◆ getData()

virtual const std::string * StringView::getData ( ) const
inlineoverrideprotectedvirtual

Override to return a pointer to the internal string.

Returns
const std::string*

Reimplemented from StringViewBase.

Definition at line 2062 of file structures.hpp.

References m_data.

◆ make_mutable()

MutableStringView StringView::make_mutable ( ) const
inline

This member function returns a MutableStringView instance with the data of this instance.

Returns
MutableStringView
Warning
Only use this method, if you know, what you're doing.

Definition at line 2320 of file structures.hpp.

References m_data, StringViewBase::m_len, and StringViewBase::m_start.

◆ operator=() [1/4]

StringView & StringView::operator= ( const MutableStringView view)
inline

Assignment operator for a MutableStringView class instance.

Parameters
viewconst MutableStringView&
Returns
StringView&

Definition at line 2238 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=() [2/4]

StringView & StringView::operator= ( const std::string &  data)
inline

Assignment operator for a const std::string reference.

Parameters
dataconst std::string&
Returns
StringView&

Definition at line 2266 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=() [3/4]

StringView & StringView::operator= ( const std::string *  data)
inline

Assignment operator for a const std::string pointer.

Parameters
dataconst std::string*
Returns
StringView&

Definition at line 2252 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=() [4/4]

StringView & StringView::operator= ( const StringView view)
inline

Assignment operator for another StringView instance.

Parameters
viewconst StringView&
Returns
StringView&

Definition at line 2224 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator[]()

const char & StringView::operator[] ( size_t  pos) const
inline

Random access operator, returning a const char reference.

Parameters
possize_t
Returns
const char&
Remarks
No boundary checks are performed.

Definition at line 2281 of file structures.hpp.

References m_data, and StringViewBase::m_start.

◆ subview()

StringView StringView::subview ( size_t  pos = 0,
size_t  len = std::string::npos 
) const
inline

Member Data Documentation

◆ m_data

const std::string* StringView::m_data
private

Definition at line 2037 of file structures.hpp.

Referenced by assign(), clear(), getData(), make_mutable(), operator[](), StringView(), and subview().


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