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

This class is a mutable version of a string view. It can be used to replace single characters or entire parts of the string. It's possible to convert a MutableStringView into a (const) StringView but not the other way around. More...

#include <structures.hpp>

Inheritance diagram for MutableStringView:
Collaboration diagram for MutableStringView:

Public Member Functions

 MutableStringView ()
 MutableStringView default constructor. More...
 
 MutableStringView (std::string *data)
 MutableStringView constructor from a std::string pointer. More...
 
 MutableStringView (std::string &data)
 MutableStringView constructor from a (non-const) std::string reference. More...
 
 MutableStringView (MutableStringView &view)
 MutableStringView copy constrcutor. More...
 
 MutableStringView (MutableStringView &&view)
 MutableStringView move constructor. More...
 
MutableStringViewoperator= (MutableStringView &view)
 Assignment operator for another MutableStringView instance. More...
 
MutableStringViewoperator= (std::string *data)
 Assignment operator for a std::string pointer. More...
 
MutableStringViewoperator= (std::string &data)
 Assignment operator for a std::string (non-const) reference. More...
 
char & operator[] (size_t pos)
 Implementation of the random access operator. Returns a (non-const) char reference. More...
 
MutableStringView subview (size_t pos=0, size_t len=std::string::npos) const
 This member function creates a new MutableStringView 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...
 
MutableStringViewreplace (size_t pos, size_t len, const std::string &s)
 This member function replaces a range in the internal viewed string with the passed string. More...
 
MutableStringViewreplace (size_t pos, size_t len, const std::string &s, size_t subpos, size_t sublen)
 This member function replaces a range in the internal viewed string with the passed string. This function allows to select a smaller part of the replacing string. More...
 
MutableStringViewreplace (size_t pos, size_t len, const StringViewBase &view)
 This member function replaces a range in the internal viewed string with the passed StringViewBase. 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 (MutableStringView &view)
 Assignment member function from another MutableStringView instance. More...
 
void assign (std::string *data)
 Assignment member function from a 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

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

Private Attributes

std::string * m_data
 

Friends

class StringView
 

Additional Inherited Members

- Protected Attributes inherited from StringViewBase
size_t m_start
 
size_t m_len
 

Detailed Description

This class is a mutable version of a string view. It can be used to replace single characters or entire parts of the string. It's possible to convert a MutableStringView into a (const) StringView but not the other way around.

Definition at line 1726 of file structures.hpp.

Constructor & Destructor Documentation

◆ MutableStringView() [1/6]

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

Private constructor used by the subview member function.

Parameters
datastd::string*
startsize_t
lensize_t

Definition at line 1741 of file structures.hpp.

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

◆ MutableStringView() [2/6]

MutableStringView::MutableStringView ( )
inline

MutableStringView default constructor.

Definition at line 1811 of file structures.hpp.

Referenced by subview().

◆ MutableStringView() [3/6]

MutableStringView::MutableStringView ( std::string *  data)
inline

MutableStringView constructor from a std::string pointer.

Parameters
datastd::string*

Definition at line 1820 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ MutableStringView() [4/6]

MutableStringView::MutableStringView ( std::string &  data)
inline

MutableStringView constructor from a (non-const) std::string reference.

Parameters
datastd::string&

Definition at line 1832 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ MutableStringView() [5/6]

MutableStringView::MutableStringView ( MutableStringView view)
inline

MutableStringView copy constrcutor.

Parameters
viewMutableStringView&

Definition at line 1843 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ MutableStringView() [6/6]

MutableStringView::MutableStringView ( MutableStringView &&  view)
inline

MutableStringView move constructor.

Parameters
viewMutableStringView&&

Definition at line 1854 of file structures.hpp.

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

Member Function Documentation

◆ assign() [1/2]

void MutableStringView::assign ( MutableStringView view)
inlineprotected

Assignment member function from another MutableStringView instance.

Parameters
viewMutableStringView&
Returns
void

Definition at line 1768 of file structures.hpp.

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

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

◆ assign() [2/2]

void MutableStringView::assign ( std::string *  data)
inlineprotected

Assignment member function from a std::string pointer.

Parameters
datastd::string*
Returns
void

Definition at line 1783 of file structures.hpp.

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

◆ clear()

virtual void MutableStringView::clear ( )
inlineoverrideprotectedvirtual

Override to clear the internal pointer as well.

Returns
virtual void

Reimplemented from StringViewBase.

Definition at line 1800 of file structures.hpp.

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

◆ getData()

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

Override to return a pointer to the internal string.

Returns
const std::string*

Reimplemented from StringViewBase.

Definition at line 1755 of file structures.hpp.

References m_data.

◆ operator=() [1/3]

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

Assignment operator for another MutableStringView instance.

Parameters
viewMutableStringView&
Returns
MutableStringView&

Definition at line 1869 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=() [2/3]

MutableStringView & MutableStringView::operator= ( std::string &  data)
inline

Assignment operator for a std::string (non-const) reference.

Parameters
datastd::string&
Returns
MutableStringView&

Definition at line 1897 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator=() [3/3]

MutableStringView & MutableStringView::operator= ( std::string *  data)
inline

Assignment operator for a std::string pointer.

Parameters
datastd::string*
Returns
MutableStringView&

Definition at line 1883 of file structures.hpp.

References assign().

Here is the call graph for this function:

◆ operator[]()

char & MutableStringView::operator[] ( size_t  pos)
inline

Implementation of the random access operator. Returns a (non-const) char reference.

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

Definition at line 1913 of file structures.hpp.

References m_data, and StringViewBase::m_start.

◆ replace() [1/3]

MutableStringView & MutableStringView::replace ( size_t  pos,
size_t  len,
const std::string &  s 
)
inline

This member function replaces a range in the internal viewed string with the passed string.

Parameters
possize_t
lensize_t
sconst std::string&
Returns
MutableStringView&
Remarks
Positions and lengths of other StringViews to the same strings are invalidated, if the lengths of the replaced and the replacing string differ.

Definition at line 1958 of file structures.hpp.

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

Referenced by mu::ParserBase::compileVectors(), mu::ParserBase::compileVectorsInMultiArgFunc(), and replace().

Here is the call graph for this function:

◆ replace() [2/3]

MutableStringView & MutableStringView::replace ( size_t  pos,
size_t  len,
const std::string &  s,
size_t  subpos,
size_t  sublen 
)
inline

This member function replaces a range in the internal viewed string with the passed string. This function allows to select a smaller part of the replacing string.

Parameters
possize_t
lensize_t
sconst std::string&
subpossize_t
sublensize_t
Returns
MutableStringView&
Remarks
Positions and lengths of other StringViews to the same strings are invalidated, if the lengths of the replaced and the replacing string differ.

Definition at line 1988 of file structures.hpp.

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

Here is the call graph for this function:

◆ replace() [3/3]

MutableStringView & MutableStringView::replace ( size_t  pos,
size_t  len,
const StringViewBase view 
)
inline

This member function replaces a range in the internal viewed string with the passed StringViewBase.

Parameters
possize_t
lensize_t
viewconst StringViewBase&
Returns
MutableStringView&
Remarks
Positions and lengths of other StringViews to the same strings are invalidated, if the lengths of the replaced and the replacing string differ.

Definition at line 2019 of file structures.hpp.

References replace(), and StringViewBase::to_string().

Here is the call graph for this function:

◆ subview()

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

This member function creates a new MutableStringView 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.

Parameters
possize_t
lensize_t
Returns
MutableStringView

Definition at line 1932 of file structures.hpp.

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

Referenced by mu::ParserBase::compileVectorExpansion(), mu::ParserBase::compileVectors(), and mu::ParserBase::compileVectorsInMultiArgFunc().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ StringView

friend class StringView
friend

Definition at line 1729 of file structures.hpp.

Member Data Documentation

◆ m_data

std::string* MutableStringView::m_data
private

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