1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 21:36:42 +00:00

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
This commit is contained in:
florent.teppe 2022-11-04 17:21:22 +01:00
parent 65cdd489fb
commit d49f60d2d6
4 changed files with 22 additions and 7 deletions

View file

@ -38,7 +38,7 @@ namespace MWWorld
for (const ESM::Global& esmGlobal : globals) 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. // Deleted globals can't appear there, so isDeleted will be ignored here.
global.load(reader, isDeleted); 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()) if (iter != mVariables.end())
iter->second = global; iter->second = global;

View file

@ -8,17 +8,17 @@ namespace ESM
{ {
bool RefId::operator==(const RefId& rhs) const 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 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 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) std::ostream& operator<<(std::ostream& os, const RefId& refId)
@ -30,7 +30,7 @@ namespace ESM
RefId RefId::stringRefId(std::string_view id) RefId RefId::stringRefId(std::string_view id)
{ {
RefId newRefId; RefId newRefId;
newRefId.mId = Misc::StringUtils::lowerCase(id); newRefId.mId = id;
return newRefId; return newRefId;
} }
@ -41,3 +41,8 @@ namespace ESM
const RefId RefId::sEmpty = {}; const RefId RefId::sEmpty = {};
} }
std::size_t std::hash<ESM::RefId>::operator()(const ESM::RefId& k) const
{
return Misc::StringUtils::CiHash()(k.getRefIdString());
}

View file

@ -45,7 +45,7 @@ namespace std
template <> template <>
struct hash<ESM::RefId> struct hash<ESM::RefId>
{ {
std::size_t operator()(const ESM::RefId& k) const { return std::hash<std::string>()(k.getRefIdString()); } std::size_t operator()(const ESM::RefId& k) const;
}; };
} }
#endif #endif

View file

@ -20,6 +20,16 @@ namespace Misc::StringUtils
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess()); 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) inline bool ciEqual(std::string_view x, std::string_view y)
{ {
if (std::size(x) != std::size(y)) if (std::size(x) != std::size(y))