1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02:00

Replace strcasecmp with boost::iequals

This commit is contained in:
Jannik Vogel 2016-08-09 14:03:38 +02:00
parent cb347143f8
commit 571fd08631
4 changed files with 11 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
// Yet another hack function to fix these paths // Yet another hack function to fix these paths
std::string fixPath(std::string path) { std::string fixPath(std::string path) {
@ -159,17 +160,15 @@ bool GameData::loadObjects(const std::string& name)
return false; return false;
} }
#include <strings.h>
uint16_t GameData::findModelObject(const std::string model) uint16_t GameData::findModelObject(const std::string model)
{ {
// Dear C++ Why do I have to resort to strcasecmp this isn't C.
auto defit = std::find_if(objectTypes.begin(), objectTypes.end(), auto defit = std::find_if(objectTypes.begin(), objectTypes.end(),
[&](const decltype(objectTypes)::value_type& d) [&](const decltype(objectTypes)::value_type& d)
{ {
if(d.second->class_type == ObjectInformation::_class("OBJS")) if(d.second->class_type == ObjectInformation::_class("OBJS"))
{ {
auto dat = static_cast<ObjectData*>(d.second.get()); auto dat = static_cast<ObjectData*>(d.second.get());
return strcasecmp(dat->modelName.c_str(), model.c_str()) == 0; return boost::iequals(dat->modelName, model);
} }
return false; return false;
}); });

View File

@ -1,3 +1,5 @@
find_package(Boost REQUIRED)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" @ONLY)
set(RWGAME_SOURCES set(RWGAME_SOURCES

View File

@ -25,6 +25,8 @@
#include <objects/CharacterObject.hpp> #include <objects/CharacterObject.hpp>
#include <objects/VehicleObject.hpp> #include <objects/VehicleObject.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "GitSHA1.h" #include "GitSHA1.h"
// Use first 8 chars of git hash as the build string // Use first 8 chars of git hash as the build string
@ -53,15 +55,15 @@ RWGame::RWGame(int argc, char* argv[])
for( int i = 1; i < argc; ++i ) for( int i = 1; i < argc; ++i )
{ {
if( strcasecmp( "-w", argv[i] ) == 0 && i+1 < argc ) if( boost::iequals( "-w", argv[i] ) && i+1 < argc )
{ {
w = std::atoi(argv[i+1]); w = std::atoi(argv[i+1]);
} }
if( strcasecmp( "-h", argv[i] ) == 0 && i+1 < argc ) if( boost::iequals( "-h", argv[i] ) && i+1 < argc )
{ {
h = std::atoi(argv[i+1]); h = std::atoi(argv[i+1]);
} }
if( strcasecmp( "-f", argv[i] ) == 0 ) if( boost::iequals( "-f", argv[i] ))
{ {
fullscreen = true; fullscreen = true;
} }

View File

@ -1,6 +1,6 @@
#include <loaders/LoaderIMG.hpp> #include <loaders/LoaderIMG.hpp>
#include <cstring> #include <boost/algorithm/string/predicate.hpp>
LoaderIMG::LoaderIMG() LoaderIMG::LoaderIMG()
: m_version(GTAIIIVC) : m_version(GTAIIIVC)
@ -50,7 +50,7 @@ bool LoaderIMG::findAssetInfo(const std::string& assetname, LoaderIMGFile& out)
{ {
for(size_t i = 0; i < m_assets.size(); ++i) for(size_t i = 0; i < m_assets.size(); ++i)
{ {
if(strcasecmp(m_assets[i].name, assetname.c_str()) == 0) if(boost::iequals(m_assets[i].name, assetname))
{ {
out = m_assets[i]; out = m_assets[i];
return true; return true;