![]() |
P4C
The P4 Compiler
|
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::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 (const cstring &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 | |
| bool | operator!= (const char *a) const |
| bool | operator!= (const std::string &a) const |
| bool | operator!= (cstring 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> (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 (cstring find, cstring replace) const |
| size_t | size () const |
| bool | startsWith (const cstring &prefix) 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) |
| 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("") |
| static cstring | newline = cstring("\n") |
A cstring is a reference to a zero-terminated, immutable, interned string. The cstring object itself is not immutable; you can reassign it as required, and it provides a mutable interface that copies the underlying immutable string as needed.
Compared to std::string, these are the benefits that cstring provides:
On the other hand, these are the disadvantages of using cstring:
Given these tradeoffs, the general rule of thumb to follow is that you should try to convert strings to cstrings early and keep them in that form. That way, you benefit from cheaper copying, assignment, and equality testing in as many places as possible, and you avoid paying the cost of repeated conversion.
However, when you're building or mutating a string, you should use std::string. Convert to a cstring only when the string is in its final form. This ensures that you don't pay the time and space cost of interning every intermediate version of the string.
Note that cstring has implicit conversions to and from other string types. This is convenient, but in performance-sensitive code it's good to be aware that mixing the two types of strings can trigger a lot of implicit copies.
|
static |
| cstring cstring::escapeJson | ( | ) | const |