|
- #pragma once
-
- #include "compare.h"
-
- namespace cppcore
- {
-
- /* op_invariant_string_less */
-
- bool op_invariant_string_less
- ::operator()(const std::string& lhs, const std::string& rhs) const
- { return op_invariant_string_compare { } (lhs, rhs) < 0; }
-
- /* op_invariant_string_compare */
-
- int op_invariant_string_compare::operator()(const std::string& lhs, const std::string& rhs) const
- {
- auto c1 = lhs.c_str();
- auto c2 = rhs.c_str();
- auto l1 = lhs.size();
- auto l2 = rhs.size();
-
- while (l1 > 0 && l2 > 0 && std::tolower(*c1) == std::tolower(*c2))
- {
- ++c1;
- ++c2;
- --l1;
- --l2;
- }
-
- if (l1 > 0 && l2 > 0)
- {
- auto x1 = std::tolower(*c1);
- auto x2 = std::tolower(*c2);
-
- return
- x1 < x2 ? -1 :
- x1 > x2 ? 1 :
- 0;
- }
- else
- {
- return
- l1 < l2 ? -1 :
- l1 > l2 ? 1 :
- 0;
- }
- }
-
-
- }
|