From d49f60d2d6a3a1904bce9af22d97e4b51e0a6bb9 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Fri, 4 Nov 2022 17:21:22 +0100 Subject: [PATCH] To change fewer things with the master implementation, the Id isn't changed to lower case on creation lower case utility functions used in comparison functions --- apps/openmw/mwworld/globals.cpp | 4 ++-- components/esm/refid.cpp | 13 +++++++++---- components/esm/refid.hpp | 2 +- components/misc/strings/algorithm.hpp | 10 ++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 691cb8d6ce..8e691d6067 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -38,7 +38,7 @@ namespace MWWorld for (const ESM::Global& esmGlobal : globals) { - mVariables.insert(std::make_pair(esmGlobal.mId.getRefIdString(), esmGlobal)); + mVariables.insert(std::make_pair(Misc::StringUtils::lowerCase(esmGlobal.mId.getRefIdString()), esmGlobal)); } } @@ -99,7 +99,7 @@ namespace MWWorld // Deleted globals can't appear there, so isDeleted will be ignored here. global.load(reader, isDeleted); - Collection::iterator iter = mVariables.find(global.mId.getRefIdString()); + Collection::iterator iter = mVariables.find(Misc::StringUtils::lowerCase(global.mId.getRefIdString())); if (iter != mVariables.end()) iter->second = global; diff --git a/components/esm/refid.cpp b/components/esm/refid.cpp index 11d2f7761e..488c54f37e 100644 --- a/components/esm/refid.cpp +++ b/components/esm/refid.cpp @@ -8,17 +8,17 @@ namespace ESM { bool RefId::operator==(const RefId& rhs) const { - return this->mId == rhs.mId; + return Misc::StringUtils::ciEqual(mId, rhs.mId); } bool RefId::operator<(const RefId& rhs) const { - return mId < rhs.mId; + return Misc::StringUtils::ciLess(mId, rhs.mId); } bool RefId::operator>(const RefId& rhs) const { - return mId > rhs.mId; + return Misc::StringUtils::ciMore(mId, rhs.mId); } std::ostream& operator<<(std::ostream& os, const RefId& refId) @@ -30,7 +30,7 @@ namespace ESM RefId RefId::stringRefId(std::string_view id) { RefId newRefId; - newRefId.mId = Misc::StringUtils::lowerCase(id); + newRefId.mId = id; return newRefId; } @@ -41,3 +41,8 @@ namespace ESM const RefId RefId::sEmpty = {}; } + +std::size_t std::hash::operator()(const ESM::RefId& k) const +{ + return Misc::StringUtils::CiHash()(k.getRefIdString()); +} diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index e9f4684e1d..2e11da59ab 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -45,7 +45,7 @@ namespace std template <> struct hash { - std::size_t operator()(const ESM::RefId& k) const { return std::hash()(k.getRefIdString()); } + std::size_t operator()(const ESM::RefId& k) const; }; } #endif diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 1e1eba30a9..f2eb91c05c 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -20,6 +20,16 @@ namespace Misc::StringUtils return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess()); } + struct CiCharMore + { + bool operator()(char x, char y) const { return toLower(x) > toLower(y); } + }; + + inline bool ciMore(std::string_view x, std::string_view y) + { + return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharMore()); + } + inline bool ciEqual(std::string_view x, std::string_view y) { if (std::size(x) != std::size(y))