1 #ifndef WREPORT_STRING_H 2 #define WREPORT_STRING_H 19 inline bool startswith(
const std::string& str,
const std::string& part)
21 if (str.size() < part.size())
23 return str.substr(0, part.size()) == part;
27 inline bool endswith(
const std::string& str,
const std::string& part)
29 if (str.size() < part.size())
31 return str.substr(str.size() - part.size()) == part;
37 template <
typename ITER>
38 std::string
join(
const std::string& sep,
const ITER& begin,
const ITER& end)
40 std::stringstream res;
42 for (ITER i = begin; i != end; ++i)
56 template <
typename ITEMS>
57 std::string
join(
const std::string& sep,
const ITEMS& items)
59 std::stringstream res;
61 for (
const auto& i : items)
75 std::string
lstrip(
const std::string& str);
80 std::string
rstrip(
const std::string& str);
85 std::string
strip(
const std::string& str);
88 inline std::string
upper(
const std::string& str)
91 res.reserve(str.size());
92 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
93 res += static_cast<char>(std::toupper(static_cast<unsigned char>(*i)));
98 inline std::string
lower(
const std::string& str)
101 res.reserve(str.size());
102 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
103 res += static_cast<char>(std::tolower(static_cast<unsigned char>(*i)));
108 [[deprecated(
"Use path.filename")]] std::string
109 basename(
const std::string& pathname);
112 [[deprecated(
"Use path.parent_path")]] std::string
113 dirname(
const std::string& pathname);
116 [[deprecated(
"Use path / path")]]
void appendpath(std::string& dest,
120 [[deprecated(
"Use path / path")]]
void appendpath(std::string& dest,
121 const std::string& path2);
124 template <
typename S1,
typename S2,
typename... Args>
125 [[deprecated(
"Use path / path")]]
void appendpath(std::string& dest, S1 first,
126 S2 second, Args... next)
128 #pragma GCC diagnostic push 129 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 132 #pragma GCC diagnostic pop 136 template <
typename... Args>
137 [[deprecated(
"Use path / path")]] std::string
joinpath(Args... components)
139 #pragma GCC diagnostic push 140 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 144 #pragma GCC diagnostic pop 153 "use path::lexically_normal or std::filesystem::canonical")]] std::string
154 normpath(
const std::string& pathname);
180 Split(
const std::string& str_,
const std::string& sep_,
181 bool skip_empty_ =
false)
189 const Split* split =
nullptr;
200 using iterator_category = std::input_iterator_tag;
201 using value_type = std::string;
202 using difference_type = int;
203 using pointer = std::string*;
204 using reference = std::string&;
214 const std::string& operator*()
const;
215 const std::string* operator->()
const;
217 std::string remainder()
const;
243 std::string
decode_cstring(
const std::string& str,
size_t& lenParsed);
246 std::string
encode_url(
const std::string& str);
249 std::string
decode_url(
const std::string& str);
void skip_separators()
Move end past all the consecutive separators that start at its position.
std::string rstrip(const std::string &str)
Return the substring of 'str' without all trailing spaces.
std::string dirname(const std::string &pathname)
Given a pathname, return the directory name without the file name.
std::string strip(const std::string &str)
Return the substring of 'str' without all leading and trailing spaces.
bool skip_empty
If true, skip empty tokens, effectively grouping consecutive separators as if they were a single one...
Definition: string.h:178
std::string basename(const std::string &pathname)
Given a pathname, return the file name without its path.
const_iterator begin()
Return the begin iterator to split a string on instances of sep.
Definition: string.h:225
std::string normpath(const std::string &pathname)
Normalise a pathname.
void appendpath(std::string &dest, const char *path2)
Append path2 to path1, adding slashes when appropriate.
std::string decode_base64(const std::string &str)
Decode a string encoded in Base64.
Split a string where a given substring is found.
Definition: string.h:168
std::string joinpath(Args... components)
Join two or more paths, adding slashes when appropriate.
Definition: string.h:137
std::string encode_url(const std::string &str)
Urlencode a string.
size_t end
Position of the first character of the next token.
Definition: string.h:193
std::string lstrip(const std::string &str)
Return the substring of 'str' without all leading spaces.
bool endswith(const std::string &str, const std::string &part)
Check if a string ends with the given substring.
Definition: string.h:27
std::string encode_cstring(const std::string &str)
Escape the string so it can safely used as a C string inside double quotes.
String functions.
Definition: string.h:16
std::string encode_base64(const std::string &str)
Encode a string in Base64.
std::string sep
Separator.
Definition: string.h:173
const_iterator end()
Return the end iterator to string split.
Definition: string.h:228
const_iterator()
End iterator.
Definition: string.h:209
std::string cur
Current token.
Definition: string.h:191
std::string decode_cstring(const std::string &str, size_t &lenParsed)
Unescape a C string, stopping at the first double quotes or at the end of the string.
std::string join(const std::string &sep, const ITER &begin, const ITER &end)
Stringify and join a sequence of objects.
Definition: string.h:38
std::string lower(const std::string &str)
Return a lowercased copy of str.
Definition: string.h:98
std::string upper(const std::string &str)
Return an uppercased copy of str.
Definition: string.h:88
std::string decode_url(const std::string &str)
Decode an urlencoded string.
bool startswith(const std::string &str, const std::string &part)
Check if a string starts with the given substring.
Definition: string.h:19
std::string str
String to split.
Definition: string.h:171