Thrill  0.1

Detailed Description

StringView is a reference to a part of a string, consisting of only a char pointer and a length.

It does not have ownership of the substring and is used mainly for temporary objects.

Definition at line 32 of file string_view.hpp.

#include <string_view.hpp>

Public Types

using iterator = const char *
 

Public Member Functions

 StringView ()=default
 Default constructor for a StringView. Doesn't initialize anything. More...
 
 StringView (const char *data, size_t size) noexcept
 Creates a new StringView, given a const char* and the size. More...
 
 StringView (const std::string::const_iterator &data, size_t size) noexcept
 Creates a new StringView, given a const iterator to a std::string and the size. More...
 
 StringView (const std::string::const_iterator &begin, const std::string::const_iterator &end) noexcept
 Creates a new reference StringView, given two const iterators to a std::string. More...
 
 StringView (const std::string &str) noexcept
 Construct a StringView to the whole std::string. More...
 
iterator begin () const noexcept
 Returns a pointer to the beginning of the data. More...
 
const char * data () const noexcept
 Returns a pointer to the start of the data. More...
 
iterator end () const noexcept
 Returns a pointer beyond the end of the data. More...
 
bool operator!= (const StringView &other) const noexcept
 Inequality operator to compare a StringView with another StringView. More...
 
bool operator!= (const std::string &other) const noexcept
 Inequality operator to compare a StringView with a std::string. More...
 
bool operator< (const StringView &other) const noexcept
 
bool operator< (const std::string &other) const noexcept
 
bool operator== (const StringView &other) const noexcept
 Equality operator to compare a StringView with another StringView. More...
 
bool operator== (const std::string &other) const noexcept
 Equality operator to compare a StringView with a std::string. More...
 
size_t size () const noexcept
 Returns the size of this StringView. More...
 
std::string to_string () const
 Returns the data of this StringView as a std::string. More...
 

Private Attributes

const char * data_
 pointer to character data More...
 
size_t size_
 size of data More...
 

Friends

std::ostream & operator<< (std::ostream &os, const StringView &sv)
 make StringView ostreamable More...
 

Member Typedef Documentation

◆ iterator

using iterator = const char*

Definition at line 35 of file string_view.hpp.

Constructor & Destructor Documentation

◆ StringView() [1/5]

StringView ( )
default

Default constructor for a StringView. Doesn't initialize anything.

◆ StringView() [2/5]

StringView ( const char *  data,
size_t  size 
)
inlinenoexcept

Creates a new StringView, given a const char* and the size.

Parameters
datapointer to start of data
sizesize of data in bytes.
Returns
new StringView object.

Definition at line 47 of file string_view.hpp.

◆ StringView() [3/5]

StringView ( const std::string::const_iterator &  data,
size_t  size 
)
inlinenoexcept

Creates a new StringView, given a const iterator to a std::string and the size.

Parameters
dataiterator to start of data
sizesize of data in character.
Returns
new StringView object.

Definition at line 58 of file string_view.hpp.

◆ StringView() [4/5]

StringView ( const std::string::const_iterator &  begin,
const std::string::const_iterator &  end 
)
inlinenoexcept

Creates a new reference StringView, given two const iterators to a std::string.

Parameters
beginiterator to start of data
enditerator to the end of data.
Returns
new StringView object.

Definition at line 69 of file string_view.hpp.

◆ StringView() [5/5]

StringView ( const std::string &  str)
inlineexplicitnoexcept

Construct a StringView to the whole std::string.

Definition at line 74 of file string_view.hpp.

Member Function Documentation

◆ begin()

iterator begin ( ) const
inlinenoexcept

Returns a pointer to the beginning of the data.

Definition at line 83 of file string_view.hpp.

References StringView::data_.

◆ data()

const char* data ( ) const
inlinenoexcept

Returns a pointer to the start of the data.

Definition at line 78 of file string_view.hpp.

References StringView::data_.

Referenced by hash< tlx::StringView >::operator()().

◆ end()

iterator end ( ) const
inlinenoexcept

Returns a pointer beyond the end of the data.

Definition at line 88 of file string_view.hpp.

References StringView::data_, and StringView::size_.

◆ operator!=() [1/2]

bool operator!= ( const StringView other) const
inlinenoexcept

Inequality operator to compare a StringView with another StringView.

Definition at line 104 of file string_view.hpp.

References StringView::operator==().

◆ operator!=() [2/2]

bool operator!= ( const std::string &  other) const
inlinenoexcept

Inequality operator to compare a StringView with a std::string.

Definition at line 122 of file string_view.hpp.

References StringView::operator==().

◆ operator<() [1/2]

bool operator< ( const StringView other) const
inlinenoexcept

Less operator to compare a StringView with another StringView lexicographically

Definition at line 110 of file string_view.hpp.

References StringView::data_, and StringView::size_.

◆ operator<() [2/2]

bool operator< ( const std::string &  other) const
inlinenoexcept

Less operator to compare a StringView with a std::string lexicographically

Definition at line 128 of file string_view.hpp.

References StringView::data_, and StringView::size_.

◆ operator==() [1/2]

bool operator== ( const StringView other) const
inlinenoexcept

Equality operator to compare a StringView with another StringView.

Definition at line 98 of file string_view.hpp.

References StringView::data_, and StringView::size_.

Referenced by StringView::operator!=().

◆ operator==() [2/2]

bool operator== ( const std::string &  other) const
inlinenoexcept

Equality operator to compare a StringView with a std::string.

Definition at line 116 of file string_view.hpp.

References StringView::data_, and StringView::size_.

◆ size()

size_t size ( ) const
inlinenoexcept

◆ to_string()

std::string to_string ( ) const
inline

Returns the data of this StringView as a std::string.

Definition at line 139 of file string_view.hpp.

References StringView::data_, and StringView::size_.

Referenced by examples::word_count::HashWordCountExample(), main(), WordCount(), and examples::word_count::WordCount().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const StringView sv 
)
friend

make StringView ostreamable

Definition at line 134 of file string_view.hpp.

Member Data Documentation

◆ data_

const char* data_
private

◆ size_

size_t size_
private

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