Commit 78d1a2d0 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'string-npos-cleanup'

db2d46e2 Remove second arg: npos in substr usages
8b6f439e Access string npos without instance
389ed56f cmLocalUnixMakefileGenerator3: Remove unnecessary local variable
9fe4a9e2

 cmParseBlanketJSCoverage: Pass unmodified parameter as const&
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !905
parents 0a082be8 db2d46e2
......@@ -811,8 +811,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
for (fit = result.begin(); fit != diff; ++fit) {
localFileName =
cmSystemTools::RelativePath(InstallPrefix, fit->c_str());
localFileName = localFileName.substr(
localFileName.find_first_not_of('/'), std::string::npos);
localFileName =
localFileName.substr(localFileName.find_first_not_of('/'));
Components[installComponent].Files.push_back(localFileName);
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
<< localFileName << "> to component <"
......
......@@ -76,7 +76,7 @@ int cmCPackNSISGenerator::PackageFiles()
}
// Strip off the component part of the path.
fileN = fileN.substr(pos + 1, std::string::npos);
fileN = fileN.substr(pos + 1);
}
std::replace(fileN.begin(), fileN.end(), '/', '\\');
......@@ -106,7 +106,7 @@ int cmCPackNSISGenerator::PackageFiles()
componentName = fileN.substr(0, slash);
// Strip off the component part of the path.
fileN = fileN.substr(slash + 1, std::string::npos);
fileN = fileN.substr(slash + 1);
}
}
std::replace(fileN.begin(), fileN.end(), '/', '\\');
......
......@@ -596,10 +596,10 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
// At this point we need to make this->SourceFile relative to
// the source root of the project, so cvs links will work
cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
if (cm->SourceFile.find("/.../") != cm->SourceFile.npos) {
if (cm->SourceFile.find("/.../") != std::string::npos) {
cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
std::string::size_type p = cm->SourceFile.find('/');
if (p != cm->SourceFile.npos) {
if (p != std::string::npos) {
cm->SourceFile =
cm->SourceFile.substr(p + 1, cm->SourceFile.size() - p);
}
......
......@@ -103,6 +103,7 @@ public:
return this->PipeState;
}
int GetProcessState() { return this->PipeState; }
private:
int PipeState;
cmsysProcess* Process;
......@@ -896,7 +897,7 @@ int cmCTestCoverageHandler::HandleBlanketJSCoverage(
cmsys::ifstream in(files[fileEntry].c_str());
cmSystemTools::GetLineFromStream(in, line);
cmSystemTools::GetLineFromStream(in, line);
if (line.find("node-jscoverage") != line.npos) {
if (line.find("node-jscoverage") != std::string::npos) {
blanketFiles.push_back(files[fileEntry]);
}
}
......@@ -1222,7 +1223,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('#') != std::string::npos) {
vec[lineIdx] = 0;
}
}
......@@ -1524,7 +1525,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('#') != std::string::npos) {
vec[lineIdx] = 0;
}
}
......@@ -2127,7 +2128,7 @@ bool cmCTestCoverageHandler::GetNextInt(std::string const& inputLine,
std::string::size_type start = pos;
pos = inputLine.find(',', start);
value = atoi(inputLine.substr(start, pos).c_str());
if (pos == inputLine.npos) {
if (pos == std::string::npos) {
return true;
}
pos++;
......@@ -2141,7 +2142,7 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine(
{
// find the first comma
std::string::size_type pos = inputLine.find(',');
if (pos == inputLine.npos) {
if (pos == std::string::npos) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error parsing string : " << inputLine << "\n");
return false;
......@@ -2168,7 +2169,7 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine(
return false;
}
// should be at the end now
if (pos != inputLine.npos) {
if (pos != std::string::npos) {
cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing input : "
<< inputLine << " last pos not npos = " << pos << "\n");
}
......
......@@ -191,9 +191,9 @@ bool cmCTestGIT::UpdateByFetchAndReset()
std::string line;
while (sha1.empty() && cmSystemTools::GetLineFromStream(fin, line)) {
this->Log << "FETCH_HEAD> " << line << "\n";
if (line.find("\tnot-for-merge\t") == line.npos) {
if (line.find("\tnot-for-merge\t") == std::string::npos) {
std::string::size_type pos = line.find('\t');
if (pos != line.npos) {
if (pos != std::string::npos) {
sha1 = line.substr(0, pos);
}
}
......
......@@ -801,7 +801,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
std::vector<std::string> lines;
cmSystemTools::Split(str.c_str(), lines);
bool unlimitedOutput = false;
if (str.find("CTEST_FULL_OUTPUT") != str.npos ||
if (str.find("CTEST_FULL_OUTPUT") != std::string::npos ||
this->CustomMaximumFailedTestOutputSize == 0) {
unlimitedOutput = true;
}
......@@ -953,7 +953,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
std::string& theLine = lines[cc];
// check for command line arguments that are not escaped
// correctly by BC
if (theLine.find("TargetArgs=") != theLine.npos) {
if (theLine.find("TargetArgs=") != std::string::npos) {
// skip this because BC gets it wrong and we can't parse it
} else if (!parser.ParseChunk(theLine.c_str(), theLine.size())) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
......
......@@ -596,8 +596,7 @@ void cmCTestRunTest::ComputeArguments()
void cmCTestRunTest::DartProcessing()
{
if (!this->ProcessOutput.empty() &&
this->ProcessOutput.find("<DartMeasurement") !=
this->ProcessOutput.npos) {
this->ProcessOutput.find("<DartMeasurement") != std::string::npos) {
if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str())) {
this->TestResult.DartString = this->TestHandler->DartStuff.match(1);
// keep searching and replacing until none are left
......
......@@ -595,7 +595,7 @@ void cmCTestSubmitHandler::ParseResponse(
std::string output;
output.append(chunk.begin(), chunk.end());
if (output.find("<cdash") != output.npos) {
if (output.find("<cdash") != std::string::npos) {
ResponseParser parser;
parser.Parse(output.c_str());
......
......@@ -225,7 +225,7 @@ public:
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
*/
bool InitialPass(std::vector<std::string> const& /*args*/,
cmExecutionStatus& /*unused*/) CM_OVERRIDE;
......@@ -247,7 +247,7 @@ inline int GetNextNumber(std::string const& in, int& val,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
if (pos2 != in.npos) {
if (pos2 != std::string::npos) {
if (pos2 - pos == 0) {
val = -1;
} else {
......@@ -273,7 +273,7 @@ inline int GetNextRealNumber(std::string const& in, double& val,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
if (pos2 != in.npos) {
if (pos2 != std::string::npos) {
if (pos2 - pos == 0) {
val = -1;
} else {
......@@ -1823,7 +1823,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
std::string::size_type pos;
while (cmSystemTools::GetLineFromStream(ifs, line)) {
pos = line.find(':', 0);
if (pos == line.npos) {
if (pos == std::string::npos) {
continue;
}
......@@ -2027,7 +2027,7 @@ void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
{
if (!length || length >= output.size() ||
output.find("CTEST_FULL_OUTPUT") != output.npos) {
output.find("CTEST_FULL_OUTPUT") != std::string::npos) {
return true;
}
......@@ -2175,7 +2175,7 @@ bool cmCTestTestHandler::SetTestsProperties(
}
if (key == "MEASUREMENT") {
size_t pos = val.find_first_of('=');
if (pos != val.npos) {
if (pos != std::string::npos) {
std::string mKey = val.substr(0, pos);
const char* mVal = val.c_str() + pos + 1;
rtit->Measurements[mKey] = mVal;
......
......@@ -22,7 +22,7 @@ public:
virtual ~JSONParser() {}
std::string getValue(std::string line, int type)
std::string getValue(std::string const& line, int type)
{
size_t begIndex;
size_t endIndex;
......@@ -35,7 +35,7 @@ public:
line.substr(begIndex + 3, endIndex - (begIndex + 4));
return foundFileName;
}
return line.substr(begIndex, line.npos);
return line.substr(begIndex);
}
bool ParseFile(std::string const& file)
{
......@@ -51,13 +51,13 @@ public:
return false;
}
while (cmSystemTools::GetLineFromStream(in, line)) {
if (line.find("filename") != line.npos) {
if (line.find("filename") != std::string::npos) {
if (foundFile) {
/*
* Upon finding a second file name, generate a
* vector within the total coverage to capture the
* information in the local vector
*/
* Upon finding a second file name, generate a
* vector within the total coverage to capture the
* information in the local vector
*/
FileLinesType& CoverageVector =
this->Coverage.TotalCoverage[filename];
CoverageVector = localCoverageVector;
......@@ -66,19 +66,19 @@ public:
foundFile = true;
inSource = false;
filename = getValue(line, 0);
} else if ((line.find("coverage") != line.npos) && foundFile &&
} else if ((line.find("coverage") != std::string::npos) && foundFile &&
inSource) {
/*
* two types of "coverage" in the JSON structure
*
* The coverage result over the file or set of files
* and the coverage for each individual line
*
* FoundFile and foundSource ensure that
* only the value of the line coverage is captured
*/
* two types of "coverage" in the JSON structure
*
* The coverage result over the file or set of files
* and the coverage for each individual line
*
* FoundFile and foundSource ensure that
* only the value of the line coverage is captured
*/
std::string result = getValue(line, 1);
result = result.substr(2, result.npos);
result = result.substr(2);
if (result == "\"\"") {
// Empty quotation marks indicate that the
// line is not executable
......@@ -87,7 +87,7 @@ public:
// Else, it contains the number of time executed
localCoverageVector.push_back(atoi(result.c_str()));
}
} else if (line.find("source") != line.npos) {
} else if (line.find("source") != std::string::npos) {
inSource = true;
}
}
......
......@@ -42,18 +42,20 @@ public:
size_t beginPos = line.find("begin");
// Check that the begin is the first non-space string on the line
if ((beginPos == line.find_first_not_of(' ')) && beginPos != line.npos) {
if ((beginPos == line.find_first_not_of(' ')) &&
beginPos != std::string::npos) {
beginSet.push_back("begin");
coverageVector.push_back(-1);
continue;
}
if (line.find('{') != line.npos) {
if (line.find('{') != std::string::npos) {
blockComFlag = true;
} else if (line.find('}') != line.npos) {
} else if (line.find('}') != std::string::npos) {
blockComFlag = false;
coverageVector.push_back(-1);
continue;
} else if ((line.find("end;") != line.npos) && !beginSet.empty()) {
} else if ((line.find("end;") != std::string::npos) &&
!beginSet.empty()) {
beginSet.pop_back();
coverageVector.push_back(-1);
continue;
......@@ -62,7 +64,7 @@ public:
// This checks for comments after lines of code, finding the
// comment symbol after the ending semicolon.
comPos = line.find("//");
if (comPos != line.npos) {
if (comPos != std::string::npos) {
semiPos = line.find(';');
if (comPos < semiPos) {
lineComFlag = true;
......@@ -91,20 +93,20 @@ public:
size_t pos = 0;
/*
* This first 'while' section goes through the found HTML
* file name and attempts to capture the source file name
* which is set as part of the HTML file name: the name of
* the file is found in parenthesis '()'
*
* See test HTML file name: UTCovTest(UTCovTest.pas).html.
*
* Find the text inside each pair of parenthesis and check
* to see if it ends in '.pas'. If it can't be found,
* exit the function.
*/
* This first 'while' section goes through the found HTML
* file name and attempts to capture the source file name
* which is set as part of the HTML file name: the name of
* the file is found in parenthesis '()'
*
* See test HTML file name: UTCovTest(UTCovTest.pas).html.
*
* Find the text inside each pair of parenthesis and check
* to see if it ends in '.pas'. If it can't be found,
* exit the function.
*/
while (true) {
lastoffset = line.find('(', pos);
if (lastoffset == line.npos) {
if (lastoffset == std::string::npos) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, endnamepos
<< "File not found " << lastoffset << std::endl,
this->Coverage.Quiet);
......@@ -112,7 +114,7 @@ public:
}
endnamepos = line.find(')', lastoffset);
filename = line.substr(lastoffset + 1, (endnamepos - 1) - lastoffset);
if (filename.find(".pas") != filename.npos) {
if (filename.find(".pas") != std::string::npos) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Coverage found for file: " << filename
<< std::endl,
......@@ -122,9 +124,9 @@ public:
pos = lastoffset + 1;
}
/*
* Glob through the source directory for the
* file found above
*/
* Glob through the source directory for the
* file found above
*/
cmsys::Glob gl;
gl.RecurseOn();
gl.RecurseThroughSymlinksOff();
......@@ -133,9 +135,9 @@ public:
std::vector<std::string> const& files = gl.GetFiles();
if (files.empty()) {
/*
* If that doesn't find any matching files
* return a failure.
*/
* If that doesn't find any matching files
* return a failure.
*/
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Unable to find file matching" << glob << std::endl,
this->Coverage.Quiet);
......@@ -144,9 +146,9 @@ public:
FileLinesType& coverageVector = this->Coverage.TotalCoverage[files[0]];
/*
* Initialize the file to have all code between 'begin' and
* 'end' tags marked as executable
*/
* Initialize the file to have all code between 'begin' and
* 'end' tags marked as executable
*/
this->initializeDelphiFile(files[0], coverageVector);
......@@ -156,19 +158,19 @@ public:
}
/*
* Now read the HTML file, looking for the lines that have an
* "inline" in it. Then parse out the "class" value of that
* line to determine if the line is executed or not.
*
* Sample HTML line:
*
* <tr class="covered"><td>47</td><td><pre style="display:inline;">
* &nbsp;CheckEquals(1,2-1);</pre></td></tr>
*
*/
* Now read the HTML file, looking for the lines that have an
* "inline" in it. Then parse out the "class" value of that
* line to determine if the line is executed or not.
*
* Sample HTML line:
*
* <tr class="covered"><td>47</td><td><pre style="display:inline;">
* &nbsp;CheckEquals(1,2-1);</pre></td></tr>
*
*/
while (cmSystemTools::GetLineFromStream(in, line)) {
if (line.find("inline") == line.npos) {
if (line.find("inline") == std::string::npos) {
continue;
}
......
......@@ -56,7 +56,7 @@ bool cmParseGTMCoverage::ReadMCovFile(const char* file)
int lastoffset = 0;
while (cmSystemTools::GetLineFromStream(in, line)) {
// only look at lines that have coverage data
if (line.find("^ZZCOVERAGE") == line.npos) {
if (line.find("^ZZCOVERAGE") == std::string::npos) {
continue;
}
std::string filepath;
......@@ -199,7 +199,7 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
// now parse the right hand side of the =
pos = line.find('=');
// no = found, this is an error
if (pos == line.npos) {
if (pos == std::string::npos) {
return false;
}
pos++; // move past =
......
......@@ -1050,7 +1050,7 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr)
const char* curField = lbl->GetValue();
if (curField) {
std::string cfld = cmSystemTools::LowerCase(curField);
if (cfld.find(str) != cfld.npos && findex != start_index) {
if (cfld.find(str) != std::string::npos && findex != start_index) {
break;
}
}
......
......@@ -369,7 +369,7 @@ bool cmAddCustomCommandCommand::CheckOutputs(
// Make sure the output file name has no invalid characters.
std::string::size_type pos = o->find_first_of("#<>");
if (pos != o->npos) {
if (pos != std::string::npos) {
std::ostringstream msg;
msg << "called with OUTPUT containing a \"" << (*o)[pos]
<< "\". This character is not allowed.";
......
......@@ -27,7 +27,7 @@ bool cmAddCustomTargetCommand::InitialPass(
std::string const& targetName = args[0];
// Check the target name.
if (targetName.find_first_of("/\\") != targetName.npos) {
if (targetName.find_first_of("/\\") != std::string::npos) {
std::ostringstream e;
e << "called with invalid target name \"" << targetName
<< "\". Target names may not contain a slash. "
......@@ -144,7 +144,7 @@ bool cmAddCustomTargetCommand::InitialPass(
}
std::string::size_type pos = targetName.find_first_of("#<>");
if (pos != targetName.npos) {
if (pos != std::string::npos) {
std::ostringstream msg;
msg << "called with target name containing a \"" << targetName[pos]
<< "\". This character is not allowed.";
......
......@@ -119,10 +119,10 @@ std::string cmCTest::CleanString(const std::string& str)
{
std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
if (spos == str.npos) {
if (spos == std::string::npos) {
return std::string();
}
if (epos != str.npos) {
if (epos != std::string::npos) {
epos = epos - spos + 1;
}
return str.substr(spos, epos);
......@@ -669,12 +669,11 @@ bool cmCTest::UpdateCTestConfiguration()
continue;
}
std::string::size_type cpos = line.find_first_of(':');
if (cpos == line.npos) {
if (cpos == std::string::npos) {
continue;
}
std::string key = line.substr(0, cpos);
std::string value =
cmCTest::CleanString(line.substr(cpos + 1, line.npos));
std::string value = cmCTest::CleanString(line.substr(cpos + 1));
this->CTestConfiguration[key] = value;
}
fin.close();
......@@ -1241,7 +1240,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
//
const char* disallowed = "\\:*?\"<>|\n\r\t\f\v";
if (safevalue.find_first_of(disallowed) != value.npos) {
if (safevalue.find_first_of(disallowed) != std::string::npos) {
std::string::size_type i = 0;
std::string::size_type n = strlen(disallowed);
char replace[2];
......@@ -2349,8 +2348,8 @@ std::string cmCTest::GetShortPathToFile(const char* cfname)
cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
// If any contains "." it is not parent directory
bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
bool inBld = bldRelpath.find("..") == bldRelpath.npos;
bool inSrc = srcRelpath.find("..") == std::string::npos;
bool inBld = bldRelpath.find("..") == std::string::npos;
// TODO: Handle files with .. in their name
std::string* res = CM_NULLPTR;
......@@ -2509,7 +2508,7 @@ void cmCTest::AddSubmitFile(Part part, const char* name)
void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
{
size_t epos = overStr.find('=');
if (epos == overStr.npos) {
if (epos == std::string::npos) {
cmCTestLog(this, ERROR_MESSAGE,
"CTest configuration overwrite specified in the wrong format."
<< std::endl
......@@ -2518,7 +2517,7 @@ void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
return;
}
std::string key = overStr.substr(0, epos);
std::string value = overStr.substr(epos + 1, overStr.npos);
std::string value = overStr.substr(epos + 1);
this->CTestConfigurationOverwrites[key] = value;
}
......
......@@ -387,7 +387,7 @@ void cmCacheManager::OutputKey(std::ostream& fout, std::string const& key)
{
// support : in key name by double quoting
const char* q =
(key.find(':') != key.npos || key.find("//") == 0) ? "\"" : "";
(key.find(':') != std::string::npos || key.find("//") == 0) ? "\"" : "";
fout << q << key << q;
}
......@@ -490,7 +490,7 @@ void cmCacheManager::AddCacheEntry(const std::string& key, const char* value,
e.Type = type;
// make sure we only use unix style paths
if (type == cmStateEnums::FILEPATH || type == cmStateEnums::PATH) {
if (e.Value.find(';') != e.Value.npos) {
if (e.Value.find(';') != std::string::npos) {
std::vector<std::string> paths;
cmSystemTools::ExpandListArgument(e.Value, paths);
const char* sep = "";
......
......@@ -1033,8 +1033,8 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
// See documentation of CMP0008.
std::string generator = this->GlobalGenerator->GetName();
if (this->Target->GetPolicyStatusCMP0008() != cmPolicies::NEW &&
(generator.find("Visual Studio") != generator.npos ||
generator.find("Xcode") != generator.npos)) {
(generator.find("Visual Studio") != std::string::npos ||
generator.find("Xcode") != std::string::npos)) {
std::string file = cmSystemTools::GetFilenameName(item);
if (!this->ExtractAnyLibraryName.find(file.c_str())) {
this->HandleBadFullItem(item, file);
......
......@@ -672,7 +672,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
fprintf(fout, " \"%s\"", si->c_str());
// Add dependencies on any non-temporary sources.
if (si->find("CMakeTmp") == si->npos) {
if (si->find("CMakeTmp") == std::string::npos) {
this->Makefile->AddCMakeDependFile(*si);
}
}
......