1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-05-11 22:41:26 +00:00

string compare and tolower

This commit is contained in:
eduard 2012-12-28 18:05:52 +01:00
parent 8545667bbd
commit c75a5ae212
3 changed files with 15 additions and 15 deletions

View file

@ -34,6 +34,12 @@ namespace
return sum; return sum;
} }
bool compare_string_ci(std::string str1, std::string str2)
{
boost::algorithm::to_lower(str1);
return str1 == str2;
}
} }
MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {} MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {}
@ -75,11 +81,11 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
MWWorld::LiveCellRef<ESM::Miscellaneous> *gold = MWWorld::LiveCellRef<ESM::Miscellaneous> *gold =
ptr.get<ESM::Miscellaneous>(); ptr.get<ESM::Miscellaneous>();
if (Misc::compare_string_ci(gold->ref.mRefID, "gold_001") if (compare_string_ci(gold->ref.mRefID, "gold_001")
|| Misc::compare_string_ci(gold->ref.mRefID, "gold_005") || compare_string_ci(gold->ref.mRefID, "gold_005")
|| Misc::compare_string_ci(gold->ref.mRefID, "gold_010") || compare_string_ci(gold->ref.mRefID, "gold_010")
|| Misc::compare_string_ci(gold->ref.mRefID, "gold_025") || compare_string_ci(gold->ref.mRefID, "gold_025")
|| Misc::compare_string_ci(gold->ref.mRefID, "gold_100")) || compare_string_ci(gold->ref.mRefID, "gold_100"))
{ {
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
@ -87,7 +93,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
ref.getPtr().getRefData().setCount(count); ref.getPtr().getRefData().setCount(count);
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
{ {
if (Misc::compare_string_ci((*iter).get<ESM::Miscellaneous>()->ref.mRefID, "gold_001")) if (compare_string_ci((*iter).get<ESM::Miscellaneous>()->ref.mRefID, "gold_001"))
{ {
(*iter).getRefData().setCount( (*iter).getRefData().getCount() + count); (*iter).getRefData().setCount( (*iter).getRefData().getCount() + count);
flagAsModified(); flagAsModified();

View file

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include <libs/platform/strings.h> #include <libs/platform/strings.h>
#include <boost/algorithm/string.hpp>
@ -92,10 +91,6 @@ bool stringCompareNoCase (std::string first, std::string second)
else else
return false; return false;
} }
bool compare_string_ci(std::string str1, std::string str2)
{
boost::algorithm::to_lower(str1);
return str1 == str2;
}
} }

View file

@ -18,13 +18,12 @@ bool ibegins(const char* str1, const char* str2);
/// Case insensitive, returns true if str1 ends with substring str2 /// Case insensitive, returns true if str1 ends with substring str2
bool iends(const char* str1, const char* str2); bool iends(const char* str1, const char* str2);
///
std::string toLower (const std::string& name); std::string toLower (const std::string& name);
/// Case fold compare
bool stringCompareNoCase (std::string first, std::string second); bool stringCompareNoCase (std::string first, std::string second);
bool compare_string_ci (std::string first, std::string second);
} }
#endif #endif