correction of trim in case of str only fill with delim char
+ added a new split, that also does trim, to split without counting newlines
This commit is contained in:
@@ -21,21 +21,42 @@ std::vector<std::string> split(std::string input, char delimiter)
|
||||
return answer;
|
||||
}
|
||||
|
||||
std::string trim(std::string str, char c)
|
||||
std::vector<std::string>
|
||||
split_trim(std::string input, std::string delim = "\n", char ctrim = '')
|
||||
{
|
||||
std::vector<std::string> split_str;
|
||||
std::string tmp;
|
||||
size_t start = 0;
|
||||
size_t end;
|
||||
|
||||
end = input.find(delim);
|
||||
while (end != -1)
|
||||
{
|
||||
tmp = input.substr(start, end - start);
|
||||
tmp = trim(tmp, ctrim);
|
||||
if (tmp.size() != 0)
|
||||
split_str.push_back( tmp );
|
||||
start = end + delim.size();
|
||||
end = input.find(delim, start);
|
||||
}
|
||||
split_str.push_back( input.substr(start, end - start) );
|
||||
return split_str;
|
||||
}
|
||||
|
||||
std::string trim(std::string str, char del)
|
||||
{
|
||||
size_t pos;
|
||||
|
||||
// delete leadings c
|
||||
pos = str.find_first_not_of(c);
|
||||
// delete leadings del
|
||||
pos = str.find_first_not_of(del);
|
||||
if (pos == std::string::npos)
|
||||
return str;
|
||||
pos = str.size();
|
||||
str = str.substr(pos);
|
||||
|
||||
// delete endings c
|
||||
pos = str.find_last_not_of(c);
|
||||
if (pos == std::string::npos)
|
||||
return str;
|
||||
str = str.substr(0, pos + 1);
|
||||
// delete trailing del
|
||||
pos = str.find_last_not_of(del);
|
||||
if (pos != std::string::npos)
|
||||
str = str.substr(0, pos + 1);
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -177,14 +198,6 @@ std::string extract_line(std::string * str, size_t pos, std::string delim)
|
||||
return del_str;
|
||||
}
|
||||
|
||||
// transform a str, like a http header, into a map
|
||||
// with <keys> delim <values>
|
||||
// and perform an action on keys and values
|
||||
// action receives address of keys and values, and return bool error :
|
||||
// bool action(&keys, &values)
|
||||
//std::map<std:string, std::string>
|
||||
// str_to_map(str, delim, action = NULL)
|
||||
|
||||
bool operator==(const listen_socket& lhs, int fd)
|
||||
{ return lhs.fd == fd; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user