1#ifndef WREPORT_STRING_H
2#define WREPORT_STRING_H
20inline bool startswith(
const std::string& str,
const std::string& part)
22 if (str.size() < part.size())
24 return str.substr(0, part.size()) == part;
28inline bool endswith(
const std::string& str,
const std::string& part)
30 if (str.size() < part.size())
32 return str.substr(str.size() - part.size()) == part;
38template<
typename ITER>
39std::string join(
const std::string& sep,
const ITER& begin,
const ITER& end)
41 std::stringstream res;
43 for (ITER i = begin; i != end; ++i)
57template<
typename ITEMS>
58std::string join(
const std::string& sep,
const ITEMS& items)
60 std::stringstream res;
62 for (
const auto& i: items)
76std::string lstrip(
const std::string& str);
81std::string rstrip(
const std::string& str);
86std::string strip(
const std::string& str);
89inline std::string upper(
const std::string& str)
92 res.reserve(str.size());
93 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
99inline std::string lower(
const std::string& str)
102 res.reserve(str.size());
103 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
104 res += ::tolower(*i);
109std::string basename(
const std::string& pathname);
112std::string dirname(
const std::string& pathname);
115void appendpath(std::string& dest,
const char* path2);
118void appendpath(std::string& dest,
const std::string& path2);
121template<
typename S1,
typename S2,
typename... Args>
122void appendpath(std::string& dest, S1 first, S2 second, Args... next)
124 appendpath(dest, first);
125 appendpath(dest, second, next...);
129template<
typename... Args>
130std::string joinpath(Args... components)
133 appendpath(res, components...);
142std::string normpath(
const std::string& pathname);
174 const Split* split =
nullptr;
184 using iterator_category = std::input_iterator_tag;
185 using value_type = std::string;
186 using difference_type = int;
187 using pointer = std::string*;
188 using reference = std::string&;
197 const std::string& operator*()
const;
198 const std::string* operator->()
const;
200 std::string remainder()
const;
216std::string encode_cstring(
const std::string& str);
225std::string decode_cstring(
const std::string& str,
size_t& lenParsed);
228std::string encode_url(
const std::string& str);
231std::string decode_url(
const std::string& str);
234std::string encode_base64(
const std::string& str);
237std::string encode_base64(
const void* data,
size_t size);
240std::string decode_base64(
const std::string& str);
size_t end
Position of the first character of the next token.
Definition string.h:178
const_iterator()
End iterator.
Definition string.h:193
std::string cur
Current token.
Definition string.h:176
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 benchmark.h:13
Split a string where a given substring is found.
Definition string.h:157
bool skip_empty
If true, skip empty tokens, effectively grouping consecutive separators as if they were a single one.
Definition string.h:166
const_iterator end()
Return the end iterator to string split.
Definition string.h:210
const_iterator begin()
Return the begin iterator to split a string on instances of sep.
Definition string.h:207
std::string sep
Separator.
Definition string.h:161
std::string str
String to split.
Definition string.h:159