summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2016-05-24 21:24:10 +0200
committerDaniel Pfeifer <daniel@pfeifer-mail.de>2016-05-24 23:22:24 +0200
commit5784747d1b0404a0c1cb0223b15b823476023fba (patch)
tree763d07bbde561ad1a2322328764b93b6c1852db2
parent5cec953e6aafd4c132a7b6c0a929d95c1dee79ea (diff)
downloadcmake-5784747d1b0404a0c1cb0223b15b823476023fba.tar.gz
Improve string find: prefer character overloads.
Apply fix-its from clang-tidy's performance-faster-string-find checker. Ignore findings in kwsys.
-rw-r--r--Source/CPack/IFW/cmCPackIFWPackage.cxx6
-rw-r--r--Source/CPack/cpack.cxx2
-rw-r--r--Source/CTest/cmCTestBuildHandler.cxx2
-rw-r--r--Source/CTest/cmCTestCoverageHandler.cxx4
-rw-r--r--Source/CTest/cmCTestSubmitHandler.cxx4
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx2
-rw-r--r--Source/CTest/cmParseDelphiCoverage.cxx2
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx2
-rw-r--r--Source/cmCTest.cxx4
-rw-r--r--Source/cmDependsFortran.cxx2
-rw-r--r--Source/cmExportFileGenerator.cxx8
-rw-r--r--Source/cmGeneratorExpression.cxx4
-rw-r--r--Source/cmGeneratorTarget.cxx2
-rw-r--r--Source/cmLocalGenerator.cxx8
-rw-r--r--Source/cmLocalNinjaGenerator.cxx2
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx10
-rw-r--r--Source/cmMakefileTargetGenerator.cxx6
-rw-r--r--Source/cmSystemTools.cxx2
-rw-r--r--Source/cmcmd.cxx2
19 files changed, 37 insertions, 37 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx
index df612e506a..ad153d1aa1 100644
--- a/Source/CPack/IFW/cmCPackIFWPackage.cxx
+++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx
@@ -56,13 +56,13 @@ cmCPackIFWPackage::DependenceStruct::DependenceStruct(
} else if ((pos = dependence.find(">=")) != std::string::npos) {
Compare.Type = CompareGreaterOrEqual;
Compare.Value = dependence.substr(pos + 2);
- } else if ((pos = dependence.find("<")) != std::string::npos) {
+ } else if ((pos = dependence.find('<')) != std::string::npos) {
Compare.Type = CompareLess;
Compare.Value = dependence.substr(pos + 1);
- } else if ((pos = dependence.find("=")) != std::string::npos) {
+ } else if ((pos = dependence.find('=')) != std::string::npos) {
Compare.Type = CompareEqual;
Compare.Value = dependence.substr(pos + 1);
- } else if ((pos = dependence.find(">")) != std::string::npos) {
+ } else if ((pos = dependence.find('>')) != std::string::npos) {
Compare.Type = CompareGreater;
Compare.Value = dependence.substr(pos + 1);
}
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index e54be2c4ec..10f60b20ba 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -68,7 +68,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
(void)argument;
cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data);
std::string value = cValue;
- size_t pos = value.find_first_of("=");
+ size_t pos = value.find_first_of('=');
if (pos == std::string::npos) {
cmCPack_Log(def->Log, cmCPackLog::LOG_ERROR,
"Please specify CPack definitions as: KEY=VALUE" << std::endl);
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx
index 20b0e9cce5..7141daf768 100644
--- a/Source/CTest/cmCTestBuildHandler.cxx
+++ b/Source/CTest/cmCTestBuildHandler.cxx
@@ -617,7 +617,7 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
if (cm->SourceFile.find("/.../") != cm->SourceFile.npos) {
cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
- std::string::size_type p = cm->SourceFile.find("/");
+ std::string::size_type p = cm->SourceFile.find('/');
if (p != cm->SourceFile.npos) {
cm->SourceFile =
cm->SourceFile.substr(p + 1, cm->SourceFile.size() - p);
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
index 550a7742ec..51456ed2b1 100644
--- a/Source/CTest/cmCTestCoverageHandler.cxx
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -1238,7 +1238,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
// Initially all entries are -1 (not used). If we get coverage
// information, increment it to 0 first.
if (vec[lineIdx] < 0) {
- if (cov > 0 || prefix.find("#") != prefix.npos) {
+ if (cov > 0 || prefix.find('#') != prefix.npos) {
vec[lineIdx] = 0;
}
}
@@ -1543,7 +1543,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
// Initially all entries are -1 (not used). If we get coverage
// information, increment it to 0 first.
if (vec[lineIdx] < 0) {
- if (cov > 0 || prefix.find("#") != prefix.npos) {
+ if (cov > 0 || prefix.find('#') != prefix.npos) {
vec[lineIdx] = 0;
}
}
diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx
index bbc6b37de3..f373348674 100644
--- a/Source/CTest/cmCTestSubmitHandler.cxx
+++ b/Source/CTest/cmCTestSubmitHandler.cxx
@@ -417,7 +417,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
}
}
std::string upload_as = url +
- ((url.find("?", 0) == std::string::npos) ? "?" : "&") + "FileName=" +
+ ((url.find('?') == std::string::npos) ? '?' : '&') + "FileName=" +
ofile;
upload_as += "&MD5=";
@@ -706,7 +706,7 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set<std::string>& files,
}
}
std::string turl = url +
- ((url.find("?", 0) == std::string::npos) ? "?" : "&") + "xmlfile=" +
+ ((url.find('?') == std::string::npos) ? '?' : '&') + "xmlfile=" +
ofile;
*this->LogFile << "Trigger url: " << turl << std::endl;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 4935f11c02..20ef6930d0 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -1869,7 +1869,7 @@ bool cmCTestTestHandler::SetTestsProperties(
cmSystemTools::ExpandListArgument(val, rtit->Labels);
}
if (key == "MEASUREMENT") {
- size_t pos = val.find_first_of("=");
+ size_t pos = val.find_first_of('=');
if (pos != val.npos) {
std::string mKey = val.substr(0, pos);
const char* mVal = val.c_str() + pos + 1;
diff --git a/Source/CTest/cmParseDelphiCoverage.cxx b/Source/CTest/cmParseDelphiCoverage.cxx
index d20b16a784..2e06078bac 100644
--- a/Source/CTest/cmParseDelphiCoverage.cxx
+++ b/Source/CTest/cmParseDelphiCoverage.cxx
@@ -171,7 +171,7 @@ public:
}
lastoffset = line.find("class=");
- endcovpos = line.find(">", lastoffset);
+ endcovpos = line.find('>', lastoffset);
lineresult = line.substr(lastoffset + 7, (endcovpos - 8) - lastoffset);
if (lineresult == "covered") {
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 7368560f02..b740eb0b2b 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -729,7 +729,7 @@ void cmCursesMainForm::FillCacheManagerFromUI()
void cmCursesMainForm::FixValue(cmState::CacheEntryType type,
const std::string& in, std::string& out) const
{
- out = in.substr(0, in.find_last_not_of(" ") + 1);
+ out = in.substr(0, in.find_last_not_of(' ') + 1);
if (type == cmState::PATH || type == cmState::FILEPATH) {
cmSystemTools::ConvertToUnixSlashes(out);
}
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 7e5d966af4..64e80783fe 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -721,7 +721,7 @@ bool cmCTest::UpdateCTestConfiguration()
if (line[0] == '#') {
continue;
}
- std::string::size_type cpos = line.find_first_of(":");
+ std::string::size_type cpos = line.find_first_of(':');
if (cpos == line.npos) {
continue;
}
@@ -2480,7 +2480,7 @@ void cmCTest::AddSubmitFile(Part part, const char* name)
void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
{
- size_t epos = overStr.find("=");
+ size_t epos = overStr.find('=');
if (epos == overStr.npos) {
cmCTestLog(this, ERROR_MESSAGE,
"CTest configuration overwrite specified in the wrong format."
diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx
index b8af17870a..c595ada009 100644
--- a/Source/cmDependsFortran.cxx
+++ b/Source/cmDependsFortran.cxx
@@ -77,7 +77,7 @@ cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
for (std::vector<std::string>::const_iterator it = definitions.begin();
it != definitions.end(); ++it) {
std::string def = *it;
- std::string::size_type assignment = def.find("=");
+ std::string::size_type assignment = def.find('=');
if (assignment != std::string::npos) {
def = it->substr(0, assignment);
}
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 2d645da2e2..736c7da7bf 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -608,8 +608,8 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.npos) {
std::string::size_type nameStartPos =
pos + sizeof("$<TARGET_PROPERTY:") - 1;
- std::string::size_type closePos = input.find(">", nameStartPos);
- std::string::size_type commaPos = input.find(",", nameStartPos);
+ std::string::size_type closePos = input.find('>', nameStartPos);
+ std::string::size_type commaPos = input.find(',', nameStartPos);
std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
if (commaPos == input.npos // Implied 'this' target
|| closePos == input.npos // Imcomplete expression.
@@ -634,7 +634,7 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
lastPos = pos;
while ((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos) {
std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
- std::string::size_type endPos = input.find(">", nameStartPos);
+ std::string::size_type endPos = input.find('>', nameStartPos);
if (endPos == input.npos) {
errorString = "$<TARGET_NAME:...> expression incomplete";
break;
@@ -659,7 +659,7 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
while (errorString.empty() &&
(pos = input.find("$<LINK_ONLY:", lastPos)) != input.npos) {
std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1;
- std::string::size_type endPos = input.find(">", nameStartPos);
+ std::string::size_type endPos = input.find('>', nameStartPos);
if (endPos == input.npos) {
errorString = "$<LINK_ONLY:...> expression incomplete";
break;
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index 002f9ecf46..53243b8e69 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -300,7 +300,7 @@ void cmGeneratorExpression::Split(const std::string& input,
std::string part = input.substr(lastPos, pos - lastPos);
std::string preGenex;
if (!part.empty()) {
- std::string::size_type startPos = input.rfind(";", pos);
+ std::string::size_type startPos = input.rfind(';', pos);
if (startPos == std::string::npos) {
preGenex = part;
part = "";
@@ -364,7 +364,7 @@ std::string::size_type cmGeneratorExpression::Find(const std::string& input)
{
const std::string::size_type openpos = input.find("$<");
if (openpos != std::string::npos &&
- input.find(">", openpos) != std::string::npos) {
+ input.find('>', openpos) != std::string::npos) {
return openpos;
}
return std::string::npos;
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 31fff9f298..f30bb8b02a 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -145,7 +145,7 @@ struct DoAccept<true>
// where the user supplied the file name and Visual Studio
// appended the suffix.
std::string resx = f->GetFullPath();
- std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
+ std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
data.ExpectedResxHeaders.insert(hFileName);
data.ResxSources.push_back(f);
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 4a52f5149a..2648bf4b91 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -640,7 +640,7 @@ std::string cmLocalGenerator::ExpandRuleVariable(
if (variable == "TARGET_BASE") {
// Strip the last extension off the target name.
std::string targetBase = replaceValues.Target;
- std::string::size_type pos = targetBase.rfind(".");
+ std::string::size_type pos = targetBase.rfind('.');
if (pos != targetBase.npos) {
return targetBase.substr(0, pos);
} else {
@@ -2306,7 +2306,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
std::string ssin = sin;
// Avoid full paths by removing leading slashes.
- ssin.erase(0, ssin.find_first_not_of("/"));
+ ssin.erase(0, ssin.find_first_not_of('/'));
// Avoid full paths by removing colons.
std::replace(ssin.begin(), ssin.end(), ':', '_');
@@ -2464,7 +2464,7 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
// Remove the source extension if it is to be replaced.
if (replaceExt) {
keptSourceExtension = false;
- std::string::size_type dot_pos = objectName.rfind(".");
+ std::string::size_type dot_pos = objectName.rfind('.');
if (dot_pos != std::string::npos) {
objectName = objectName.substr(0, dot_pos);
}
@@ -2603,7 +2603,7 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
}
// Many compilers do not support # in the value so we disable it.
- if (define.find_first_of("#") != define.npos) {
+ if (define.find_first_of('#') != define.npos) {
std::ostringstream e;
/* clang-format off */
e << "WARNING: Preprocessor definitions containing '#' may not be "
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index c7e1a90f8b..d0b667f392 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -205,7 +205,7 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os)
cmSystemTools::ExpandListArgument(jobpools, pools);
for (size_t i = 0; i < pools.size(); ++i) {
const std::string pool = pools[i];
- const std::string::size_type eq = pool.find("=");
+ const std::string::size_type eq = pool.find('=');
unsigned int jobs;
if (eq != std::string::npos &&
sscanf(pool.c_str() + eq, "=%u", &jobs) == 1) {
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index defac95533..46891b7a98 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -71,7 +71,7 @@ private:
static std::string cmSplitExtension(std::string const& in, std::string& base)
{
std::string ext;
- std::string::size_type dot_pos = in.rfind(".");
+ std::string::size_type dot_pos = in.rfind('.');
if (dot_pos != std::string::npos) {
// Remove the extension first in case &base == &in.
ext = in.substr(dot_pos, std::string::npos);
@@ -949,11 +949,11 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
cmSystemTools::ReplaceString(cmd, "/./", "/");
// Convert the command to a relative path only if the current
// working directory will be the start-output directory.
- bool had_slash = cmd.find("/") != cmd.npos;
+ bool had_slash = cmd.find('/') != cmd.npos;
if (workingDir.empty()) {
cmd = this->Convert(cmd, START_OUTPUT);
}
- bool has_slash = cmd.find("/") != cmd.npos;
+ bool has_slash = cmd.find('/') != cmd.npos;
if (had_slash && !has_slash) {
// This command was specified as a path to a file in the
// current directory. Add a leading "./" so it can run
@@ -975,9 +975,9 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// must be written {{} instead of just {. Otherwise some
// curly braces are removed. The hack can be skipped if the
// first curly brace is the last character.
- std::string::size_type lcurly = cmd.find("{");
+ std::string::size_type lcurly = cmd.find('{');
if (lcurly != cmd.npos && lcurly < (cmd.size() - 1)) {
- std::string::size_type rcurly = cmd.find("}");
+ std::string::size_type rcurly = cmd.find('}');
if (rcurly == cmd.npos || rcurly > lcurly) {
// The first curly is a left curly. Use the hack.
std::string hack_cmd = cmd.substr(0, lcurly);
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index e4801406c0..c67170dee4 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -661,9 +661,9 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
if (do_preprocess_rules || do_assembly_rules) {
std::vector<std::string> force_depends;
force_depends.push_back("cmake_force");
- std::string::size_type dot_pos = relativeObj.rfind(".");
+ std::string::size_type dot_pos = relativeObj.rfind('.');
std::string relativeObjBase = relativeObj.substr(0, dot_pos);
- dot_pos = obj.rfind(".");
+ dot_pos = obj.rfind('.');
std::string objBase = obj.substr(0, dot_pos);
if (do_preprocess_rules) {
@@ -1479,7 +1479,7 @@ void cmMakefileTargetGenerator::CreateLinkLibs(
useResponseFile, useWatcomQuote);
linkLibs = frameworkPath + linkPath + linkLibs;
- if (useResponseFile && linkLibs.find_first_not_of(" ") != linkLibs.npos) {
+ if (useResponseFile && linkLibs.find_first_not_of(' ') != linkLibs.npos) {
// Lookup the response file reference flag.
std::string responseFlagVar = "CMAKE_";
responseFlagVar +=
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ed83069679..52278d0b7e 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1298,7 +1298,7 @@ cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment()
eit != currentEnv.end(); ++eit) {
std::string var(*eit);
- std::string::size_type pos = var.find("=");
+ std::string::size_type pos = var.find('=');
if (pos != std::string::npos) {
var = var.substr(0, pos);
}
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 891b291daa..a7718d2202 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -386,7 +386,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::cerr << "cmake -E env: unknown option '" << a << "'"
<< std::endl;
return 1;
- } else if (a.find("=") != a.npos) {
+ } else if (a.find('=') != a.npos) {
// Set environment variable.
cmSystemTools::PutEnv(a);
} else {