CppCMS
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
cppcms::string_key Class Reference

This is a special object that may hold an std::string or alternatively reference to external (unowned) chunk of text. More...

#include <cppcms/string_key.h>

Public Types

typedef char const * const_iterator
 

Public Member Functions

 string_key ()
 
 string_key (char const *key)
 
 string_key (std::string const &key)
 
size_t size () const
 
size_t length () const
 
void clear ()
 
bool empty () const
 
size_t find (char c, size_t pos=0) const
 
string_key substr (size_t pos=0, size_t n=npos) const
 
string_key unowned_substr (size_t pos=0, size_t n=npos) const
 
char const & operator[] (size_t n) const
 
char const & at (size_t n) const
 
char const * begin () const
 
char const * end () const
 
bool operator< (string_key const &other) const
 
bool operator> (string_key const &other) const
 
bool operator>= (string_key const &other) const
 
bool operator<= (string_key const &other) const
 
bool operator== (string_key const &other) const
 
bool operator!= (string_key const &other) const
 
char const * data () const
 
std::string str () const
 
 operator std::string () const
 

Static Public Member Functions

static string_key unowned (std::string const &v)
 
static string_key unowned (char const *str)
 
static string_key unowned (char const *begin, char const *end)
 

Static Public Attributes

static const size_t npos = -1
 

Detailed Description

This is a special object that may hold an std::string or alternatively reference to external (unowned) chunk of text.

It is designed to be used for efficiency and reduce amount of memory allocations and copies.

It has interface that is roughly similar to the interface of std::string, but it does not provide a members that can mutate it or provide a NUL terminated string c_str().

Member Typedef Documentation

Iterator type

Constructor & Destructor Documentation

cppcms::string_key::string_key ( )
inline

Default constructor - empty key

Referenced by operator std::string(), substr(), unowned(), and unowned_substr().

cppcms::string_key::string_key ( char const *  key)
inline

Create a new string copying the key

cppcms::string_key::string_key ( std::string const &  key)
inline

Create a new string copying the key

Member Function Documentation

char const& cppcms::string_key::at ( size_t  n) const
inline

Get a character at position n, if n is not valid position, throws std::out_of_range exception

References begin(), and size().

char const* cppcms::string_key::begin ( ) const
inline

Get a pointer to the first character in the string

Referenced by at(), data(), empty(), find(), operator<(), operator==(), operator[](), size(), substr(), and unowned_substr().

void cppcms::string_key::clear ( )
inline

Clear the string

char const* cppcms::string_key::data ( ) const
inline

Get the pointer to the first character in the string. Note it should not be NUL terminated

References begin().

Referenced by cppcms::operator<<().

bool cppcms::string_key::empty ( ) const
inline

Check if the string is empty

References begin(), and end().

char const* cppcms::string_key::end ( ) const
inline

Get a pointer to the one past last character in the string

Referenced by empty(), operator<(), operator==(), size(), substr(), unowned(), and unowned_substr().

size_t cppcms::string_key::find ( char  c,
size_t  pos = 0 
) const
inline

Find first occurrence of a character in the string starting from position pos. Returns npos if not character found.

References begin(), npos, and size().

size_t cppcms::string_key::length ( ) const
inline

Same as size()

References size().

cppcms::string_key::operator std::string ( ) const
inline

Convert the key to the std::string

References str(), and string_key().

bool cppcms::string_key::operator!= ( string_key const &  other) const
inline

Compare two strings

bool cppcms::string_key::operator< ( string_key const &  other) const
inline

Compare two strings

References begin(), and end().

bool cppcms::string_key::operator<= ( string_key const &  other) const
inline

Compare two strings

bool cppcms::string_key::operator== ( string_key const &  other) const
inline

Compare two strings

References begin(), and end().

bool cppcms::string_key::operator> ( string_key const &  other) const
inline

Compare two strings

bool cppcms::string_key::operator>= ( string_key const &  other) const
inline

Compare two strings

char const& cppcms::string_key::operator[] ( size_t  n) const
inline

Get a character at position n

References begin().

size_t cppcms::string_key::size ( ) const
inline

String size in bytes

References begin(), and end().

Referenced by at(), find(), length(), cppcms::operator<<(), and unowned_substr().

std::string cppcms::string_key::str ( ) const
inline

Create std::string from the key

Referenced by operator std::string(), and unowned().

string_key cppcms::string_key::substr ( size_t  pos = 0,
size_t  n = npos 
) const
inline

Create a substring from this string starting from character pos of size at most n

References begin(), end(), string_key(), and unowned_substr().

static string_key cppcms::string_key::unowned ( std::string const &  v)
inlinestatic

Create a string from v without copying the memory. v should remain valid as long as this object is used

References string_key().

Referenced by cppcms::operator!=(), cppcms::operator<(), cppcms::operator<=(), cppcms::operator==(), cppcms::operator>(), and cppcms::operator>=().

static string_key cppcms::string_key::unowned ( char const *  str)
inlinestatic

Create a string from str without copying the memory. str should remain valid as long as this object is used

References end(), str(), and string_key().

static string_key cppcms::string_key::unowned ( char const *  begin,
char const *  end 
)
inlinestatic

Create a string from characters at rang [begin,end) without copying the memory. The range should remain valid as long as this object is used

References string_key().

string_key cppcms::string_key::unowned_substr ( size_t  pos = 0,
size_t  n = npos 
) const
inline

Create a substring from this string starting from character pos of size at most n such that the memory is not copied but only reference by the created substring

References begin(), end(), size(), and string_key().

Referenced by substr().

Member Data Documentation

const size_t cppcms::string_key::npos = -1
static

The last position of the character in the string

Referenced by find().


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