diff options
author | Brad King <brad.king@kitware.com> | 2023-08-01 13:31:21 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-08-01 13:31:45 (GMT) |
commit | d8b6a750a0c5fcba6b3b5e18cd677b44ba1221ed (patch) | |
tree | 035fa17676b16be224e575709825246ca67121da /Source/CPack | |
parent | 08c637423c48f588c46d426bdafc1fd7b9e7bb86 (diff) | |
parent | d58253d155b43b8af1d0b64412145625907e3d9e (diff) | |
download | CMake-d8b6a750a0c5fcba6b3b5e18cd677b44ba1221ed.zip CMake-d8b6a750a0c5fcba6b3b5e18cd677b44ba1221ed.tar.gz CMake-d8b6a750a0c5fcba6b3b5e18cd677b44ba1221ed.tar.bz2 |
Merge topic 'windows-tidy-cmstrcat'
d58253d155 clang-tidy: fix `performance-faster-string-find` lints
a19ec77200 clang-tidy: fix `readability-static-accessed-through-instance` lints
3d03629f20 cmWIXRichTextFormatWriter: remove identity cast
1df29567ac clang-tidy: fix `modernize-use-equals-default` lints
32fe862b8c clang-tidy: fix `readability-container-size-empty` lints
7eaab9a957 clang-tidy: fix `modernize-raw-string-literal` lints
ffa49c23aa clang-tidy: fix `readability-else-after-return` lints
4489e9a85c clang-tidy: fix `modernize-use-auto` lints
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8668
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/WiX/cmCPackWIXGenerator.cxx | 153 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXAccessControlList.cxx | 10 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx | 6 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx | 12 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatch.cxx | 11 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatchParser.cxx | 17 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx | 9 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXShortcut.cxx | 2 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXSourceWriter.cxx | 32 | ||||
-rw-r--r-- | Source/CPack/cmCPackCygwinBinaryGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/CPack/cmCPackCygwinSourceGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/CPack/cmCPackInnoSetupGenerator.cxx | 8 |
12 files changed, 145 insertions, 125 deletions
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 1ea78fd..5077596 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -7,6 +7,7 @@ #include <cm/memory> #include <cm/string_view> #include <cmext/algorithm> +#include <cmext/string_view> #include "cmsys/Directory.hxx" #include "cmsys/Encoding.hxx" @@ -54,7 +55,7 @@ int cmCPackWIXGenerator::InitializeInternal() bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command) { - std::string logFileName = this->CPackTopLevel + "/wix.log"; + std::string logFileName = cmStrCat(this->CPackTopLevel, "/wix.log"); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Running WiX command: " << command << std::endl); @@ -62,8 +63,9 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command) std::string output; int returnValue = 0; - bool status = cmSystemTools::RunSingleCommand( - command, &output, &output, &returnValue, 0, cmSystemTools::OUTPUT_NONE); + bool status = + cmSystemTools::RunSingleCommand(command, &output, &output, &returnValue, + nullptr, cmSystemTools::OUTPUT_NONE); cmsys::ofstream logFile(logFileName.c_str(), std::ios::app); logFile << command << std::endl; @@ -102,22 +104,22 @@ bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile, } std::ostringstream command; - command << QuotePath(executable); - command << " -nologo"; - command << " -arch " << arch; - command << " -out " << QuotePath(objectFile); + command << QuotePath(executable) + << " -nologo" + " -arch " + << arch << " -out " << QuotePath(objectFile); for (std::string const& ext : CandleExtensions) { command << " -ext " << QuotePath(ext); } if (!cmHasSuffix(sourceFile, this->CPackTopLevel)) { - command << " " << QuotePath("-I" + this->CPackTopLevel); + command << ' ' << QuotePath(cmStrCat("-I", this->CPackTopLevel)); } AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command); - command << " " << QuotePath(sourceFile); + command << ' ' << QuotePath(sourceFile); return RunWiXCommand(command.str()); } @@ -130,9 +132,10 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) } std::ostringstream command; - command << QuotePath(executable); - command << " -nologo"; - command << " -out " << QuotePath(CMakeToWixPath(packageFileNames.at(0))); + command << QuotePath(executable) + << " -nologo" + " -out " + << QuotePath(CMakeToWixPath(packageFileNames.at(0))); for (std::string const& ext : this->LightExtensions) { command << " -ext " << QuotePath(ext); @@ -145,7 +148,7 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command); - command << " " << objectFiles; + command << ' ' << objectFiles; return RunWiXCommand(command.str()); } @@ -196,7 +199,8 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration() } if (!GetOption("CPACK_WIX_LICENSE_RTF")) { - std::string licenseFilename = this->CPackTopLevel + "/License.rtf"; + std::string licenseFilename = + cmStrCat(this->CPackTopLevel, "/License.rtf"); SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename); if (!CreateLicenseFile()) { @@ -293,14 +297,14 @@ bool cmCPackWIXGenerator::PackageFilesImpl() usedBaseNames.insert(uniqueBaseName); std::string objectFilename = - this->CPackTopLevel + "/" + uniqueBaseName + ".wixobj"; + cmStrCat(this->CPackTopLevel, '/', uniqueBaseName, ".wixobj"); if (!RunCandleCommand(CMakeToWixPath(sourceFilename), CMakeToWixPath(objectFilename))) { return false; } - objectFiles << " " << QuotePath(CMakeToWixPath(objectFilename)); + objectFiles << ' ' << QuotePath(CMakeToWixPath(objectFilename)); } AppendUserSuppliedExtraObjects(objectFiles); @@ -311,8 +315,9 @@ bool cmCPackWIXGenerator::PackageFilesImpl() void cmCPackWIXGenerator::AppendUserSuppliedExtraSources() { cmValue cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES"); - if (!cpackWixExtraSources) + if (!cpackWixExtraSources) { return; + } cmExpandList(cpackWixExtraSources, this->WixSources); } @@ -320,8 +325,9 @@ void cmCPackWIXGenerator::AppendUserSuppliedExtraSources() void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream) { cmValue cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS"); - if (!cpackWixExtraObjects) + if (!cpackWixExtraObjects) { return; + } cmList expandedExtraObjects{ cpackWixExtraObjects }; @@ -332,7 +338,8 @@ void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream) void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() { - std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi"; + std::string includeFilename = + cmStrCat(this->CPackTopLevel, "/cpack_variables.wxi"); cmWIXSourceWriter includeFile(this->Logger, includeFilename, this->ComponentGuidType, @@ -356,7 +363,8 @@ void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() { - std::string includeFilename = this->CPackTopLevel + "/properties.wxi"; + std::string includeFilename = + cmStrCat(this->CPackTopLevel, "/properties.wxi"); cmWIXSourceWriter includeFile(this->Logger, includeFilename, this->ComponentGuidType, @@ -405,7 +413,8 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile() { - std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi"; + std::string includeFilename = + cmStrCat(this->CPackTopLevel, "/product_fragment.wxi"); cmWIXSourceWriter includeFile(this->Logger, includeFilename, this->ComponentGuidType, @@ -444,7 +453,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() // if install folder is supposed to be set absolutely, the default // component guid "*" cannot be used std::string directoryDefinitionsFilename = - this->CPackTopLevel + "/directories.wxs"; + cmStrCat(this->CPackTopLevel, "/directories.wxs"); this->WixSources.push_back(directoryDefinitionsFilename); @@ -466,7 +475,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.BeginInstallationPrefixDirectory(GetRootFolderId(), installRoot); - std::string fileDefinitionsFilename = this->CPackTopLevel + "/files.wxs"; + std::string fileDefinitionsFilename = + cmStrCat(this->CPackTopLevel, "/files.wxs"); this->WixSources.push_back(fileDefinitionsFilename); @@ -477,7 +487,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() fileDefinitions.BeginElement("Fragment"); std::string featureDefinitionsFilename = - this->CPackTopLevel + "/features.wxs"; + cmStrCat(this->CPackTopLevel, "/features.wxs"); this->WixSources.push_back(featureDefinitionsFilename); @@ -536,7 +546,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() std::string componentPath = cmStrCat(toplevel, '/', component.Name); - std::string const componentFeatureId = "CM_C_" + component.Name; + std::string const componentFeatureId = cmStrCat("CM_C_", component.Name); cmWIXShortcuts featureShortcuts; AddComponentsToFeature(componentPath, componentFeatureId, @@ -556,7 +566,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() bool emitUninstallShortcut = true; cmValue cpackWixProgramMenuFolder = GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); - if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder == ".") { + if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder == "."_s) { emitUninstallShortcut = false; } else if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) == emittedShortcutTypes.end()) { @@ -613,7 +623,7 @@ std::string cmCPackWIXGenerator::GetRootFolderId() const result = *rootFolderId; } - if (GetArchitecture() == "x86") { + if (GetArchitecture() == "x86"_s) { cmSystemTools::ReplaceString(result, "<64>", ""); } else { cmSystemTools::ReplaceString(result, "<64>", "64"); @@ -636,7 +646,7 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() return false; } - std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs"; + std::string mainSourceFilePath = cmStrCat(this->CPackTopLevel, "/main.wxs"); if (!ConfigureFile(wixTemplate, mainSourceFilePath)) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -656,7 +666,7 @@ bool cmCPackWIXGenerator::CreateFeatureHierarchy( { for (auto const& i : ComponentGroups) { cmCPackComponentGroup const& group = i.second; - if (group.ParentGroup == 0) { + if (group.ParentGroup == nullptr) { featureDefinitions.EmitFeatureForComponentGroup(group, *this->Patch); } } @@ -757,7 +767,7 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( case cmWIXShortcuts::START_MENU: { cmValue cpackWixProgramMenuFolder = GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); - if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder == ".") { + if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder == "."_s) { directoryId = "ProgramMenuFolder"; } else { directoryId = "PROGRAM_MENU_FOLDER"; @@ -788,13 +798,13 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( std::string idSuffix; if (!cpackComponentName.empty()) { - idSuffix += "_"; + idSuffix += '_'; idSuffix += cpackComponentName; } std::string componentId = "CM_SHORTCUT"; - if (idPrefix.size()) { - componentId += "_" + idPrefix; + if (!idPrefix.empty()) { + componentId += cmStrCat('_', idPrefix); } componentId += idSuffix; @@ -810,7 +820,7 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( this->Patch->ApplyFragment(componentId, fileDefinitions); std::string registryKey = - std::string("Software\\") + cpackVendor + "\\" + cpackPackageName; + cmStrCat("Software\\", cpackVendor, '\\', cpackPackageName); shortcuts.EmitShortcuts(type, registryKey, cpackComponentName, fileDefinitions); @@ -818,9 +828,9 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( if (type == cmWIXShortcuts::START_MENU) { cmValue cpackWixProgramMenuFolder = GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); - if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder != ".") { - fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + - idSuffix); + if (cpackWixProgramMenuFolder && cpackWixProgramMenuFolder != "."_s) { + fileDefinitions.EmitRemoveFolder( + cmStrCat("CM_REMOVE_PROGRAM_MENU_FOLDER", idSuffix)); } } @@ -851,10 +861,10 @@ bool cmCPackWIXGenerator::CreateLicenseFile() std::string extension = GetRightmostExtension(licenseSourceFilename); - if (extension == ".rtf") { + if (extension == ".rtf"_s) { cmSystemTools::CopyAFile(licenseSourceFilename.c_str(), licenseDestinationFilename.c_str()); - } else if (extension == ".txt") { + } else if (extension == ".txt"_s) { cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename); cmsys::ifstream licenseSource(licenseSourceFilename.c_str()); @@ -923,19 +933,18 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitions( for (size_t i = 0; i < dir.GetNumberOfFiles(); ++i) { std::string fileName = dir.GetFile(static_cast<unsigned long>(i)); - if (fileName == "." || fileName == "..") { + if (fileName == "."_s || fileName == ".."_s) { continue; } - std::string fullPath = topdir + "/" + fileName; + std::string fullPath = cmStrCat(topdir, '/', fileName); - std::string relativePath = - cmSystemTools::RelativePath(toplevel.c_str(), fullPath.c_str()); + std::string relativePath = cmSystemTools::RelativePath(toplevel, fullPath); std::string id = PathToId(relativePath); - if (cmSystemTools::FileIsDirectory(fullPath.c_str())) { - std::string subDirectoryId = std::string("CM_D") + id; + if (cmSystemTools::FileIsDirectory(fullPath)) { + std::string subDirectoryId = cmStrCat("CM_D", id); directoryDefinitions.BeginElement("Directory"); directoryDefinitions.AddAttribute("Id", subDirectoryId); @@ -965,7 +974,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitions( std::string const& textLabel = packageExecutables[j]; if (cmSystemTools::LowerCase(fileName) == - cmSystemTools::LowerCase(executableName) + ".exe") { + cmStrCat(cmSystemTools::LowerCase(executableName), ".exe")) { cmWIXShortcut shortcut; shortcut.label = textLabel; shortcut.workingDirectoryId = directoryId; @@ -988,12 +997,12 @@ bool cmCPackWIXGenerator::RequireOption(std::string const& name, value = *tmp; return true; - } else { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Required variable " << name << " not set" << std::endl); - - return false; } + + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Required variable " << name << " not set" << std::endl); + + return false; } std::string cmCPackWIXGenerator::GetArchitecture() const @@ -1001,11 +1010,10 @@ std::string cmCPackWIXGenerator::GetArchitecture() const std::string void_p_size; RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size); - if (void_p_size == "8") { + if (void_p_size == "8"_s) { return "x64"; - } else { - return "x86"; } + return "x86"; } std::string cmCPackWIXGenerator::GenerateGUID() @@ -1034,7 +1042,7 @@ std::string cmCPackWIXGenerator::GenerateGUID() std::string cmCPackWIXGenerator::QuotePath(std::string const& path) { - return std::string("\"") + path + '"'; + return cmStrCat('"', path, '"'); } std::string cmCPackWIXGenerator::GetRightmostExtension( @@ -1042,7 +1050,7 @@ std::string cmCPackWIXGenerator::GetRightmostExtension( { std::string extension; - std::string::size_type i = filename.rfind("."); + std::string::size_type i = filename.rfind('.'); if (i != std::string::npos) { extension = filename.substr(i); } @@ -1052,9 +1060,10 @@ std::string cmCPackWIXGenerator::GetRightmostExtension( std::string cmCPackWIXGenerator::PathToId(std::string const& path) { - id_map_t::const_iterator i = PathToIdMap.find(path); - if (i != PathToIdMap.end()) + auto i = PathToIdMap.find(path); + if (i != PathToIdMap.end()) { return i->second; + } std::string id = CreateNewIdForPath(path); return id; @@ -1063,7 +1072,7 @@ std::string cmCPackWIXGenerator::PathToId(std::string const& path) std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path) { std::vector<std::string> components; - cmSystemTools::SplitPath(path.c_str(), components, false); + cmSystemTools::SplitPath(path, components, false); size_t replacementCount = 0; @@ -1071,8 +1080,9 @@ std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path) std::string currentComponent; for (size_t i = 1; i < components.size(); ++i) { - if (i != 1) + if (i != 1) { identifier += '.'; + } currentComponent = NormalizeComponentForId(components[i], replacementCount); @@ -1088,18 +1098,19 @@ std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path) } std::ostringstream result; - result << idPrefix << "_" << identifier; + result << idPrefix << '_' << identifier; size_t ambiguityCount = ++IdAmbiguityCounter[identifier]; if (ambiguityCount > 999) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while trying to generate a unique Id for '" - << path << "'" << std::endl); + << path << '\'' << std::endl); return std::string(); - } else if (ambiguityCount > 1) { - result << "_" << ambiguityCount; + } + if (ambiguityCount > 1) { + result << '_' << ambiguityCount; } std::string resultString = result.str(); @@ -1157,8 +1168,9 @@ void cmCPackWIXGenerator::CollectExtensions(std::string const& variableName, extension_set_t& extensions) { cmValue variableContent = GetOption(variableName); - if (!variableContent) + if (!variableContent) { return; + } cmList list{ variableContent }; extensions.insert(list.begin(), list.end()); @@ -1182,7 +1194,8 @@ void cmCPackWIXGenerator::CollectXmlNamespaces(std::string const& variableName, } else { cmCPackLogger(cmCPackLog::LOG_ERROR, "Invalid element in CPACK_WIX_CUSTOM_XMLNS ignored: " - << "\"" << str << "\"" << std::endl); + "\"" + << str << '"' << std::endl); } } std::ostringstream oss; @@ -1197,13 +1210,14 @@ void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName, std::ostream& stream) { cmValue variableContent = GetOption(variableName); - if (!variableContent) + if (!variableContent) { return; + } cmList list{ variableContent }; for (std::string const& i : list) { - stream << " " << QuotePath(i); + stream << ' ' << QuotePath(i); } } @@ -1222,6 +1236,7 @@ std::string cmCPackWIXGenerator::RelativePathWithoutComponentPrefix( void cmCPackWIXGenerator::InjectXmlNamespaces(cmWIXSourceWriter& sourceWriter) { for (auto& ns : this->CustomXmlNamespaces) { - sourceWriter.AddAttributeUnlessEmpty("xmlns:" + ns.first, ns.second); + sourceWriter.AddAttributeUnlessEmpty(cmStrCat("xmlns:", ns.first), + ns.second); } } diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx index 2261a66..0ebe2f4 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.cxx +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -102,13 +102,14 @@ bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name) "Write", "WriteAttributes", "WriteExtendedAttributes", - 0 + nullptr }; size_t i = 0; while (validAttributes[i]) { - if (name == validAttributes[i++]) + if (name == validAttributes[i++]) { return true; + } } return false; @@ -118,9 +119,8 @@ void cmWIXAccessControlList::EmitBooleanAttribute(std::string const& entry, std::string const& name) { if (!this->IsBooleanAttribute(name)) { - std::ostringstream message; - message << "Unknown boolean attribute '" << name << "'"; - this->ReportError(entry, message.str()); + this->ReportError(entry, + cmStrCat("Unknown boolean attribute '", name, '\'')); } this->SourceWriter.AddAttribute(name, "yes"); diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx index 0a83ca2..a655d86 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXDirectoriesSourceWriter.h" +#include <cmext/string_view> + cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter( cmCPackLog* logger, std::string const& filename, GuidType componentGuidType) : cmWIXSourceWriter(logger, filename, componentGuidType) @@ -14,7 +16,7 @@ void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder( BeginElement("Directory"); AddAttribute("Id", "ProgramMenuFolder"); - if (startMenuFolder != ".") { + if (startMenuFolder != "."_s) { BeginElement("Directory"); AddAttribute("Id", "PROGRAM_MENU_FOLDER"); AddAttribute("Name", startMenuFolder); @@ -53,7 +55,7 @@ size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory( std::vector<std::string> installRoot; - cmSystemTools::SplitPath(installRootString.c_str(), installRoot); + cmSystemTools::SplitPath(installRootString, installRoot); if (!installRoot.empty() && installRoot.back().empty()) { installRoot.pop_back(); diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx index a7a0648..78c2208 100644 --- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWIXFeaturesSourceWriter.h" +#include "cmStringAlgorithms.h" + cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter( cmCPackLog* logger, std::string const& filename, GuidType componentGuidType) : cmWIXSourceWriter(logger, filename, componentGuidType) @@ -17,7 +19,7 @@ void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry( AddAttribute("Guid", CreateGuidFromComponentId("CM_PACKAGE_REGISTRY")); std::string registryKey = - std::string("Software\\Kitware\\CMake\\Packages\\") + package; + cmStrCat(R"(Software\Kitware\CMake\Packages\)", package); BeginElement("RegistryValue"); AddAttribute("Root", "HKLM"); @@ -35,7 +37,7 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup( cmCPackComponentGroup const& group, cmWIXPatch& patch) { BeginElement("Feature"); - AddAttribute("Id", "CM_G_" + group.Name); + AddAttribute("Id", cmStrCat("CM_G_", group.Name)); if (group.IsExpandedByDefault) { AddAttribute("Display", "expand"); @@ -44,7 +46,7 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup( AddAttributeUnlessEmpty("Title", group.DisplayName); AddAttributeUnlessEmpty("Description", group.Description); - patch.ApplyFragment("CM_G_" + group.Name, *this); + patch.ApplyFragment(cmStrCat("CM_G_", group.Name), *this); for (cmCPackComponentGroup* subgroup : group.Subgroups) { EmitFeatureForComponentGroup(*subgroup, patch); @@ -61,7 +63,7 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponent( cmCPackComponent const& component, cmWIXPatch& patch) { BeginElement("Feature"); - AddAttribute("Id", "CM_C_" + component.Name); + AddAttribute("Id", cmStrCat("CM_C_", component.Name)); AddAttributeUnlessEmpty("Title", component.DisplayName); AddAttributeUnlessEmpty("Description", component.Description); @@ -78,7 +80,7 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponent( AddAttribute("Level", "2"); } - patch.ApplyFragment("CM_C_" + component.Name, *this); + patch.ApplyFragment(cmStrCat("CM_C_", component.Name), *this); EndElement("Feature"); } diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx index 122ffaf..c65449c 100644 --- a/Source/CPack/WiX/cmWIXPatch.cxx +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -14,7 +14,7 @@ bool cmWIXPatch::LoadFragments(std::string const& patchFilePath) cmWIXPatchParser parser(Fragments, Logger); if (!parser.ParseFile(patchFilePath.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Failed parsing XML patch file: '" << patchFilePath << "'" + "Failed parsing XML patch file: '" << patchFilePath << '\'' << std::endl); return false; } @@ -25,9 +25,10 @@ bool cmWIXPatch::LoadFragments(std::string const& patchFilePath) void cmWIXPatch::ApplyFragment(std::string const& id, cmWIXSourceWriter& writer) { - cmWIXPatchParser::fragment_map_t::iterator i = Fragments.find(id); - if (i == Fragments.end()) + auto i = Fragments.find(id); + if (i == Fragments.end()) { return; + } const cmWIXPatchElement& fragment = i->second; for (auto const& attr : fragment.attributes) { @@ -75,9 +76,9 @@ bool cmWIXPatch::CheckForUnappliedFragments() fragmentList += ", "; } - fragmentList += "'"; + fragmentList += '\''; fragmentList += fragment.first; - fragmentList += "'"; + fragmentList += '\''; } if (!fragmentList.empty()) { diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx index 8b26c4e..136eaac 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.cxx +++ b/Source/CPack/WiX/cmWIXPatchParser.cxx @@ -5,6 +5,7 @@ #include <utility> #include <cm/memory> +#include <cmext/string_view> #include <cm3p/expat.h> @@ -20,9 +21,7 @@ cmWIXPatchNode::Type cmWIXPatchElement::type() return cmWIXPatchNode::ELEMENT; } -cmWIXPatchNode::~cmWIXPatchNode() -{ -} +cmWIXPatchNode::~cmWIXPatchNode() = default; cmWIXPatchElement::cmWIXPatchElement() = default; cmWIXPatchElement::~cmWIXPatchElement() = default; @@ -39,13 +38,13 @@ cmWIXPatchParser::cmWIXPatchParser(fragment_map_t& fragments, void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) { if (State == BEGIN_DOCUMENT) { - if (name == "CPackWiXPatch") { + if (name == "CPackWiXPatch"_s) { State = BEGIN_FRAGMENTS; } else { ReportValidationError("Expected root element 'CPackWiXPatch'"); } } else if (State == BEGIN_FRAGMENTS) { - if (name == "CPackWiXFragment") { + if (name == "CPackWiXFragment"_s) { State = INSIDE_FRAGMENT; StartFragment(atts); } else { @@ -78,7 +77,7 @@ void cmWIXPatchParser::StartFragment(const char** attributes) const std::string key = attributes[i]; const std::string value = attributes[i + 1]; - if (key == "Id") { + if (key == "Id"_s) { if (Fragments.find(value) != Fragments.end()) { std::ostringstream tmp; tmp << "Invalid reuse of 'CPackWixFragment' 'Id': " << value; @@ -98,7 +97,7 @@ void cmWIXPatchParser::StartFragment(const char** attributes) const std::string key = attributes[i]; const std::string value = attributes[i + 1]; - if (key != "Id") { + if (key != "Id"_s) { new_element->attributes[key] = value; } } @@ -108,7 +107,7 @@ void cmWIXPatchParser::StartFragment(const char** attributes) void cmWIXPatchParser::EndElement(const std::string& name) { if (State == INSIDE_FRAGMENT) { - if (name == "CPackWiXFragment") { + if (name == "CPackWiXFragment"_s) { State = BEGIN_FRAGMENTS; ElementStack.clear(); } else { @@ -142,7 +141,7 @@ void cmWIXPatchParser::ReportError(int line, int column, const char* msg) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while processing XML patch file at " - << line << ":" << column << ": " << msg << std::endl); + << line << ':' << column << ": " << msg << std::endl); Valid = false; } diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx index d7e534a..8a63239 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx @@ -135,7 +135,7 @@ void cmWIXRichTextFormatWriter::WriteDocumentPrefix() void cmWIXRichTextFormatWriter::ControlWord(std::string const& keyword) { - File << "\\" << keyword; + File << '\\' << keyword; } void cmWIXRichTextFormatWriter::NewControlWord(std::string const& keyword) @@ -158,7 +158,8 @@ void cmWIXRichTextFormatWriter::EmitUnicodeCodepoint(int c) // Do not emit byte order mark (BOM) if (c == 0xFEFF) { return; - } else if (c <= 0xFFFF) { + } + if (c <= 0xFFFF) { EmitUnicodeSurrogate(c); } else { c -= 0x10000; @@ -175,12 +176,12 @@ void cmWIXRichTextFormatWriter::EmitUnicodeSurrogate(int c) } else { File << (c - 65536); } - File << "?"; + File << '?'; } void cmWIXRichTextFormatWriter::EmitInvalidCodepoint(int c) { ControlWord("cf1 "); - File << "[INVALID-BYTE-" << int(c) << "]"; + File << "[INVALID-BYTE-" << c << ']'; ControlWord("cf0 "); } diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx index c3eb219..1cfb6c1 100644 --- a/Source/CPack/WiX/cmWIXShortcut.cxx +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -20,7 +20,7 @@ bool cmWIXShortcuts::EmitShortcuts( std::string const& cpackComponentName, cmWIXFilesSourceWriter& fileDefinitions) const { - shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type); + auto i = this->Shortcuts.find(type); if (i == this->Shortcuts.end()) { return false; diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx index 8e9bfdf..82dc019 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx @@ -34,7 +34,7 @@ cmWIXSourceWriter::~cmWIXSourceWriter() cmCPackLogger(cmCPackLog::LOG_ERROR, Elements.size() - 1 << " WiX elements were still open when closing '" - << SourceFilename << "'" << std::endl); + << SourceFilename << '\'' << std::endl); return; } @@ -44,12 +44,12 @@ cmWIXSourceWriter::~cmWIXSourceWriter() void cmWIXSourceWriter::BeginElement(std::string const& name) { if (State == BEGIN) { - File << ">"; + File << '>'; } - File << "\n"; + File << '\n'; Indent(Elements.size()); - File << "<" << name; + File << '<' << name; Elements.push_back(name); State = BEGIN; @@ -60,7 +60,7 @@ void cmWIXSourceWriter::EndElement(std::string const& name) if (Elements.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "can not end WiX element with no open elements in '" - << SourceFilename << "'" << std::endl); + << SourceFilename << '\'' << std::endl); return; } @@ -68,14 +68,14 @@ void cmWIXSourceWriter::EndElement(std::string const& name) cmCPackLogger(cmCPackLog::LOG_ERROR, "WiX element <" << Elements.back() << "> can not be closed by </" << name - << "> in '" << SourceFilename << "'" << std::endl); + << "> in '" << SourceFilename << '\'' << std::endl); return; } if (State == DEFAULT) { - File << "\n"; + File << '\n'; Indent(Elements.size() - 1); - File << "</" << Elements.back() << ">"; + File << "</" << Elements.back() << '>'; } else { File << "/>"; } @@ -87,17 +87,17 @@ void cmWIXSourceWriter::EndElement(std::string const& name) void cmWIXSourceWriter::AddTextNode(std::string const& text) { if (State == BEGIN) { - File << ">"; + File << '>'; } if (Elements.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "can not add text without open WiX element in '" - << SourceFilename << "'" << std::endl); + << SourceFilename << '\'' << std::endl); return; } - File << this->EscapeAttributeValue(text); + File << cmWIXSourceWriter::EscapeAttributeValue(text); State = DEFAULT; } @@ -105,12 +105,12 @@ void cmWIXSourceWriter::AddProcessingInstruction(std::string const& target, std::string const& content) { if (State == BEGIN) { - File << ">"; + File << '>'; } - File << "\n"; + File << '\n'; Indent(Elements.size()); - File << "<?" << target << " " << content << "?>"; + File << "<?" << target << ' ' << content << "?>"; State = DEFAULT; } @@ -118,7 +118,7 @@ void cmWIXSourceWriter::AddProcessingInstruction(std::string const& target, void cmWIXSourceWriter::AddAttribute(std::string const& key, std::string const& value) { - File << " " << key << "=\"" << EscapeAttributeValue(value) << '"'; + File << ' ' << key << "=\"" << EscapeAttributeValue(value) << '"'; } void cmWIXSourceWriter::AddAttributeUnlessEmpty(std::string const& key, @@ -144,7 +144,7 @@ std::string cmWIXSourceWriter::CreateGuidFromComponentId( void cmWIXSourceWriter::WriteXMLDeclaration() { - File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; + File << R"(<?xml version="1.0" encoding="UTF-8"?>)" << std::endl; } void cmWIXSourceWriter::Indent(size_t count) diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx index fabf4c5..fcb79a2 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx @@ -44,9 +44,9 @@ int cmCPackCygwinBinaryGenerator::PackageFiles() cmGeneratedFileStream ofs(manifestFile); for (std::string const& file : files) { // remove the temp dir and replace with /usr - ofs << file.substr(tempdir.size()) << "\n"; + ofs << file.substr(tempdir.size()) << '\n'; } - ofs << manifest << "\n"; + ofs << manifest << '\n'; } // add the manifest file to the list of all files files.push_back(manifestFile); @@ -60,7 +60,7 @@ const char* cmCPackCygwinBinaryGenerator::GetOutputExtension() this->OutputExtension = "-"; cmValue patchNumber = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER"); if (!patchNumber) { - this->OutputExtension += "1"; + this->OutputExtension += '1'; cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER not specified using 1" << std::endl); diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.cxx b/Source/CPack/cmCPackCygwinSourceGenerator.cxx index a5863ff..f025a6c 100644 --- a/Source/CPack/cmCPackCygwinSourceGenerator.cxx +++ b/Source/CPack/cmCPackCygwinSourceGenerator.cxx @@ -98,7 +98,7 @@ int cmCPackCygwinSourceGenerator::PackageFiles() cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER" << " not specified, defaulting to 1\n"); - outerTarFile += "1"; + outerTarFile += '1'; } else { outerTarFile += patch; } @@ -150,7 +150,7 @@ const char* cmCPackCygwinSourceGenerator::GetOutputExtension() cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER" << " not specified, defaulting to 1\n"); - this->OutputExtension += "1"; + this->OutputExtension += '1'; } else { this->OutputExtension += patch; } diff --git a/Source/CPack/cmCPackInnoSetupGenerator.cxx b/Source/CPack/cmCPackInnoSetupGenerator.cxx index ada9a5b..b8bf070 100644 --- a/Source/CPack/cmCPackInnoSetupGenerator.cxx +++ b/Source/CPack/cmCPackInnoSetupGenerator.cxx @@ -106,7 +106,7 @@ int cmCPackInnoSetupGenerator::PackageFiles() const cmList extraScripts(GetOption("CPACK_INNOSETUP_EXTRA_SCRIPTS")); for (const std::string& i : extraScripts) { - includeDirectives.push_back(cmStrCat( + includeDirectives.emplace_back(cmStrCat( "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel)))); } } @@ -142,7 +142,7 @@ int cmCPackInnoSetupGenerator::PackageFiles() const cmList codeFiles(GetOption("CPACK_INNOSETUP_CODE_FILES")); for (const std::string& i : codeFiles) { - codeIncludes.push_back(cmStrCat( + codeIncludes.emplace_back(cmStrCat( "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel)))); } } @@ -781,7 +781,7 @@ bool cmCPackInnoSetupGenerator::ConfigureISScript() // Create internal variables std::vector<std::string> setupSection; for (const auto& i : setupDirectives) { - setupSection.push_back(cmStrCat(i.first, '=', TranslateBool(i.second))); + setupSection.emplace_back(cmStrCat(i.first, '=', TranslateBool(i.second))); } // Also create comments if the sections are empty @@ -1082,7 +1082,7 @@ std::string cmCPackInnoSetupGenerator::ISKeyValueLine( std::vector<std::string> keys; for (const char* i : availableKeys) { if (params.count(i)) { - keys.push_back(cmStrCat(i, ": ", params.at(i))); + keys.emplace_back(cmStrCat(i, ": ", params.at(i))); } } |