From ca8427262d9cb6d6efdac23fdd642073929bafdc Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 4 Aug 2022 01:41:19 +0200 Subject: [PATCH] wrote a tiny thing to improve the operator< overlaod, will test tomorrow --- srcs/config/LocationConfig.hpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/srcs/config/LocationConfig.hpp b/srcs/config/LocationConfig.hpp index 7be88fe..ad1465d 100644 --- a/srcs/config/LocationConfig.hpp +++ b/srcs/config/LocationConfig.hpp @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/23 16:08:00 by me #+# #+# */ -/* Updated: 2022/08/02 14:06:07 by lperrey ### ########.fr */ +/* Updated: 2022/08/04 01:40:40 by me ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,8 @@ public: } // works a lot better than using a compare function... +// but it still doesn't work... +// problem is the logic bool operator<(const LocationConfig& rhs) const { size_t len_lhs = 0; @@ -75,6 +77,15 @@ public: // consider adding 1 to path that ends in a file not folder. + // What are the rules... + // / is smaller than /test + // and /test/test1 is bigger than test + // so we want to count / + + len_lhs = _count_chars(this->path); + len_rhs = _count_chars(rhs.path); + +/* while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos) { std::cout << "tmp_lhs: " << tmp << "\n"; @@ -88,11 +99,30 @@ public: ++tmp; ++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 <= ? }; + size_t _count_chars(std::string str) + { + const char *tmp = str.c_str(); + size_t i = 0; + size_t count = 0; + + while (i < str.lenght()) + { + if (tmp[i] == '/') + ++count; + ++i; + } + + return (count); + } + + + }; // ok it needs to go somewhere else