COMMS
Template library intended to help with implementation of communication protocols.
Public Types | Public Member Functions | Static Public Attributes | Related Functions | List of all members
comms::util::StringView Class Reference

#include "comms/util/StringView.h"

Detailed Description

Describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero.

Similar to std::string_view introduced in C++17.

Inheritance diagram for comms::util::StringView:
comms::util::ArrayView< char >

Public Types

using const_iterator = typename Base::const_iterator
 Implementation defined constant RandomAccessIterator and ContiguousIterator whose value_type is char.
 
using const_pointer = typename Base::const_pointer
 Pointer to the constant character (const char*)
 
using const_reference = typename Base::const_reference
 Reference to a const character (const char&)
 
using const_reverse_iterator = typename Base::const_reverse_iterator
 Same as std::reverse_iterator<const_iterator>
 
using ConstIterator = const_iterator
 Same as const_iterator.
 
using ConstPointer = const_pointer
 Same as const_pointer.
 
using ConstReference = const_reference
 Same as const_reference.
 
using ConstReverseIterator = const_reverse_iterator
 Same as const_reverse_iterator.
 
using iterator = const_iterator
 Same as const_iterator.
 
using Iterator = iterator
 Same as iterator.
 
using pointer = typename Base::pointer
 Pointer to the character (char*)
 
using Pointer = pointer
 Same as pointer.
 
using reference = typename Base::reference
 Reference to a character (char&)
 
using Reference = reference
 Same as reference.
 
using reverse_iterator = const_reverse_iterator
 Same as const_reverse_iterator.
 
using ReverseIterator = reverse_iterator
 Same as reverse_iterator.
 
using size_type = typename Base::size_type
 Equal to std::size_t.
 
using SizeType = size_type
 Same as size_type;.
 
using value_type = typename Base::value_type
 Type of the character (char)
 
using ValueType = value_type
 Same as value_type.
 

Public Member Functions

 StringView () noexcept=default
 Default constructor. More...
 
template<std::size_t TN>
 StringView (char(&str)[TN]) noexcept
 Construct out of array of characters with known size. More...
 
 StringView (const char *str) noexcept
 Constructor. More...
 
 StringView (const char *str, size_type len) noexcept
 Constructor. More...
 
template<std::size_t TN>
 StringView (const char(&str)[TN]) noexcept
 Construct out of array of characters with known size. More...
 
 StringView (const std::string &str) noexcept
 Constructor.
 
 StringView (const StringView &) noexcept=default
 Copy constructor. More...
 
 ~StringView () noexcept=default
 Destructor.
 
const_reference at (size_type pos) const
 Similar to std::string::at() More...
 
constexpr const_reference back () const
 Same as std::string_view::back()
 
constexpr iterator begin () const noexcept
 Same as std::string_view::begin().
 
constexpr const_iterator cbegin () const noexcept
 Same as std::string_view::cbegin().
 
constexpr const_iterator cend () const noexcept
 Same as std::string_view::end().
 
int compare (const char *s) const
 Same as std::string_view::compare().
 
int compare (const StringView &other) const
 Same as std::string_view::compare().
 
int compare (size_type pos, size_type count, const char *s) const
 Same as std::string_view::compare().
 
int compare (size_type pos, size_type count, const StringView &other) const
 Same as std::string_view::compare().
 
int compare (size_type pos1, size_type count1, const char *s, size_type count2) const
 Same as std::string_view::compare().
 
int compare (size_type pos1, size_type count1, const StringView &other, size_type pos2, size_type count2) const
 Same as std::string_view::compare().
 
size_type copy (char *dest, size_type count, size_type pos=0) const
 Same as std::string_view::copy().
 
const_reverse_iterator crbegin () const noexcept
 Same as std::string_view::crbegin().
 
const_reverse_iterator crend () const noexcept
 Same as std::string_view::crend().
 
constexpr const_pointer data () const noexcept
 Same as std::string_view::data()
 
constexpr bool empty () const noexcept
 Same as std::string_view::empty()
 
constexpr iterator end () const noexcept
 Same as std::string_view::end().
 
size_type find (char c, size_type pos=0) const
 Same as std::string_view::find().
 
size_type find (const char *str, size_type pos, size_type count) const
 Same as std::string_view::find().
 
size_type find (const char *str, size_type pos=0) const
 Same as std::string_view::find().
 
size_type find (const StringView &str, size_type pos=0) const
 Same as std::string_view::find().
 
size_type find_first_not_of (char c, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_not_of>std::string_view::find_first_not_of.
 
size_type find_first_not_of (const char *str, size_type pos, size_type count)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_not_of>std::string_view::find_first_not_of.
 
size_type find_first_not_of (const char *str, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_not_of>std::string_view::find_first_not_of.
 
size_type find_first_not_of (const StringView &other, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_not_of>std::string_view::find_first_not_of.
 
size_type find_first_of (char c, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_of>std::string_view::find_first_of.
 
size_type find_first_of (const char *str, size_type pos, size_type count)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_of>std::string_view::find_first_of.
 
size_type find_first_of (const char *str, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_of>std::string_view::find_first_of.
 
size_type find_first_of (const StringView &other, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_first_of>std::string_view::find_first_of.
 
size_type find_last_not_of (char c, size_type pos=0)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_not_of>std::string_view::find_last_not_of.
 
size_type find_last_not_of (const char *str, size_type pos, size_type count)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_not_of>std::string_view::find_last_not_of.
 
size_type find_last_not_of (const char *str, size_type pos=npos)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_not_of>std::string_view::find_last_not_of.
 
size_type find_last_not_of (const StringView &other, size_type pos=npos)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_not_of>std::string_view::find_last_not_of.
 
size_type find_last_of (char c, size_type pos=npos)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_of>std::string_view::find_last_of.
 
size_type find_last_of (const char *str, size_type pos, size_type count)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_of>std::string_view::find_last_of.
 
size_type find_last_of (const char *str, size_type pos=npos)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_of>std::string_view::find_last_of.
 
size_type find_last_of (const StringView &other, size_type pos=npos)
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/find_last_of>std::string_view::find_last_of.
 
constexpr const_reference front () const
 Same as std::string_view::front()
 
constexpr size_type length () const noexcept
 Same as std::string_view::length()
 
template<std::size_t TN>
StringViewoperator= (char(&str)[TN])
 Assign array of characters with known size. More...
 
template<std::size_t TN>
StringViewoperator= (const char(&str)[TN])
 Assign array of characters with known size. More...
 
StringViewoperator= (const StringView &)=default
 Copy assign.
 
constexpr const_reference operator[] (size_type pos) const
 Same as std::string_view::oprator[]()
 
const_reverse_iterator rbegin () const noexcept
 Same as std::string_view::rbegin().
 
void remove_prefix (size_type n)
 Same as std::string_view::remove_prefix()
 
void remove_suffix (size_type n)
 Same as std::string_view::remove_suffix()
 
reverse_iterator rend () const noexcept
 Same as std::string_view::rend().
 
constexpr size_type size () const noexcept
 Same as std::string_view::size()
 
std::string substr (size_type pos=0, size_type count=npos) const
 Same as std::string_view::substr()
 
void swap (ArrayView &other) noexcept
 Swap contents of two views.
 
void swap (StringView &other) noexcept
 Same as <a href="http://en.cppreference.com/w/cpp/string/basic_string_view/swap>std::string_view::swap().
 

Static Public Attributes

static const auto npos = static_cast<SizeType>(-1)
 Special value, the meaning is the same as std::string_view::npos.
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Inequality compare between the views.
 
bool operator!= (const StringView &str1, const StringView &str2)
 Inequality compare between the string views. More...
 
bool operator< (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Lexicographical compare between the views.
 
bool operator< (const StringView &str1, const StringView &str2)
 Lexicographical compare between the string views. More...
 
bool operator<= (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Lexicographical compare between the views.
 
bool operator<= (const StringView &str1, const StringView &str2)
 Lexicographical compare between the string views. More...
 
bool operator== (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Equality compare between the views.
 
bool operator== (const StringView &str1, const StringView &str2)
 Equality compare between the string views. More...
 
bool operator> (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Lexicographical compare between the views.
 
bool operator> (const StringView &str1, const StringView &str2)
 Lexicographical compare between the string views. More...
 
bool operator>= (const ArrayView< char > &view1, const ArrayView< char > &view2) noexcept
 Lexicographical compare between the views.
 
bool operator>= (const StringView &str1, const StringView &str2)
 Lexicographical compare between the string views. More...
 
void swap (comms::util::ArrayView< char > &view1, comms::util::ArrayView< char > &view2)
 Specializes the std::swap algorithm.
 
void swap (comms::util::StringView &str1, comms::util::StringView &str2)
 Specializes the std::swap algorithm. More...
 

Constructor & Destructor Documentation

◆ StringView() [1/6]

comms::util::StringView::StringView ( )
defaultnoexcept

Default constructor.

See std::string_view constructor for details.

◆ StringView() [2/6]

comms::util::StringView::StringView ( const StringView )
defaultnoexcept

Copy constructor.

See std::string_view constructor for details.

◆ StringView() [3/6]

comms::util::StringView::StringView ( const char *  str,
size_type  len 
)
noexcept

Constructor.

See std::string_view constructor for details.

◆ StringView() [4/6]

comms::util::StringView::StringView ( const char *  str)
noexcept

Constructor.

See std::string_view constructor for details.

◆ StringView() [5/6]

template<std::size_t TN>
comms::util::StringView::StringView ( const char(&)  str[TN])
noexcept

Construct out of array of characters with known size.

Omits the last '\0' character if such exists

◆ StringView() [6/6]

template<std::size_t TN>
comms::util::StringView::StringView ( char(&)  str[TN])
noexcept

Construct out of array of characters with known size.

Omits the last '\0' character if such exists

Member Function Documentation

◆ at()

const_reference comms::util::StringView::at ( size_type  pos) const

Similar to std::string::at()

Checks the range with COMMS_ASSERT() macro without throwing exception.

◆ operator=() [1/2]

template<std::size_t TN>
StringView& comms::util::StringView::operator= ( char(&)  str[TN])

Assign array of characters with known size.

Omits the last '\0' character if such exists

◆ operator=() [2/2]

template<std::size_t TN>
StringView& comms::util::StringView::operator= ( const char(&)  str[TN])

Assign array of characters with known size.

Omits the last '\0' character if such exists

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const StringView str1,
const StringView str2 
)
related

Inequality compare between the string views.

See also
Reference

◆ operator<()

bool operator< ( const StringView str1,
const StringView str2 
)
related

Lexicographical compare between the string views.

See also
Reference

◆ operator<=()

bool operator<= ( const StringView str1,
const StringView str2 
)
related

Lexicographical compare between the string views.

See also
Reference

◆ operator==()

bool operator== ( const StringView str1,
const StringView str2 
)
related

Equality compare between the string views.

See also
Reference

◆ operator>()

bool operator> ( const StringView str1,
const StringView str2 
)
related

Lexicographical compare between the string views.

See also
Reference

◆ operator>=()

bool operator>= ( const StringView str1,
const StringView str2 
)
related

Lexicographical compare between the string views.

See also
Reference

◆ swap()

void swap ( comms::util::StringView str1,
comms::util::StringView str2 
)
related

Specializes the std::swap algorithm.

See also
Reference

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