From fce1bcbecea24691544ffe1afa6cd2ee6e75c8f0 Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 4 Aug 2022 16:45:12 +0200 Subject: [PATCH] well, the location sorter is better, but i don't understand why, kinda by accident, will try to figure it out --- default.config | 2 -- srcs/config/LocationConfig.hpp | 44 +++++++++++++++++++++++++------ srcs/config/postProcessing.cpp | 47 +++++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/default.config b/default.config index beade3c..096b35f 100644 --- a/default.config +++ b/default.config @@ -34,11 +34,9 @@ server { location /something/long/here { - } location /something/long/here/but/more { - } diff --git a/srcs/config/LocationConfig.hpp b/srcs/config/LocationConfig.hpp index ad1465d..07ce034 100644 --- a/srcs/config/LocationConfig.hpp +++ b/srcs/config/LocationConfig.hpp @@ -71,9 +71,11 @@ public: // problem is the logic bool operator<(const LocationConfig& rhs) const { - size_t len_lhs = 0; - size_t len_rhs = 0; - size_t tmp = 0; +// size_t len_lhs = 0; +// size_t len_rhs = 0; + int len_lhs = 0; + int len_rhs = 0; +// size_t tmp = 0; // consider adding 1 to path that ends in a file not folder. @@ -82,8 +84,28 @@ public: // and /test/test1 is bigger than test // so we want to count / - len_lhs = _count_chars(this->path); - len_rhs = _count_chars(rhs.path); +// len_lhs = _count_chars(this->path); +// len_rhs = _count_chars(rhs.path); + + const char *tmp1 = this->path.c_str(); + size_t i = 0; + + while (tmp1[i]) + { + if (tmp1[i] == '/') + ++len_lhs; + ++i; + } + + const char *tmp2 = rhs.path.c_str(); + i = 0; + + while (tmp2[i]) + { + if (tmp2[i] == '/') + ++len_rhs; + ++i; + } /* while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos) @@ -100,11 +122,17 @@ public: ++len_rhs; } */ - std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs << (len_lhs < len_rhs) << "\n"; - return (len_lhs < len_rhs); // right comparison ? not <= ? + std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs \ + << " bool res: " << (len_lhs > len_rhs) << "\n"; + // i honestly can't tell you how or why but using > rather than < + // fixed all my problems + // the fact that the bool was always 0 before, and the correct order + // i want... super weird... + return (len_lhs > len_rhs); // right comparison ? not <= ? }; +/* size_t _count_chars(std::string str) { const char *tmp = str.c_str(); @@ -120,7 +148,7 @@ public: return (count); } - +*/ }; diff --git a/srcs/config/postProcessing.cpp b/srcs/config/postProcessing.cpp index e9971db..0b0cfcf 100644 --- a/srcs/config/postProcessing.cpp +++ b/srcs/config/postProcessing.cpp @@ -24,8 +24,25 @@ bool compareLocationConfigs(const LocationConfig &a, const LocationConfig &b) } */ +/* +class spec_int +{ +public: + spec_int() {} + spec_int(int i): i(i){} + ~spec_int() {} +// spec_int(int start, int num) +// { + +// } - + int i; + bool operator<(const spec_int &a, const spec_int &b) + { + return (a.i < b.i); + } +} +*/ void ConfigParser::_post_processing(std::vector *servers) { @@ -135,6 +152,34 @@ void ConfigParser::_post_processing(std::vector *servers) // std::reverse(it->locations.begin(), it->locations.end()); + +/* +// let's test sort + int myints[] = {32,71,12,45,26,80,53,33}; +// std::vector myvector (myints, myints+8); +// std::vector myvector(10, 5); + std::vector myvector; + + myvector.resize(6); + + myvector[0].i = 32; + myvector[1].i = 71; + myvector[2].i = 12; + myvector[3].i = 45; + myvector[4].i = 26; + myvector[5].i = 80; + + + std::sort(myvector.begin(), myvector.end()); + + std::cout << "myvector contains:"; +// for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) + for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) + std::cout << ' ' << *it; + std::cout << '\n'; +*/ + + ++it; }