diff --git a/src/libs/util/include/storm/string_compare.hpp b/src/libs/util/include/storm/string_compare.hpp index 66d7ed29f..d7c97febf 100644 --- a/src/libs/util/include/storm/string_compare.hpp +++ b/src/libs/util/include/storm/string_compare.hpp @@ -48,8 +48,8 @@ bool iEquals(const Range1T &first, const Range2T &second, const size_t count) const auto first_end = std::end(first_normalized); const auto second_end = std::end(second_normalized); - const auto first_length = std::distance(first_begin, first_end) - 1; - const auto second_length = std::distance(first_begin, first_end) - 1; + const auto first_length = std::distance(first_begin, first_end); + const auto second_length = std::distance(second_begin, second_end); if (first_length < count || second_length < count) { if (first_length != second_length) @@ -64,7 +64,7 @@ bool iEquals(const Range1T &first, const Range2T &second, const size_t count) } else { - return std::equal(first_begin, first_end, second_begin, second_end, comp); + return std::equal(first_begin, first_begin + count, second_begin, second_begin + count, comp); } } diff --git a/src/libs/util/testsuite/string_compare.cpp b/src/libs/util/testsuite/string_compare.cpp index ac3dca31a..2ba5b1976 100644 --- a/src/libs/util/testsuite/string_compare.cpp +++ b/src/libs/util/testsuite/string_compare.cpp @@ -58,6 +58,8 @@ TEST_CASE("Case-insensitive string comparison", "[utils]") SECTION("Compare only count number of character at most") { CHECK(iEquals(str_lowercase, str_long, 8)); + CHECK(iEquals(str_long, str_lowercase, 8)); + CHECK_FALSE(iEquals(".txt1", ".txt2", 5)); } }