makefile for cgi_scripts

This commit is contained in:
hugogogo
2022-08-15 15:28:19 +02:00
parent a284e400c1
commit 036256522a
7 changed files with 232 additions and 140 deletions

View File

@@ -0,0 +1,78 @@
#include "cgi_utils.hpp"
std::string trim(std::string str, char del)
{
size_t pos;
// delete leadings del
pos = str.find_first_not_of(del);
if (pos == NPOS)
pos = str.size();
str = str.substr(pos);
// delete trailing del
pos = str.find_last_not_of(del);
if (pos != NPOS)
str = str.substr(0, pos + 1);
return str;
}
std::vector<std::string>
split(const std::string & input, std::string delim, char ctrim)
{
std::vector<std::string> split_str;
std::string tmp;
size_t start = 0;
size_t end = 0;
size_t len = 0;
while (end != NPOS)
{
end = input.find(delim, start);
len = end - start;
if (end == NPOS)
len = end;
tmp = input.substr(start, len);
if (ctrim != '\0')
tmp = trim(tmp, ctrim);
if (tmp.size() != 0)
split_str.push_back( tmp );
start = end + delim.size();
}
return split_str;
}
std::string itos(int n)
{
std::stringstream strs;
strs << n;
return ( strs.str() );
}
std::string fill_env(std::string env, std::string tag)
{
std::string ret;
char * ret_env;
ret = "<";
ret += tag;
ret += ">";
ret_env = getenv(env.c_str());
if (ret_env != NULL)
ret += ret_env;
else
{
ret += env;
ret += " not foud";
}
ret += "</";
ret += tag;
ret += ">";
return ret;
}