P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::cstring Class Reference

Public Member Functions

 cstring (const char *string)
 
 cstring (const char *string, std::size_t length)
 
 cstring (const std::string &string)
 
 cstring (const std::stringstream &stream)
 
template<typename Iter >
 cstring (Iter begin, Iter end)
 
 cstring (std::nullptr_t)
 
 cstring (std::string_view string)
 
cstring before (const char *at) const
 
const char * begin () const
 
const char * c_str () const
 
cstring capitalize () const
 Capitalize the first symbol.
 
const char * end () const
 
bool endsWith (std::string_view suffix) const
 
cstring escapeJson () const
 
cstring exceptLast (size_t count)
 
const char * find (const char *s) const
 
const char * find (int c) const
 
const char * findlast (int c) const
 
char get (unsigned index) const
 
cstring indent (size_t amount) const
 Append this many spaces after each newline (and before the first string).
 
bool isNull () const
 
bool isNullOrEmpty () const
 
 operator const char * () const
 
 operator std::string () const
 
 operator std::string_view () const
 
bool operator!= (const char *a) const
 
bool operator!= (const std::string &a) const
 
bool operator!= (cstring a) const
 
bool operator!= (std::nullptr_t) const
 
bool operator!= (std::string_view a) const
 
cstring operator+= (char a)
 
cstring operator+= (const char *a)
 
cstring operator+= (cstring a)
 
cstring operator+= (std::string a)
 
bool operator< (const char *a) const
 
bool operator< (const std::string &a) const
 
bool operator< (cstring a) const
 
bool operator<= (const char *a) const
 
bool operator<= (const std::string &a) const
 
bool operator<= (cstring a) const
 
bool operator== (const char *a) const
 
bool operator== (const std::string &a) const
 
bool operator== (cstring a) const
 
bool operator== (std::nullptr_t) const
 
bool operator== (std::string_view a) const
 
bool operator> (const char *a) const
 
bool operator> (const std::string &a) const
 
bool operator> (cstring a) const
 
bool operator>= (const char *a) const
 
bool operator>= (const std::string &a) const
 
bool operator>= (cstring a) const
 
cstring replace (char find, char replace) const
 
cstring replace (std::string_view find, std::string_view replace) const
 
size_t size () const
 
bool startsWith (std::string_view prefix) const
 
std::string string () const
 
std::string_view string_view () const
 
cstring substr (size_t start) const
 
cstring substr (size_t start, size_t length) const
 
cstring toLower () const
 Convert the cstring to lowercase.
 
cstring toUpper () const
 Convert the cstring to uppercase.
 
cstring trim (const char *ws=" \t\r\n") const
 

Static Public Member Functions

static size_t cache_size (size_t &count)
 
static cstring get_cached (std::string_view s)
 
static bool is_cached (std::string_view s)
 
template<typename Iterator >
static cstring join (Iterator begin, Iterator end, const char *delim=", ")
 
template<typename T , std::size_t N, typename = typename std::enable_if<std::is_same<T, const char>::value>::type>
static cstring literal (T(&string)[N])
 
template<class T >
static cstring make_unique (const T &inuse, cstring base, char sep='.')
 
template<class T >
static cstring make_unique (const T &inuse, cstring base, int &counter, char sep='.')
 
static cstring own (const char *string, std::size_t length)
 
template<typename T >
static cstring to_cstring (const T &t)
 

Static Public Attributes

static cstring empty = cstring::literal("")
 
static cstring newline = cstring::literal("\n")
 

Friends

cstring P4::literals::operator""_cs (const char *str, std::size_t len)
 

Member Function Documentation

◆ cache_size()

size_t P4::cstring::cache_size ( size_t & count)
static
Returns
the total size in bytes of all interned strings. @count is set to the total number of interned strings.

◆ escapeJson()

cstring P4::cstring::escapeJson ( ) const
Returns
a version of the string where all necessary characters are properly escaped to make this into a json string (without the enclosing quotes).

◆ get_cached()

cstring P4::cstring::get_cached ( std::string_view s)
static
Returns
corresponding cstring if it was interned, null cstring otherwise

◆ is_cached()

bool P4::cstring::is_cached ( std::string_view s)
static
Returns
true if a given string is interned (contained in cstring cache)