6 #ifndef LIBDAZEUS_UTILS_H
7 #define LIBDAZEUS_UTILS_H
18 std::string
trim(
const std::string &s);
19 std::vector<std::string>
split(
const std::string &s,
const std::string &sep);
20 bool contains(std::string x,
char v);
22 bool startsWith(std::string x, std::string y,
bool caseInsensitive);
23 std::vector<std::string>::iterator
find_ci(std::vector<std::string> &v,
const std::string &s);
25 template <
typename Container,
typename Key>
27 return x.count(k) != 0;
30 template <
typename Value>
32 return find(x.begin(), x.end(), v) != x.end();
35 template <
typename Container,
typename Value>
36 void erase(Container &x, Value v) {
37 x.erase(
remove(x.begin(), x.end(), v), x.end());
40 template <
typename Container,
typename Value>
47 template <
typename Value>
48 typename std::map<std::string,Value>::iterator
find_ci(std::map<std::string,Value> &m,
const std::string &s) {
50 typename std::map<std::string,Value>::iterator it;
51 for(it = m.begin(); it != m.end(); ++it) {
59 template <
typename Container,
typename Key>
61 return find_ci(x, s) != x.end();
64 template <
typename Container>
65 void erase_ci(Container &x,
const std::string &s) {
67 typename Container::iterator it =
find_ci(x, s);
69 while(it != x.end()) {
75 template <
typename Container>
76 std::string
join(Container c, std::string s) {
78 typename Container::const_iterator it;
80 for(it = c.begin(); it != c.end(); ++it) {
89 std::vector<std::string> &operator<<(std::vector<std::string> &x,
const char *v);
91 std::vector<T> &operator<<(std::vector<T> &x, T v) {
97 std::vector<T> &operator<<(std::vector<T> &x,
const std::vector<T> &v) {
98 x.insert(x.end(), v.begin(), v.end());