Something went wrong. Try again.
An HTTP server written in C++98 projects.intra.42.fr/projects/webserv
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586/* ************************************************************************** *//* *//* ::: :::::::: *//* parse_utils.cpp :+: :+: :+: *//* +:+ +:+ +:+ *//* By: bcausseq <bcausseq@42angouleme.fr> +#+ +:+ +#+ *//* +#+#+#+#+#+ +#+ *//* Created: 2026/09/27 00:25:48 by bcausseq #+# #+# *//* Updated: 2026/09/27 22:15:18 by bcausseq ### ########.fr *//* *//* ************************************************************************** */
#include "ParserExceptions.hpp"#include "parse_utils.hpp"
#include <sstream>
boolcheck_root(std::string& line, unsigned int& line_nbr){ const std::string acceptedparam = "/abcdefghijklmnopqrstuvwxyz.-";
for (auto it = line.begin(); it != line.end(); ++it) { if (acceptedparam.find(*it) == acceptedparam.npos) { std::string errs("Wrong character in the root. Problem line : "); errs += itos(line_nbr); throw (ParserExceptions(errs)); } } return (true);}
std::stringitos(unsigned int &line_nbr){ std::stringstream ss;
ss << line_nbr; std::string ret = ss.str(); return (ret);}
std::stringwhite_space(std::string& line){ size_t left = line.find_first_not_of(" \t"); size_t right = line.find_first_of(';');
if (left == std::string::npos) return (line); if (right == std::string::npos) right = line.size() - 1;
std::string ret(line.substr(left, right - left + 1));
return (ret);}
voidtrim_comma(std::string& line){ size_t comma = line.find(';');
if (comma == line.npos || comma != line.size() - 1) return ;
line.erase(line.size() - 1);}
boolcheck_method(std::string& method, unsigned int& line_nbr){ const std::string methods[3] = {"GET", "DELETE", "POST"};
for (size_t i = 0; i <= 2; ++i) { if (method == methods[i]) return (true); } std::string errs("Wrong methods in location. Problem line : "); errs += itos(line_nbr); throw (ParserExceptions(errs));}