1 #ifndef WREPORT_STRING_H
2 #define WREPORT_STRING_H
20 inline bool startswith(
const std::string& str,
const std::string& part)
22 if (str.size() < part.size())
24 return str.substr(0, part.size()) == part;
28 inline 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;
38 template<
typename ITER>
39 std::string join(
const std::string& sep,
const ITER& begin,
const ITER& end)
41 std::stringstream res;
43 for (ITER i = begin; i != end; ++i)
57 template<
typename ITEMS>
58 std::string join(
const std::string& sep,
const ITEMS& items)
60 std::stringstream res;
62 for (
const auto& i: items)
76 std::string lstrip(
const std::string& str);
81 std::string rstrip(
const std::string& str);
86 std::string strip(
const std::string& str);
89 inline 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)
99 inline 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);
109 std::string basename(
const std::string& pathname);
112 std::string dirname(
const std::string& pathname);
115 void appendpath(std::string& dest,
const char* path2);
118 void appendpath(std::string& dest,
const std::string& path2);
121 template<
typename S1,
typename S2,
typename... Args>
122 void appendpath(std::string& dest, S1 first, S2 second, Args... next)
124 appendpath(dest, first);
125 appendpath(dest, second, next...);
129 template<
typename... Args>
130 std::string joinpath(Args... components)
133 appendpath(res, components...);
142 std::string normpath(
const std::string& pathname);
171 class const_iterator :
public std::iterator<std::input_iterator_tag, std::string>
174 const Split* split =
nullptr;
191 const std::string& operator*()
const;
192 const std::string* operator->()
const;
194 std::string remainder()
const;
210 std::string encode_cstring(
const std::string& str);
219 std::string decode_cstring(
const std::string& str,
size_t& lenParsed);
222 std::string encode_url(
const std::string& str);
225 std::string decode_url(
const std::string& str);
228 std::string encode_base64(
const std::string& str);
231 std::string encode_base64(
const void* data,
size_t size);
234 std::string decode_base64(
const std::string& str);