zutil-cpp/util.h

48 lines
913 B
C++

#ifndef ZUTIL
#define ZUTIL
#include <vector>
#include <algorithm>
#include <sstream>
#include <cctype>
using namespace std;
namespace zutil{
void tolower(string &s);
void trim(string &str);
vector<string> parseLine(istream &in, char separator, char endl);
vector<string> split(const string &s, char separator);
template<typename T>
bool remove(vector<T> &v, const T &item){
typename vector<T>::iterator it;
it = find(v.begin(), v.end(), item);
if(it != v.end()){
v.erase(it);
return true;
}
return false;
}
template<typename T>
bool contains(const vector<T> &v, const T &item){
typename vector<T>::const_iterator it;
it = find(v.begin(), v.end(), item);
if(it != v.end())
return true;
return false;
}
template<typename T>
string to_string(const T &t){
stringstream ss;
ss << t;
return ss.str();
}
}
#endif