DLPrimitives
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
dlprim::json::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 <include/dlprim/json.hpp>

Public Types

typedef char const * const_iterator
 Iterator type.
 

Public Member Functions

 string_key ()
 Default constructor - empty key.
 
 string_key (char const *key)
 Create a new string copying the key.
 
 string_key (std::string const &key)
 Create a new string copying the key.
 
size_t size () const
 String size in bytes.
 
size_t length () const
 Same as size()
 
void clear ()
 Clear the string.
 
bool empty () const
 Check if the string is empty.
 
size_t find (char c, size_t pos=0) const
 Find first occurrence of a character in the string starting from position pos. Returns npos if not character found.
 
string_key substr (size_t pos=0, size_t n=npos) const
 Create a substring from this string starting from character pos of size at most n.
 
string_key unowned_substr (size_t pos=0, size_t n=npos) const
 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.
 
char const & operator[] (size_t n) const
 Get a character at position n.
 
char const & at (size_t n) const
 Get a character at position n, if n is not valid position, throws std::out_of_range exception.
 
char const * begin () const
 Get a pointer to the first character in the string.
 
char const * end () const
 Get a pointer to the one past last character in the string.
 
bool operator< (string_key const &other) const
 Compare two strings.
 
bool operator> (string_key const &other) const
 Compare two strings.
 
bool operator>= (string_key const &other) const
 Compare two strings.
 
bool operator<= (string_key const &other) const
 Compare two strings.
 
bool operator== (string_key const &other) const
 Compare two strings.
 
bool operator!= (string_key const &other) const
 Compare two strings.
 
char const * data () const
 Get the pointer to the first character in the string. Note it should not be NUL terminated.
 
std::string str () const
 Create std::string from the key.
 
 operator std::string () const
 Convert the key to the std::string.
 

Static Public Member Functions

static string_key unowned (std::string const &v)
 Create a string from v without copying the memory. v should remain valid as long as this object is used.
 
static string_key unowned (char const *str)
 Create a string from str without copying the memory. str should remain valid as long as this object is used.
 
static string_key unowned (char const *begin, char const *end)
 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.
 

Static Public Attributes

static const size_t npos = -1
 The last position of the character in the string.
 

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().


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