Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Fix issues with partial iEquals
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammie committed Dec 30, 2021
1 parent 2ed0c42 commit 9f62a7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libs/util/include/storm/string_compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libs/util/testsuite/string_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 9f62a7f

Please sign in to comment.