1 #ifndef RADARELAB_UTILS_STRING_H
2 #define RADARELAB_UTILS_STRING_H
21 inline bool startswith(
const std::string& str,
const std::string& part)
23 if (str.size() < part.size())
25 return str.substr(0, part.size()) == part;
29 inline bool endswith(
const std::string& str,
const std::string& part)
31 if (str.size() < part.size())
33 return str.substr(str.size() - part.size()) == part;
39 template<
typename ITER>
40 std::string join(
const std::string& sep,
const ITER& begin,
const ITER& end)
42 std::stringstream res;
44 for (ITER i = begin; i != end; ++i)
58 template<
typename ITEMS>
59 std::string join(
const std::string& sep,
const ITEMS& items)
61 std::stringstream res;
63 for (
const auto& i: items)
77 std::string lstrip(
const std::string& str);
82 std::string rstrip(
const std::string& str);
87 std::string strip(
const std::string& str);
90 inline std::string upper(
const std::string& str)
93 res.reserve(str.size());
94 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
100 inline std::string lower(
const std::string& str)
103 res.reserve(str.size());
104 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
105 res += ::tolower(*i);
110 std::string basename(
const std::string& pathname);
113 std::string dirname(
const std::string& pathname);
116 void appendpath(std::string& dest,
const char* path2);
119 void appendpath(std::string& dest,
const std::string& path2);
122 template<
typename S1,
typename S2,
typename... Args>
123 void appendpath(std::string& dest, S1 first, S2 second, Args... next)
125 appendpath(dest, first);
126 appendpath(dest, second, next...);
130 template<
typename... Args>
131 std::string joinpath(Args... components)
134 appendpath(res, components...);
143 std::string normpath(
const std::string& pathname);
175 const Split* split =
nullptr;
182 void skip_separators();
185 using iterator_category = std::input_iterator_tag;
186 using value_type = std::string;
187 using difference_type = int;
188 using pointer = std::string*;
189 using reference = std::string&;
192 const_iterator(
const Split& split);
197 const_iterator& operator++();
198 const std::string& operator*()
const;
199 const std::string* operator->()
const;
201 std::string remainder()
const;
203 bool operator==(
const const_iterator& ti)
const;
204 bool operator!=(
const const_iterator& ti)
const;
208 const_iterator
begin() {
return const_iterator(*
this); }
211 const_iterator
end() {
return const_iterator(); }
217 std::string encode_cstring(
const std::string& str);
226 std::string decode_cstring(
const std::string& str,
size_t& lenParsed);
229 std::string encode_url(
const std::string& str);
232 std::string decode_url(
const std::string& str);
235 std::string encode_base64(
const std::string& str);
238 std::string encode_base64(
const void* data,
size_t size);
241 std::string decode_base64(
const std::string& str);
std::string sep
Separator.
const_iterator begin()
Return the begin iterator to split a string on instances of sep.
const_iterator end()
Return the end iterator to string split.
std::string str
String to split.
bool skip_empty
If true, skip empty tokens, effectively grouping consecutive separators as if they were a single one.
Split a string where a given substring is found.