cpp utils files, network and a smal util class
This commit is contained in:
parent
ea3dffdb4a
commit
62f50a2f79
13 changed files with 610 additions and 0 deletions
48
util.cpp
Normal file
48
util.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "util.h"
|
||||
|
||||
|
||||
void zutil::tolower(string &s){
|
||||
for(size_t i=0; s[i] ;++i){
|
||||
s[i] = std::tolower(s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void zutil::trim(string &str){
|
||||
size_t s = str.find_first_not_of(" \n\r\t");
|
||||
size_t e = str.find_last_not_of (" \n\r\t");
|
||||
|
||||
if( string::npos != s && string::npos != e)
|
||||
str = str.substr(s, e-s+1);
|
||||
}
|
||||
|
||||
|
||||
vector<string> zutil::parseLine(istream &in, char separator, char endl){
|
||||
vector<string> parsed;
|
||||
string line;
|
||||
getline(in, line, endl);
|
||||
|
||||
return split( line, separator );
|
||||
}
|
||||
|
||||
vector<string> zutil::split(const string &line, char separator){
|
||||
vector<string> parsed;
|
||||
|
||||
string tmp;
|
||||
for(size_t i=0; i<line.length() ;++i){
|
||||
if(line[i] == separator && !tmp.empty()){
|
||||
parsed.push_back( tmp );
|
||||
tmp = "";
|
||||
}
|
||||
else{
|
||||
tmp += line[i];
|
||||
}
|
||||
}
|
||||
if(!tmp.empty()){
|
||||
parsed.push_back( tmp );
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue