1#ifndef WREPORT_STRING_H
2#define WREPORT_STRING_H
21 if (
str.size() < part.size())
23 return str.substr(0, part.size()) == part;
27inline 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;
37template <
typename ITER>
38std::string
join(
const std::string& sep,
const ITER& begin,
const ITER& end)
40 std::stringstream res;
42 for (ITER i = begin; i != end; ++i)
56template <
typename ITEMS>
57std::string
join(
const std::string& sep,
const ITEMS& items)
59 std::stringstream res;
61 for (
const auto& i : items)
88inline 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)));
98inline 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
112[[deprecated(
"Use path.parent_path")]] std::string
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);
124template <
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
136template <
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
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;
size_t end
Position of the first character of the next token.
Definition string.h:193
const_iterator()
End iterator.
Definition string.h:209
std::string cur
Current token.
Definition string.h:191
const_iterator(const Split &split)
Begin iterator.
void skip_separators()
Move end past all the consecutive separators that start at its position.
String functions.
Definition string.h:16
std::string strip(const std::string &str)
Return the substring of 'str' without all leading and trailing spaces.
std::string encode_base64(const std::string &str)
Encode a string in Base64.
std::string basename(const std::string &pathname)
Given a pathname, return the file name without its path.
std::string decode_base64(const std::string &str)
Decode a string encoded in Base64.
std::string rstrip(const std::string &str)
Return the substring of 'str' without all trailing spaces.
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 lstrip(const std::string &str)
Return the substring of 'str' without all leading spaces.
std::string lower(const std::string &str)
Return a lowercased copy of str.
Definition string.h:98
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_url(const std::string &str)
Urlencode a string.
std::string dirname(const std::string &pathname)
Given a pathname, return the directory name without the file name.
std::string normpath(const std::string &pathname)
Normalise a pathname.
std::string joinpath(Args... components)
Join two or more paths, adding slashes when appropriate.
Definition string.h:137
std::string join(const std::string &sep, const ITER &begin, const ITER &end)
Stringify and join a sequence of objects.
Definition string.h:38
void appendpath(std::string &dest, const char *path2)
Append path2 to path1, adding slashes when appropriate.
std::string encode_cstring(const std::string &str)
Escape the string so it can safely used as a C string inside double quotes.
std::string upper(const std::string &str)
Return an uppercased copy of str.
Definition string.h:88
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 decode_url(const std::string &str)
Decode an urlencoded string.
bool skip_empty
If true, skip empty tokens, effectively grouping consecutive separators as if they were a single one.
Definition string.h:178
const_iterator end()
Return the end iterator to string split.
Definition string.h:228
const_iterator begin()
Return the begin iterator to split a string on instances of sep.
Definition string.h:225
std::string sep
Separator.
Definition string.h:173
std::string str
String to split.
Definition string.h:171