Skip to content

Commit

Permalink
use lexicographical_compare for operator
Browse files Browse the repository at this point in the history
shorter and easier to read.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Nov 25, 2024
1 parent cf728b0 commit 2eb9853
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,11 @@ class EXIV2API XmpArrayValue : public XmpValue {
struct LangAltValueComparator {
//! LangAltValueComparator comparison case insensitive function
bool operator()(const std::string& str1, const std::string& str2) const {
int result = str1.size() < str2.size() ? 1 : str1.size() > str2.size() ? -1 : 0;
if (result == 0) {
for (auto c1 = str1.begin(), c2 = str2.begin(); result == 0 && c1 != str1.end(); ++c1, ++c2) {
result = tolower(*c1) < tolower(*c2) ? 1 : tolower(*c1) > tolower(*c2) ? -1 : 0;
}
}
return result < 0;
if (str1.size() != str2.size())
return str1.size() < str2.size();

auto f = [](char c1, char c2) { return tolower(c1) < tolower(c2); };
return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end(), f);
}
};

Expand Down

0 comments on commit 2eb9853

Please sign in to comment.