Commit 6052e4b3 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'improve-character-find-and-replace'

5784747d Improve string find: prefer character overloads.
5cec953e Use std::replace for replacing chars in strings.
2a1a2033 cmExtraEclipseCDT4Generator: use std::replace.
34bc6e1f cmCTestScriptHandler: don't call find repeatedly.
parents 9ebc2092 5784747d
......@@ -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);
}
......
......@@ -74,7 +74,7 @@ int cmCPackNSISGenerator::PackageFiles()
// Strip off the component part of the path.
fileN = fileN.substr(fileN.find('/') + 1, std::string::npos);
}
cmSystemTools::ReplaceString(fileN, "/", "\\");
std::replace(fileN.begin(), fileN.end(), '/', '\\');
str << " Delete \"$INSTDIR\\" << fileN << "\"" << std::endl;
}
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str()
......@@ -104,7 +104,7 @@ int cmCPackNSISGenerator::PackageFiles()
fileN = fileN.substr(slash + 1, std::string::npos);
}
}
cmSystemTools::ReplaceString(fileN, "/", "\\");
std::replace(fileN.begin(), fileN.end(), '/', '\\');
dstr << " RMDir \"$INSTDIR\\" << fileN << "\"" << std::endl;
if (!componentName.empty()) {
this->Components[componentName].Directories.push_back(fileN);
......@@ -548,7 +548,7 @@ void cmCPackNSISGenerator::CreateMenuLinks(std::ostringstream& str,
// Convert / to \ in filenames, but not in urls:
//
if (!url) {
cmSystemTools::ReplaceString(sourceName, "/", "\\");
std::replace(sourceName.begin(), sourceName.end(), '/', '\\');
}
++it;
......@@ -790,13 +790,13 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
for (pathIt = component->Files.begin(); pathIt != component->Files.end();
++pathIt) {
path = *pathIt;
cmSystemTools::ReplaceString(path, "/", "\\");
std::replace(path.begin(), path.end(), '/', '\\');
macrosOut << " Delete \"$INSTDIR\\" << path << "\"\n";
}
for (pathIt = component->Directories.begin();
pathIt != component->Directories.end(); ++pathIt) {
path = *pathIt;
cmSystemTools::ReplaceString(path, "/", "\\");
std::replace(path.begin(), path.end(), '/', '\\');
macrosOut << " RMDir \"$INSTDIR\\" << path << "\"\n";
}
macrosOut << " noremove_" << component->Name << ":\n";
......
......@@ -34,13 +34,13 @@ int cmCPackRPMGenerator::InitializeInternal()
*/
if (this->GetOption("CPACK_PACKAGE_NAME")) {
std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
cmSystemTools::ReplaceString(packageName, " ", "-");
std::replace(packageName.begin(), packageName.end(), ' ', '-');
this->SetOption("CPACK_PACKAGE_NAME", packageName.c_str());
}
/* same for CPACK_PACKAGE_FILE_NAME */
if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
std::string packageName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
cmSystemTools::ReplaceString(packageName, " ", "-");
std::replace(packageName.begin(), packageName.end(), ' ', '-');
this->SetOption("CPACK_PACKAGE_FILE_NAME", packageName.c_str());
}
return this->Superclass::InitializeInternal();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -330,9 +330,10 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
// passed into the scripts as S_ARG
std::string script = total_script_arg;
std::string script_arg;
if (total_script_arg.find(",") != std::string::npos) {
script = total_script_arg.substr(0, total_script_arg.find(","));
script_arg = total_script_arg.substr(total_script_arg.find(",") + 1);
const std::string::size_type comma_pos = total_script_arg.find(',');
if (comma_pos != std::string::npos) {
script = total_script_arg.substr(0, comma_pos);
script_arg = total_script_arg.substr(comma_pos + 1);
}
// make sure the file exists
if (!cmSystemTools::FileExists(script.c_str())) {
......
......@@ -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,
......
......@@ -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;
......
......@@ -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") {
......
......@@ -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);
}
......
......@@ -32,9 +32,9 @@ bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
cmsys::RegularExpression reg("[()/]");
if (reg.find(cacheValue)) {
std::string cv = cacheValue;
cmSystemTools::ReplaceString(cv, "/", "_");
cmSystemTools::ReplaceString(cv, "(", "_");
cmSystemTools::ReplaceString(cv, ")", "_");
std::replace(cv.begin(), cv.end(), '/', '_');
std::replace(cv.begin(), cv.end(), '(', '_');
std::replace(cv.begin(), cv.end(), ')', '_');
this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
cmState::STRING);
}
......@@ -57,9 +57,9 @@ bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
this->Makefile->ExpandVariablesInString(compiler);
buildname += "-";
buildname += cmSystemTools::GetFilenameName(compiler);
cmSystemTools::ReplaceString(buildname, "/", "_");
cmSystemTools::ReplaceString(buildname, "(", "_");
cmSystemTools::ReplaceString(buildname, ")", "_");
std::replace(buildname.begin(), buildname.end(), '/', '_');
std::replace(buildname.begin(), buildname.end(), '(', '_');
std::replace(buildname.begin(), buildname.end(), ')', '_');
this->Makefile->AddCacheDefinition(args[0], buildname.c_str(),
"Name of build.", cmState::STRING);
......
......@@ -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."
......
......@@ -95,9 +95,9 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
cmSystemTools::ConvertToUnixSlashes(func_name);
cmSystemTools::ReplaceString(func_name, " ", "_");
cmSystemTools::ReplaceString(func_name, "/", "_");
cmSystemTools::ReplaceString(func_name, ":", "_");
std::replace(func_name.begin(), func_name.end(), ' ', '_');
std::replace(func_name.begin(), func_name.end(), '/', '_');
std::replace(func_name.begin(), func_name.end(), ':', '_');
tests_func_name.push_back(func_name);
forwardDeclareCode += "int ";
forwardDeclareCode += func_name;
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -435,11 +435,7 @@ void cmExtraEclipseCDT4Generator::WriteGroups(
linkName3 += "/";
linkName3 += sgIt->GetFullName();
size_t pos = 0;
while ((pos = linkName3.find("\\", pos)) != std::string::npos) {
linkName3.replace(pos, 1, "/");
pos++;
}
std::replace(linkName3.begin(), linkName3.end(), '\\', '/');
this->AppendLinkedResource(xml, linkName3, "virtual:/virtual",
VirtualFolder);
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -214,7 +214,7 @@ void cmGlobalGhsMultiGenerator::OpenBuildFileStream()
this->GetCMakeInstance()->MarkCliAsUsed("GHS_OS_DIR");
}
std::string fOSDir(this->trimQuotes(osDir));
cmSystemTools::ReplaceString(fOSDir, "\\", "/");
std::replace(fOSDir.begin(), fOSDir.end(), '\\', '/');
if (!fOSDir.empty() && ('c' == fOSDir[0] || 'C' == fOSDir[0])) {
this->OSDirRelative = false;
} else {
......@@ -230,7 +230,7 @@ void cmGlobalGhsMultiGenerator::OpenBuildFileStream()
this->GetCMakeInstance()->MarkCliAsUsed("GHS_BSP_NAME");
}
std::string fBspName(this->trimQuotes(bspName));
cmSystemTools::ReplaceString(fBspName, "\\", "/");
std::replace(fBspName.begin(), fBspName.end(), '\\', '/');
this->WriteMacros();
this->WriteHighLevelDirectives();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment