wrote a tiny thing to improve the operator< overlaod, will test tomorrow

This commit is contained in:
Me
2022-08-04 01:41:19 +02:00
parent 3d46505411
commit ca8427262d

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */ /* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/23 16:08:00 by me #+# #+# */ /* 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... // 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 bool operator<(const LocationConfig& rhs) const
{ {
size_t len_lhs = 0; size_t len_lhs = 0;
@@ -75,6 +77,15 @@ public:
// consider adding 1 to path that ends in a file not folder. // 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) while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos)
{ {
std::cout << "tmp_lhs: " << tmp << "\n"; std::cout << "tmp_lhs: " << tmp << "\n";
@@ -88,11 +99,30 @@ public:
++tmp; ++tmp;
++len_rhs; ++len_rhs;
} }
*/
std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs << (len_lhs < len_rhs) << "\n"; std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs << (len_lhs < len_rhs) << "\n";
return (len_lhs < len_rhs); // right comparison ? not <= ? 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 // ok it needs to go somewhere else