NPOS macro
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/23 16:08:00 by me #+# #+# */
|
||||
/* Updated: 2022/08/04 19:32:40 by erlazo ### ########.fr */
|
||||
/* Updated: 2022/08/12 18:12:23 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
int comp_rhs = 0;
|
||||
size_t tmp = 0;
|
||||
|
||||
while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos)
|
||||
while ((tmp = this->path.find_first_of("/", tmp)) != NPOS)
|
||||
{
|
||||
++tmp;
|
||||
++comp_lhs;
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
if (path[path.find_last_of("/") + 1] != '\0')
|
||||
++comp_lhs;
|
||||
tmp = 0;
|
||||
while ((tmp = rhs.path.find_first_of("/", tmp)) != std::string::npos)
|
||||
while ((tmp = rhs.path.find_first_of("/", tmp)) != NPOS)
|
||||
{
|
||||
++tmp;
|
||||
++comp_rhs;
|
||||
|
||||
@@ -13,10 +13,10 @@ std::string ConfigParser::_pre_set_val_check(const std::string key, \
|
||||
// check values for ; at end and right number of words depending on key
|
||||
|
||||
// std::cout << "pre check\n";
|
||||
if (key.find_first_of(";") != std::string::npos)
|
||||
if (key.find_first_of(";") != NPOS)
|
||||
throw std::invalid_argument("bad config file arguments 2");
|
||||
|
||||
if (value.find_first_of("\t") != std::string::npos)
|
||||
if (value.find_first_of("\t") != NPOS)
|
||||
throw std::invalid_argument("why would you put tabs between values");
|
||||
|
||||
size_t i = value.find_first_of(";");
|
||||
@@ -24,7 +24,7 @@ std::string ConfigParser::_pre_set_val_check(const std::string key, \
|
||||
// you can't have just ;
|
||||
// and you can't have a ; not at the end or several ;
|
||||
// in theory value_find_last_of should find the only ;
|
||||
if (i == std::string::npos || (value.find_last_not_of(" \n")) != i \
|
||||
if (i == NPOS || (value.find_last_not_of(" \n")) != i \
|
||||
|| value.compare(";") == 0)
|
||||
throw std::invalid_argument("bad config file arguments 4");
|
||||
|
||||
@@ -38,9 +38,9 @@ std::string ConfigParser::_get_first_word(size_t *curr)
|
||||
{
|
||||
size_t start;
|
||||
|
||||
if ((start = _content.find_first_not_of(" \t\n", *curr)) == std::string::npos)
|
||||
if ((start = _content.find_first_not_of(" \t\n", *curr)) == NPOS)
|
||||
throw std::invalid_argument("bad config file arguments");
|
||||
if ((*curr = _content.find_first_of(" \t\n", start)) == std::string::npos)
|
||||
if ((*curr = _content.find_first_of(" \t\n", start)) == NPOS)
|
||||
throw std::invalid_argument("bad config file arguments");
|
||||
|
||||
std::string key = _content.substr(start, *curr - start);
|
||||
@@ -53,9 +53,9 @@ std::string ConfigParser::_get_rest_of_line(size_t *curr)
|
||||
{
|
||||
size_t start;
|
||||
|
||||
if ((start = _content.find_first_not_of(" \t\n", *curr)) == std::string::npos)
|
||||
if ((start = _content.find_first_not_of(" \t\n", *curr)) == NPOS)
|
||||
throw std::invalid_argument("bad config file arguments");
|
||||
if ((*curr = _content.find_first_of("\n", start)) == std::string::npos)
|
||||
if ((*curr = _content.find_first_of("\n", start)) == NPOS)
|
||||
throw std::invalid_argument("bad config file arguments");
|
||||
|
||||
std::string values = _content.substr(start, *curr - start);
|
||||
|
||||
@@ -24,10 +24,10 @@ ConfigParser::ConfigParser(const char* path)
|
||||
{
|
||||
getline(file, buf);
|
||||
// remove # comments here.
|
||||
if ((comment = buf.find_first_of("#")) == std::string::npos)
|
||||
if ((comment = buf.find_first_of("#")) == NPOS)
|
||||
{
|
||||
// remove empty lines, i think...
|
||||
if ((buf.find_first_not_of(" \t")) != std::string::npos)
|
||||
if ((buf.find_first_not_of(" \t")) != NPOS)
|
||||
_content.append(buf + '\n');
|
||||
}
|
||||
else if (comment > 0 && (buf.find_first_not_of(" \t")) < comment)
|
||||
@@ -67,14 +67,14 @@ std::vector<ServerConfig> * ConfigParser::parse()
|
||||
size_t start = 0;
|
||||
size_t curr = _content.find_first_not_of(" \t\n", 0);
|
||||
|
||||
if (curr == std::string::npos)
|
||||
if (curr == NPOS)
|
||||
throw std::invalid_argument("empty config file");
|
||||
while (curr != std::string::npos)
|
||||
while (curr != NPOS)
|
||||
{
|
||||
if ((start = _content.find_first_not_of(" \t\n", curr)) == std::string::npos)
|
||||
if ((start = _content.find_first_not_of(" \t\n", curr)) == NPOS)
|
||||
throw std::invalid_argument("empty config file");
|
||||
|
||||
if ((curr = _content.find_first_of(" \t\n", start)) == std::string::npos)
|
||||
if ((curr = _content.find_first_of(" \t\n", start)) == NPOS)
|
||||
throw std::invalid_argument("empty config file");
|
||||
std::string key = _content.substr(start, curr - start);
|
||||
if (key != "server")
|
||||
@@ -91,13 +91,13 @@ ServerConfig ConfigParser::_parse_server(size_t *start)
|
||||
size_t curr = _content.find_first_not_of(" \t\n", *start);
|
||||
|
||||
ret.client_body_limit = 0;
|
||||
if (curr == std::string::npos || _content[curr] != '{')
|
||||
if (curr == NPOS || _content[curr] != '{')
|
||||
throw std::invalid_argument("bad config file syntax 1");
|
||||
|
||||
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == std::string::npos)
|
||||
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == NPOS)
|
||||
throw std::invalid_argument("bad config file syntax");
|
||||
// are there other things to check for?
|
||||
while (curr != std::string::npos) // here curr == { + 1
|
||||
while (curr != NPOS) // here curr == { + 1
|
||||
{
|
||||
// so this moves curr to past the word...
|
||||
std::string key = _get_first_word(&curr);
|
||||
@@ -140,12 +140,12 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
|
||||
curr = _content.find_first_not_of(" \t\n", curr);
|
||||
|
||||
if (curr == std::string::npos || _content[curr] != '{')
|
||||
if (curr == NPOS || _content[curr] != '{')
|
||||
throw std::invalid_argument("bad config file syntax 2");
|
||||
|
||||
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == std::string::npos)
|
||||
if ((curr = _content.find_first_of(" \t\n", curr + 1)) == NPOS)
|
||||
throw std::invalid_argument("bad config file syntax");
|
||||
while (curr != std::string::npos)
|
||||
while (curr != NPOS)
|
||||
{
|
||||
// so this moves curr to past the word...
|
||||
std::string key = _get_first_word(&curr);
|
||||
@@ -192,7 +192,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
else if (key == "listen" && size == 1 && server->host == "" \
|
||||
&& server->port == "")
|
||||
{
|
||||
if (tmp_val[0].find_first_of(":") == std::string::npos)
|
||||
if (tmp_val[0].find_first_of(":") == NPOS)
|
||||
{
|
||||
if (!::isNumeric(tmp_val[0]))
|
||||
throw std::invalid_argument("bad port number");
|
||||
|
||||
Reference in New Issue
Block a user