cpp utils files, network and a smal util class

This commit is contained in:
Ziver Koc 2009-11-21 01:11:05 +00:00
parent ea3dffdb4a
commit 62f50a2f79
13 changed files with 610 additions and 0 deletions

48
util.h Normal file
View file

@ -0,0 +1,48 @@
#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