81    const char *str = 
nullptr;
 
   93    cstring(
const char *
string, std::size_t length) {  
 
   94        if (
string != 
nullptr) {
 
   95            construct_from_shared(
string, length);
 
  102    explicit cstring(
const char *
string) {
 
  103        if (
string != 
nullptr) {
 
  104            construct_from_shared(
string, std::strlen(
string));
 
  110    cstring(
const std::string &
string) {  
 
  111        construct_from_shared(
string.data(), 
string.length());
 
  116    explicit cstring(std::string_view 
string) {  
 
  117        construct_from_shared(
string.data(), 
string.length());
 
  125    cstring(
const std::stringstream &stream)  
 
  132    static cstring own(
const char *
string, std::size_t length) {
 
  133        if (
string == 
nullptr) {
 
  138        result.construct_from_unique(
string, length);
 
  143    template <
typename T, std::size_t N,
 
  144              typename = 
typename std::enable_if<std::is_same<T, const char>::value>::type>
 
  145    static cstring literal(T (&
string)[N]) {  
 
  147        result.construct_from_literal(
string, N - 1 );
 
  152    static bool is_cached(std::string_view s);
 
  158    void construct_from_shared(
const char *
string, std::size_t length);
 
  161    void construct_from_unique(
const char *
string, std::size_t length);
 
  164    void construct_from_literal(
const char *
string, std::size_t length);
 
  166    friend cstring P4::literals::operator
""_cs(
const char *str, std::size_t len);
 
  174    template <
typename Iter>
 
  175    cstring(Iter begin, Iter end) {
 
  176        *
this = std::string(begin, end);
 
  179    char get(
unsigned index)
 const { 
return (index < size()) ? str[index] : 0; }
 
  180    const char *c_str()
 const { 
return str; }
 
  181    operator const char *() 
const { 
return str; }
 
  183    std::string string()
 const { 
return str ? std::string(str) : std::string(
""); }
 
  184    explicit operator std::string()
 const { 
return string(); }
 
  186    std::string_view string_view()
 const {
 
  187        return str ? std::string_view(str) : std::string_view(
"");
 
  189    explicit operator std::string_view()
 const { 
return string_view(); }
 
  192    size_t size()
 const {
 
  196        return str ? strlen(str) : 0;
 
  198    bool isNull()
 const { 
return str == 
nullptr; }
 
  199    bool isNullOrEmpty()
 const { 
return str == 
nullptr ? true : str[0] == 0; }
 
  202    const char *begin()
 const { 
return str; }
 
  203    const char *end()
 const { 
return str ? str + strlen(str) : str; }
 
  206    const char *find(
int c)
 const { 
return str ? strchr(str, c) : 
nullptr; }
 
  207    const char *findlast(
int c)
 const { 
return str ? strrchr(str, c) : str; }
 
  210    const char *find(
const char *s)
 const { 
return str ? strstr(str, s) : 
nullptr; }
 
  213    bool operator==(
cstring a)
 const { 
return str == a.str; }
 
  214    bool operator!=(
cstring a)
 const { 
return str != a.str; }
 
  216    bool operator==(std::nullptr_t)
 const { 
return str == 
nullptr; }
 
  217    bool operator!=(std::nullptr_t)
 const { 
return str != 
nullptr; }
 
  220    bool operator==(
const char *a)
 const { 
return str ? a && !strcmp(str, a) : !a; }
 
  221    bool operator!=(
const char *a)
 const { 
return str ? !a || !!strcmp(str, a) : !!a; }
 
  222    bool operator<(
cstring a)
 const { 
return *
this < a.str; }
 
  223    bool operator<(
const char *a)
 const { 
return str ? a && strcmp(str, a) < 0 : !!a; }
 
  224    bool operator<=(
cstring a)
 const { 
return *
this <= a.str; }
 
  225    bool operator<=(
const char *a)
 const { 
return str ? a && strcmp(str, a) <= 0 : 
true; }
 
  226    bool operator>(
cstring a)
 const { 
return *
this > a.str; }
 
  227    bool operator>(
const char *a)
 const { 
return str ? !a || strcmp(str, a) > 0 : 
false; }
 
  228    bool operator>=(
cstring a)
 const { 
return *
this >= a.str; }
 
  229    bool operator>=(
const char *a)
 const { 
return str ? !a || strcmp(str, a) >= 0 : !a; }
 
  230    bool operator==(std::string_view a)
 const { 
return str ? a.compare(str) == 0 : a.empty(); }
 
  231    bool operator!=(std::string_view a)
 const { 
return str ? a.compare(str) != 0 : !a.empty(); }
 
  233    bool operator==(
const std::string &a)
 const { 
return *
this == a.c_str(); }
 
  234    bool operator!=(
const std::string &a)
 const { 
return *
this != a.c_str(); }
 
  235    bool operator<(
const std::string &a)
 const { 
return *
this < a.c_str(); }
 
  236    bool operator<=(
const std::string &a)
 const { 
return *
this <= a.c_str(); }
 
  237    bool operator>(
const std::string &a)
 const { 
return *
this > a.c_str(); }
 
  238    bool operator>=(
const std::string &a)
 const { 
return *
this >= a.c_str(); }
 
  240    bool startsWith(std::string_view prefix) 
const;
 
  241    bool endsWith(std::string_view suffix) 
const;
 
  252    cstring operator+=(
const char *a);
 
  253    cstring operator+=(std::string a);
 
  256    cstring before(
const char *at) 
const;
 
  257    cstring substr(
size_t start)
 const {
 
  258        return (start >= size()) ? cstring::literal(
"") : substr(start, size() - start);
 
  260    cstring substr(
size_t start, 
size_t length) 
const;
 
  261    cstring replace(
char find, 
char replace) 
const;
 
  262    cstring replace(std::string_view find, std::string_view replace) 
const;
 
  263    cstring exceptLast(
size_t count) { 
return substr(0, size() - count); }
 
  266    cstring trim(
const char *ws = 
" \t\r\n") 
const;
 
  273    template <
typename T>
 
  274    static cstring to_cstring(
const T &t) {
 
  275        std::stringstream ss;
 
  279    template <
typename Iterator>
 
  280    static cstring join(Iterator begin, Iterator end, 
const char *delim = 
", ") {
 
  281        std::stringstream ss;
 
  282        for (
auto current = begin; current != end; ++current) {
 
  283            if (begin != current) ss << delim;
 
  289    static cstring make_unique(
const T &inuse, 
cstring base, 
char sep = 
'.');
 
  291    static cstring make_unique(
const T &inuse, 
cstring base, 
int &counter, 
char sep = 
'.');
 
 
  385    return make_unique(inuse, base, counter, sep);
 
cstring indent(size_t amount) const
Append this many spaces after each newline (and before the first string).
Definition cstring.cpp:262