1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 22:15:35 +00:00

Replace compare with more idiomatic methods

This commit is contained in:
Evil Eye 2023-05-22 19:51:27 +02:00
parent 3138eb406b
commit 9728024978
12 changed files with 33 additions and 41 deletions

View file

@ -545,17 +545,14 @@ void MwIniImporter::importGameFiles(
if (it == ini.end()) if (it == ini.end())
break; break;
for (std::vector<std::string>::const_iterator entry = it->second.begin(); entry != it->second.end(); ++entry) for (const std::string& file : it->second)
{ {
std::string filetype(entry->substr(entry->length() - 3)); if (Misc::StringUtils::ciEndsWith(file, "esm") || Misc::StringUtils::ciEndsWith(file, "esp"))
Misc::StringUtils::lowerCaseInPlace(filetype);
if (filetype.compare("esm") == 0 || filetype.compare("esp") == 0)
{ {
bool found = false; bool found = false;
for (auto& dataPath : dataPaths) for (auto& dataPath : dataPaths)
{ {
std::filesystem::path path = dataPath / *entry; std::filesystem::path path = dataPath / file;
std::time_t time = lastWriteTime(path, defaultTime); std::time_t time = lastWriteTime(path, defaultTime);
if (time != defaultTime) if (time != defaultTime)
{ {
@ -565,7 +562,7 @@ void MwIniImporter::importGameFiles(
} }
} }
if (!found) if (!found)
std::cout << "Warning: " << *entry << " not found, ignoring" << std::endl; std::cout << "Warning: " << file << " not found, ignoring" << std::endl;
} }
} }
} }

View file

@ -178,7 +178,7 @@ namespace MWInput
void ActionManager::screenshot() void ActionManager::screenshot()
{ {
const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video"); const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video");
bool regularScreenshot = settingStr.size() == 0 || settingStr.compare("regular") == 0; bool regularScreenshot = settingStr.empty() || settingStr == "regular";
if (regularScreenshot) if (regularScreenshot)
{ {

View file

@ -1835,7 +1835,7 @@ namespace MWMechanics
mAnimation->disable(mAnimQueue.front().mGroup); mAnimation->disable(mAnimQueue.front().mGroup);
mAnimQueue.pop_front(); mAnimQueue.pop_front();
bool loopfallback = (mAnimQueue.front().mGroup.compare(0, 4, "idle") == 0); bool loopfallback = mAnimQueue.front().mGroup.starts_with("idle");
mAnimation->play(mAnimQueue.front().mGroup, Priority_Default, MWRender::Animation::BlendMask_All, false, mAnimation->play(mAnimQueue.front().mGroup, Priority_Default, MWRender::Animation::BlendMask_All, false,
1.0f, "start", "stop", 0.0f, mAnimQueue.front().mLoopCount, loopfallback); 1.0f, "start", "stop", 0.0f, mAnimQueue.front().mLoopCount, loopfallback);
} }
@ -2463,7 +2463,7 @@ namespace MWMechanics
clearStateAnimation(mCurrentIdle); clearStateAnimation(mCurrentIdle);
mIdleState = CharState_SpecialIdle; mIdleState = CharState_SpecialIdle;
bool loopfallback = (mAnimQueue.front().mGroup.compare(0, 4, "idle") == 0); bool loopfallback = mAnimQueue.front().mGroup.starts_with("idle");
mAnimation->play(anim.mGroup, Priority_Persistent, MWRender::Animation::BlendMask_All, false, 1.0f, "start", mAnimation->play(anim.mGroup, Priority_Persistent, MWRender::Animation::BlendMask_All, false, 1.0f, "start",
"stop", complete, anim.mLoopCount, loopfallback); "stop", complete, anim.mLoopCount, loopfallback);
} }
@ -2513,7 +2513,7 @@ namespace MWMechanics
clearStateAnimation(mCurrentIdle); clearStateAnimation(mCurrentIdle);
mIdleState = CharState_SpecialIdle; mIdleState = CharState_SpecialIdle;
bool loopfallback = (entry.mGroup.compare(0, 4, "idle") == 0); bool loopfallback = entry.mGroup.starts_with("idle");
mAnimation->play(groupname, persist && groupname != "idle" ? Priority_Persistent : Priority_Default, mAnimation->play(groupname, persist && groupname != "idle" ? Priority_Persistent : Priority_Default,
MWRender::Animation::BlendMask_All, false, 1.0f, ((mode == 2) ? "loop start" : "start"), "stop", 0.0f, MWRender::Animation::BlendMask_All, false, 1.0f, ((mode == 2) ? "loop start" : "start"), "stop", 0.0f,
count - 1, loopfallback); count - 1, loopfallback);

View file

@ -611,7 +611,7 @@ namespace MWRender
{ {
model = Misc::ResourceHelpers::correctActorModelPath(model, mSceneManager->getVFS()); model = Misc::ResourceHelpers::correctActorModelPath(model, mSceneManager->getVFS());
std::string kfname = Misc::StringUtils::lowerCase(model); std::string kfname = Misc::StringUtils::lowerCase(model);
if (kfname.size() > 4 && kfname.compare(kfname.size() - 4, 4, ".nif") == 0) if (kfname.size() > 4 && kfname.ends_with(".nif"))
{ {
kfname.replace(kfname.size() - 4, 4, ".kf"); kfname.replace(kfname.size() - 4, 4, ".kf");
if (mSceneManager->getVFS()->exists(kfname)) if (mSceneManager->getVFS()->exists(kfname))

View file

@ -166,17 +166,17 @@ namespace MWRender
Screenshot360Type screenshotMapping = Spherical; Screenshot360Type screenshotMapping = Spherical;
const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video"); const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video");
std::vector<std::string> settingArgs; std::vector<std::string_view> settingArgs;
Misc::StringUtils::split(settingStr, settingArgs); Misc::StringUtils::split(settingStr, settingArgs);
if (settingArgs.size() > 0) if (settingArgs.size() > 0)
{ {
std::string typeStrings[4] = { "spherical", "cylindrical", "planet", "cubemap" }; std::string_view typeStrings[4] = { "spherical", "cylindrical", "planet", "cubemap" };
bool found = false; bool found = false;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
if (settingArgs[0].compare(typeStrings[i]) == 0) if (settingArgs[0] == typeStrings[i])
{ {
screenshotMapping = static_cast<Screenshot360Type>(i); screenshotMapping = static_cast<Screenshot360Type>(i);
found = true; found = true;

View file

@ -125,9 +125,9 @@ namespace MWWorld
Misc::StringUtils::lowerCaseInPlace(mesh); Misc::StringUtils::lowerCaseInPlace(mesh);
if (mesh[slashpos + 1] == 'x') if (mesh[slashpos + 1] == 'x')
{ {
std::string kfname = mesh; if (mesh.size() > 4 && mesh.ends_with(".nif"))
if (kfname.size() > 4 && kfname.compare(kfname.size() - 4, 4, ".nif") == 0)
{ {
std::string kfname = mesh;
kfname.replace(kfname.size() - 4, 4, ".kf"); kfname.replace(kfname.size() - 4, 4, ".kf");
if (mSceneManager->getVFS()->exists(kfname)) if (mSceneManager->getVFS()->exists(kfname))
mPreloadedObjects.insert(mKeyframeManager->get(kfname)); mPreloadedObjects.insert(mKeyframeManager->get(kfname));

View file

@ -33,7 +33,7 @@ namespace MWWorld
{ {
std::string model = Misc::StringUtils::lowerCase(stat.mModel); std::string model = Misc::StringUtils::lowerCase(stat.mModel);
std::replace(model.begin(), model.end(), '/', '\\'); std::replace(model.begin(), model.end(), '/', '\\');
if (model.compare(0, prefix.size(), prefix) != 0) if (!model.starts_with(prefix))
continue; continue;
mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs); mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs);
} }
@ -42,7 +42,7 @@ namespace MWWorld
{ {
std::string model = Misc::StringUtils::lowerCase(stat.mModel); std::string model = Misc::StringUtils::lowerCase(stat.mModel);
std::replace(model.begin(), model.end(), '/', '\\'); std::replace(model.begin(), model.end(), '/', '\\');
if (model.compare(0, prefix.size(), prefix) != 0) if (!model.starts_with(prefix))
continue; continue;
mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs); mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs);
} }

View file

@ -217,7 +217,7 @@ namespace Nif
"Gamebryo File Format", "Gamebryo File Format",
}; };
const bool supportedHeader = std::any_of(verStrings.begin(), verStrings.end(), const bool supportedHeader = std::any_of(verStrings.begin(), verStrings.end(),
[&](const std::string& verString) { return head.compare(0, verString.size(), verString) == 0; }); [&](const std::string& verString) { return head.starts_with(verString); });
if (!supportedHeader) if (!supportedHeader)
throw Nif::Exception("Invalid NIF header: " + head, filename); throw Nif::Exception("Invalid NIF header: " + head, filename);
@ -321,7 +321,7 @@ namespace Nif
} }
// Record separator. Some Havok records in Oblivion do not have it. // Record separator. Some Havok records in Oblivion do not have it.
if (hasRecordSeparators && rec.compare(0, 3, "bhk")) if (hasRecordSeparators && !rec.starts_with("bhk"))
if (nif.getInt()) if (nif.getInt())
Log(Debug::Warning) << "NIFFile Warning: Record number " << i << " out of " << recNum Log(Debug::Warning) << "NIFFile Warning: Record number " << i << " out of " << recNum
<< " is preceded by a non-zero separator. File: " << filename; << " is preceded by a non-zero separator. File: " << filename;

View file

@ -726,13 +726,9 @@ namespace NifOsg
if (isGeometry && !skipMeshes) if (isGeometry && !skipMeshes)
{ {
const std::string nodeName = Misc::StringUtils::lowerCase(nifNode->name); const bool isMarker = hasMarkers && Misc::StringUtils::ciStartsWith(nifNode->name, "tri editormarker");
static const std::string markerName = "tri editormarker"; if (!isMarker && !Misc::StringUtils::ciStartsWith(nifNode->name, "shadow")
static const std::string shadowName = "shadow"; && !Misc::StringUtils::ciStartsWith(nifNode->name, "tri shadow"))
static const std::string shadowName2 = "tri shadow";
const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName);
if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName)
&& nodeName.compare(0, shadowName2.size(), shadowName2))
{ {
Nif::NiSkinInstancePtr skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin; Nif::NiSkinInstancePtr skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin;

View file

@ -783,7 +783,7 @@ namespace Resource
// NPC skeleton files can not be optimized because of keyframes added in post // NPC skeleton files can not be optimized because of keyframes added in post
// (most of them are usually named like 'xbase_anim.nif' anyway, but not all of them :( ) // (most of them are usually named like 'xbase_anim.nif' anyway, but not all of them :( )
if (basename.compare(0, 9, "base_anim") == 0 || basename.compare(0, 4, "skin") == 0) if (basename.starts_with("base_anim") || basename.starts_with("skin"))
return false; return false;
} }

View file

@ -47,25 +47,25 @@ namespace Resource
const auto kw = kwList.substr(std::distance(kwList.begin(), kwBegin), std::distance(kwBegin, kwEnd)); const auto kw = kwList.substr(std::distance(kwList.begin(), kwBegin), std::distance(kwBegin, kwEnd));
if (kw.compare("gpu") == 0) if (kw == "gpu")
collectStatGPU = true; collectStatGPU = true;
else if (kw.compare("event") == 0) else if (kw == "event")
collectStatEvent = true; collectStatEvent = true;
else if (kw.compare("frame_rate") == 0) else if (kw == "frame_rate")
collectStatFrameRate = true; collectStatFrameRate = true;
else if (kw.compare("update") == 0) else if (kw == "update")
collectStatUpdate = true; collectStatUpdate = true;
else if (kw.compare("engine") == 0) else if (kw == "engine")
collectStatEngine = true; collectStatEngine = true;
else if (kw.compare("rendering") == 0) else if (kw == "rendering")
collectStatRendering = true; collectStatRendering = true;
else if (kw.compare("cameraobjects") == 0) else if (kw == "cameraobjects")
collectStatCameraObjects = true; collectStatCameraObjects = true;
else if (kw.compare("viewerobjects") == 0) else if (kw == "viewerobjects")
collectStatViewerObjects = true; collectStatViewerObjects = true;
else if (kw.compare("resource") == 0) else if (kw == "resource")
collectStatResource = true; collectStatResource = true;
else if (kw.compare("times") == 0) else if (kw == "times")
{ {
collectStatGPU = true; collectStatGPU = true;
collectStatEvent = true; collectStatEvent = true;

View file

@ -51,8 +51,7 @@ namespace SceneUtil
bool operator()(const std::multimap<float, std::string>::value_type& value) const bool operator()(const std::multimap<float, std::string>::value_type& value) const
{ {
return value.second.compare(0, mGroupName.size(), mGroupName) == 0 return value.second.starts_with(mGroupName) && value.second.compare(mGroupName.size(), 2, ": ") == 0;
&& value.second.compare(mGroupName.size(), 2, ": ") == 0;
} }
}; };