Files
42_INT_12_webserv/srcs/utils.cpp

48 lines
934 B
C++

#include "utils.hpp"
std::vector<std::string> split(std::string input, char delimiter)
{
std::vector<std::string> answer;
std::stringstream ss(input);
std::string temp;
while (getline(ss, temp, delimiter))
answer.push_back(temp);
return answer;
}
bool isNumeric(std::string str)
{
for (size_t i = 0; i < str.length(); i++)
{
if (std::isdigit(str[i]) == false)
return false;
}
return true;
}
bool isNumeric_btw(int low, int high, std::string str)
{
for (size_t i = 0; i < str.length(); i++)
{
if (std::isdigit(str[i]) == false)
return false;
}
int n = std::atoi(str.c_str());
if (n < low || n > high)
return false;
return true;
}
char* itoa(int n)
{
std::stringstream strs;
strs << n;
// casts : https://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used
return ( const_cast<char*>( strs.str().c_str() ) );
}