openMSX
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
zstring_view Class Reference

Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string. More...

#include <zstring_view.hh>

Public Types

using size_type = size_t
 
using const_iterator = const char *
 

Public Member Functions

constexpr zstring_view ()
 
constexpr zstring_view (const char *s)
 
constexpr zstring_view (const char *s, size_t n)
 
 zstring_view (const std::string &s)
 
constexpr auto begin () const
 
constexpr auto end () const
 
constexpr auto size () const
 
constexpr auto empty () const
 
constexpr char operator[] (size_type i) const
 
constexpr char front () const
 
constexpr char back () const
 
constexpr const char * data () const
 
constexpr const char * c_str () const
 
constexpr auto find (char c, size_type pos=0) const
 
constexpr auto find (const char *s, size_type pos=0) const
 
constexpr zstring_view substr (size_type pos) const
 
constexpr std::string_view substr (size_type pos, size_type count) const
 
constexpr bool starts_with (std::string_view sv) const
 
constexpr bool starts_with (char c) const
 
constexpr bool starts_with (const char *s) const
 
constexpr bool ends_with (std::string_view sv) const
 
constexpr bool ends_with (char c) const
 
constexpr bool ends_with (const char *s) const
 
 operator std::string () const
 
constexpr std::string_view view () const
 
 explicit (false) const expr operator std
 

Static Public Attributes

static constexpr auto npos = std::string_view::npos
 

Friends

bool operator== (const zstring_view &x, const std::string &y)
 
constexpr friend bool operator== (const zstring_view &x, const std::string_view &y)
 
constexpr friend bool operator== (const zstring_view &x, const char *y)
 
std::ostream & operator<< (std::ostream &os, const zstring_view &str)
 

Detailed Description

Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.

In other words it has this additional invariant: data()[size()] == '\0'

Current version only implements a subset of the std::string_view API. That is because:

Definition at line 21 of file zstring_view.hh.

Member Typedef Documentation

◆ const_iterator

using zstring_view::const_iterator = const char*

Definition at line 25 of file zstring_view.hh.

◆ size_type

using zstring_view::size_type = size_t

Definition at line 24 of file zstring_view.hh.

Constructor & Destructor Documentation

◆ zstring_view() [1/4]

constexpr zstring_view::zstring_view ( )
inlineconstexpr

Definition at line 29 of file zstring_view.hh.

◆ zstring_view() [2/4]

constexpr zstring_view::zstring_view ( const char *  s)
inlineconstexpr

Definition at line 31 of file zstring_view.hh.

◆ zstring_view() [3/4]

constexpr zstring_view::zstring_view ( const char *  s,
size_t  n 
)
inlineconstexpr

Definition at line 33 of file zstring_view.hh.

◆ zstring_view() [4/4]

zstring_view::zstring_view ( const std::string &  s)
inline

Definition at line 35 of file zstring_view.hh.

Member Function Documentation

◆ back()

constexpr char zstring_view::back ( ) const
inlineconstexpr

Definition at line 49 of file zstring_view.hh.

◆ begin()

constexpr auto zstring_view::begin ( ) const
inlineconstexpr

Definition at line 38 of file zstring_view.hh.

Referenced by begin().

◆ c_str()

constexpr const char * zstring_view::c_str ( ) const
inlineconstexpr

◆ data()

constexpr const char * zstring_view::data ( ) const
inlineconstexpr

◆ empty()

constexpr auto zstring_view::empty ( ) const
inlineconstexpr

Definition at line 42 of file zstring_view.hh.

Referenced by openmsx::ImGuiTrainer::paint().

◆ end()

constexpr auto zstring_view::end ( ) const
inlineconstexpr

Definition at line 39 of file zstring_view.hh.

Referenced by end().

◆ ends_with() [1/3]

constexpr bool zstring_view::ends_with ( char  c) const
inlineconstexpr

Definition at line 81 of file zstring_view.hh.

References view().

◆ ends_with() [2/3]

constexpr bool zstring_view::ends_with ( const char *  s) const
inlineconstexpr

Definition at line 84 of file zstring_view.hh.

References view().

◆ ends_with() [3/3]

constexpr bool zstring_view::ends_with ( std::string_view  sv) const
inlineconstexpr

Definition at line 78 of file zstring_view.hh.

References view().

Referenced by openmsx::FileOperations::mkdir().

◆ explicit()

zstring_view::explicit ( false  ) const
inline

Definition at line 94 of file zstring_view.hh.

References view().

◆ find() [1/2]

constexpr auto zstring_view::find ( char  c,
size_type  pos = 0 
) const
inlineconstexpr

Definition at line 53 of file zstring_view.hh.

References view().

Referenced by openmsx::XMLDocumentHandler::doctype(), and openmsx::FileOperations::openFile().

◆ find() [2/2]

constexpr auto zstring_view::find ( const char *  s,
size_type  pos = 0 
) const
inlineconstexpr

Definition at line 56 of file zstring_view.hh.

References view().

◆ front()

constexpr char zstring_view::front ( ) const
inlineconstexpr

Definition at line 48 of file zstring_view.hh.

◆ operator std::string()

zstring_view::operator std::string ( ) const
inlineexplicit

Definition at line 88 of file zstring_view.hh.

◆ operator[]()

constexpr char zstring_view::operator[] ( size_type  i) const
inlineconstexpr

Definition at line 44 of file zstring_view.hh.

◆ size()

constexpr auto zstring_view::size ( ) const
inlineconstexpr

◆ starts_with() [1/3]

constexpr bool zstring_view::starts_with ( char  c) const
inlineconstexpr

Definition at line 72 of file zstring_view.hh.

References view().

◆ starts_with() [2/3]

constexpr bool zstring_view::starts_with ( const char *  s) const
inlineconstexpr

Definition at line 75 of file zstring_view.hh.

References view().

◆ starts_with() [3/3]

constexpr bool zstring_view::starts_with ( std::string_view  sv) const
inlineconstexpr

Definition at line 69 of file zstring_view.hh.

References view().

◆ substr() [1/2]

constexpr zstring_view zstring_view::substr ( size_type  pos) const
inlineconstexpr

Definition at line 60 of file zstring_view.hh.

Referenced by openmsx::XMLDocumentHandler::doctype().

◆ substr() [2/2]

constexpr std::string_view zstring_view::substr ( size_type  pos,
size_type  count 
) const
inlineconstexpr

Definition at line 64 of file zstring_view.hh.

References view().

◆ view()

constexpr std::string_view zstring_view::view ( ) const
inlineconstexpr

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const zstring_view str 
)
friend

Definition at line 111 of file zstring_view.hh.

◆ operator== [1/3]

constexpr friend bool operator== ( const zstring_view x,
const char *  y 
)
friend

Definition at line 107 of file zstring_view.hh.

◆ operator== [2/3]

bool operator== ( const zstring_view x,
const std::string &  y 
)
friend

Definition at line 101 of file zstring_view.hh.

◆ operator== [3/3]

constexpr friend bool operator== ( const zstring_view x,
const std::string_view &  y 
)
friend

Definition at line 104 of file zstring_view.hh.

Member Data Documentation

◆ npos

constexpr auto zstring_view::npos = std::string_view::npos
staticconstexpr

Definition at line 27 of file zstring_view.hh.


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