From 5885d6484af3bac814ebb4bbc0dbede8f93fcedc Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Mon, 13 Jun 2016 20:21:10 +0200 Subject: [PATCH] Fixed cppcheck issue I fixed a complain of cppcheck which discourage using find()==0 This will allow upgrading to latest cppcheck. --- src/core/CLTool.cpp | 2 +- src/core/CLToolMain.cpp | 2 +- src/tools/Tools.cpp | 5 +++++ src/tools/Tools.h | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/CLTool.cpp b/src/core/CLTool.cpp index 8f6b814e2..527e5b6cb 100644 --- a/src/core/CLTool.cpp +++ b/src/core/CLTool.cpp @@ -94,7 +94,7 @@ bool CLTool::readCommandLineArgs( int argc, char**argv, FILE*out ){ if( a==thiskey ){ prefix=thiskey+"="; found=true; inputData.insert(std::pair<std::string,std::string>(thiskey,"")); - } else if( a.find(thiskey+"=")==0){ + } else if(Tools::startWith(a,thiskey+"=")){ a.erase(0,a.find("=")+1); prefix=""; found=true; if(inputData.count(thiskey)==0){ inputData.insert(std::pair<std::string,std::string>(thiskey,a)); diff --git a/src/core/CLToolMain.cpp b/src/core/CLToolMain.cpp index e5eb16190..10fa902b6 100644 --- a/src/core/CLToolMain.cpp +++ b/src/core/CLToolMain.cpp @@ -144,7 +144,7 @@ int CLToolMain::run(int argc, char **argv,FILE*in,FILE*out,Communicator& pc){ } } else if(a=="--standalone-executable"){ standalone_executable=true; - } else if(a.find("--load=")==0){ + } else if(Tools::startWith(a,"--load=")){ a.erase(0,a.find("=")+1); prefix=""; void *p=dlloader.load(a); diff --git a/src/tools/Tools.cpp b/src/tools/Tools.cpp index 3e7063813..c1ffe96f9 100644 --- a/src/tools/Tools.cpp +++ b/src/tools/Tools.cpp @@ -322,4 +322,9 @@ std::string Tools::extension(const std::string&s){ return ext; } +bool Tools::startWith(const std::string & full,const std::string &start){ + return (full.substr(0,start.length())==start); +} + + } diff --git a/src/tools/Tools.h b/src/tools/Tools.h index 99592ce99..f4b00e926 100644 --- a/src/tools/Tools.h +++ b/src/tools/Tools.h @@ -121,6 +121,9 @@ public: static std::string extension(const std::string&); /// Fast int power static double fastpow(double base,int exp); +/// Check if a string full starts with string start. +/// Same as full.find(start)==0 + static bool startWith(const std::string & full,const std::string &start); }; template <class T> -- GitLab