/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parse_utils.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bcausseq +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 bool check_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::string itos(unsigned int &line_nbr) { std::stringstream ss; ss << line_nbr; std::string ret = ss.str(); return (ret); } std::string white_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); } void trim_comma(std::string& line) { size_t comma = line.find(';'); if (comma == line.npos || comma != line.size() - 1) return ; line.erase(line.size() - 1); } bool check_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)); }