ast-grep: simplify cmHasLiteral{Suf,Pre}fix with char literals

This commit is contained in:
Ben Boeckel
2025-10-27 16:19:22 -04:00
parent 9945be27af
commit 366b25e62e
21 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -233,7 +233,7 @@ int cmCPackArchiveGenerator::InitializeInternal()
cmValue newExtensionValue = this->GetOption("CPACK_ARCHIVE_FILE_EXTENSION");
if (!newExtensionValue.IsEmpty()) {
std::string newExtension = *newExtensionValue;
if (!cmHasLiteralPrefix(newExtension, ".")) {
if (!cmHasPrefix(newExtension, '.')) {
newExtension = cmStrCat('.', newExtension);
}
cmCPackLogger(cmCPackLog::LOG_DEBUG,
+1 -1
View File
@@ -834,7 +834,7 @@ int cmCPackGenerator::InstallCMakeProject(
// Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
// exists:
//
if (cmHasLiteralPrefix(dir, "/")) {
if (cmHasPrefix(dir, '/')) {
dir = tempInstallDirectory + dir;
} else {
dir = tempInstallDirectory + "/" + dir;
+1 -1
View File
@@ -85,7 +85,7 @@ bool cmParseGTMCoverage::ReadMCovFile(char const* file)
}
// Find the full path to the file
bool found = this->FindMumpsFile(routine, filepath);
if (!found && cmHasLiteralSuffix(routine, "%")) {
if (!found && cmHasSuffix(routine, '%')) {
routine.erase(0, 1);
found = this->FindMumpsFile(routine, filepath);
}
+1 -1
View File
@@ -287,7 +287,7 @@ static bool cmOSXInstall(std::string const& dir, std::string const& tool)
static int cmOSXInstall(std::string dir)
{
if (!cmHasLiteralSuffix(dir, "/")) {
if (!cmHasSuffix(dir, '/')) {
dir += "/";
}
return (cmOSXInstall(dir, cmSystemTools::GetCMakeCommand()) &&
+1 -1
View File
@@ -2531,7 +2531,7 @@ int cmCTest::Run(std::vector<std::string> const& args)
this->Impl->BuildAndTest.TestCommandArgs.emplace_back(args[i]);
}
}
if (!matched && cmHasLiteralPrefix(arg, "-") &&
if (!matched && cmHasPrefix(arg, '-') &&
!cmHasLiteralPrefix(arg, "--preset")) {
cmSystemTools::Error(cmStrCat("Unknown argument: ", arg));
cmSystemTools::Error("Run 'ctest --help' for all supported options.");
+1 -1
View File
@@ -53,7 +53,7 @@ std::string EvaluateSplitConfigGenex(
++pos;
continue;
}
if (cmHasLiteralPrefix(cur, ">")) {
if (cmHasPrefix(cur, '>')) {
--nestingLevel;
if (nestingLevel == 0) {
++pos;
+1 -1
View File
@@ -1067,7 +1067,7 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
installer["destination"] = installDir->GetDestination(this->Config);
Json::Value paths = Json::arrayValue;
for (std::string const& dir : dirs) {
if (cmHasLiteralSuffix(dir, "/")) {
if (cmHasSuffix(dir, '/')) {
paths.append(this->DumpInstallerPath(
this->TopSource, dir.substr(0, dir.size() - 1), "."));
} else {
+3 -3
View File
@@ -2511,7 +2511,7 @@ cm::optional<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran(
}
dir_top_bld = tdi["dir-top-bld"].asString();
if (!dir_top_bld.empty() && !cmHasLiteralSuffix(dir_top_bld, "/")) {
if (!dir_top_bld.empty() && !cmHasSuffix(dir_top_bld, '/')) {
dir_top_bld += '/';
}
@@ -2524,7 +2524,7 @@ cm::optional<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran(
Json::Value const& tdi_module_dir = tdi["module-dir"];
module_dir = tdi_module_dir.asString();
if (!module_dir.empty() && !cmHasLiteralSuffix(module_dir, "/")) {
if (!module_dir.empty() && !cmHasSuffix(module_dir, '/')) {
module_dir += '/';
}
@@ -3021,7 +3021,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
}
std::string module_dir = tdi["module-dir"].asString();
if (!module_dir.empty() && !cmHasLiteralSuffix(module_dir, "/")) {
if (!module_dir.empty() && !cmHasSuffix(module_dir, '/')) {
module_dir += '/';
}
std::vector<std::string> linked_target_dirs;
+1 -1
View File
@@ -998,7 +998,7 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
root->MaybeRelativeToCurBinDir(lg->GetCurrentBinaryDirectory());
if (dir == "."_s) {
dir.clear();
} else if (!cmHasLiteralSuffix(dir, "/")) {
} else if (!cmHasSuffix(dir, '/')) {
dir += "/";
}
+1 -1
View File
@@ -45,7 +45,7 @@ static bool cmLinkItemValidForDevice(std::string const& item)
// * '-pthread' => drop
// * '-a' => drop
// * '-framework Name' (as one string) => drop
return (!cmHasLiteralPrefix(item, "-") || //
return (!cmHasPrefix(item, '-') || //
cmHasLiteralPrefix(item, "-l") || //
cmHasLiteralPrefix(item, "-L") || //
cmHasLiteralPrefix(item, "--library"));
+1 -1
View File
@@ -489,7 +489,7 @@ bool RuleNeedsCMD(std::string const& cmd)
auto it = std::find_if(args.cbegin(), args.cend(),
[](std::string const& arg) -> bool {
// FIXME: Detect more windows shell operators.
return cmHasLiteralPrefix(arg, ">");
return cmHasPrefix(arg, '>');
});
return it != args.cend();
}
+1 -1
View File
@@ -919,7 +919,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
cmOutputConverter::SHELL);
if (this->LocalGenerator->IsMinGWMake() &&
cmHasLiteralSuffix(targetOutPathCompilePDB, "\\")) {
cmHasSuffix(targetOutPathCompilePDB, '\\')) {
// mingw32-make incorrectly interprets 'a\ b c' as 'a b' and 'c'
// (but 'a\ b "c"' as 'a\', 'b', and 'c'!). Workaround this by
// avoiding a trailing backslash in the argument.
+1 -1
View File
@@ -456,7 +456,7 @@ std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
{
// Choose an extension to compile already-preprocessed source.
std::string ppExt = source->GetExtension();
if (cmHasLiteralPrefix(ppExt, "F")) {
if (cmHasPrefix(ppExt, 'F')) {
// Some Fortran compilers automatically enable preprocessing for
// upper-case extensions. Since the source is already preprocessed,
// use a lower-case extension.
+1 -1
View File
@@ -223,7 +223,7 @@ std::vector<std::string> ReadList(Json::Value const& data, char const* key)
std::string NormalizeTargetName(std::string const& name,
std::string const& context)
{
if (cmHasLiteralPrefix(name, ":")) {
if (cmHasPrefix(name, ':')) {
return cmStrCat(context, ':', name);
}
+1 -1
View File
@@ -81,7 +81,7 @@ bool cmSetCommand(std::vector<std::string> const& args,
// watch for CACHE{} signature
if (cmHasLiteralPrefix(variable, "CACHE{") && variable.size() > 7 &&
cmHasLiteralSuffix(variable, "}")) {
cmHasSuffix(variable, '}')) {
// what is the variable name
auto const& varName = variable.substr(6, variable.size() - 7);
// VALUE handling
+1 -1
View File
@@ -642,7 +642,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
{
std::vector<std::string> arg_full;
for (std::string const& arg : cmMakeRange(argBeg, argEnd)) {
if (cmHasLiteralPrefix(arg, "@")) {
if (cmHasPrefix(arg, '@')) {
cmsys::ifstream responseFile(arg.substr(1).c_str(), std::ios::in);
if (!responseFile) {
std::string error = cmStrCat("failed to open for reading (",
+1 -1
View File
@@ -283,7 +283,7 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
if (cmHasLiteralPrefix(cur, "$<")) {
++genexNesting;
++pos;
} else if (genexNesting > 0 && cmHasLiteralPrefix(cur, ">")) {
} else if (genexNesting > 0 && cmHasPrefix(cur, '>')) {
--genexNesting;
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ std::vector<std::string> ConvertToAbsoluteContent(
// Use '<foo.h>' and '"foo.h"' includes and absolute paths as-is.
// Interpret relative paths with respect to the source directory.
// If the path starts in a generator expression, assume it is absolute.
if (cmHasLiteralPrefix(src, "<") || cmHasLiteralPrefix(src, "\"") ||
if (cmHasPrefix(src, '<') || cmHasPrefix(src, '"') ||
cmSystemTools::FileIsFullPath(src) ||
cmGeneratorExpression::Find(src) == 0) {
absoluteSrc = src;
+1 -1
View File
@@ -30,7 +30,7 @@ bool cmUnsetCommand(std::vector<std::string> const& args,
}
// unset(CACHE{VAR})
if (cmHasLiteralPrefix(variable, "CACHE{") && variable.size() > 7 &&
cmHasLiteralSuffix(variable, "}")) {
cmHasSuffix(variable, '}')) {
// get the variable name
auto const& varName = variable.substr(6, variable.size() - 7);
status.GetMakefile().RemoveCacheDefinition(varName);
+1 -1
View File
@@ -1483,7 +1483,7 @@ void cmake::SetArgs(std::vector<std::string> const& args)
if (!parsedCorrectly) {
cmSystemTools::Error("Run 'cmake --help' for all supported options.");
exit(1);
} else if (!matched && cmHasLiteralPrefix(arg, "-")) {
} else if (!matched && cmHasPrefix(arg, '-')) {
possibleUnknownArg = arg;
} else if (!matched) {
bool parsedDirectory = this->SetDirectoriesFromFile(arg);
+5 -5
View File
@@ -180,7 +180,7 @@ bool cmTarFilesFrom(std::string const& file, std::vector<std::string>& files)
}
if (cmHasLiteralPrefix(line, "--add-file=")) {
files.push_back(line.substr(11));
} else if (cmHasLiteralPrefix(line, "-")) {
} else if (cmHasPrefix(line, '-')) {
cmSystemTools::Error(cmStrCat("-E tar --files-from='", file,
"' file invalid line:\n", line, '\n'));
return false;
@@ -1084,7 +1084,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
bool doing_options = true;
bool at_least_one_file = false;
for (auto const& arg : cmMakeRange(args).advance(2)) {
if (doing_options && cmHasLiteralPrefix(arg, "-")) {
if (doing_options && cmHasPrefix(arg, '-')) {
if (arg == "--") {
doing_options = false;
}
@@ -1239,7 +1239,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
// Destroy console buffers to drop cout/cerr encoding transform.
console.reset();
cmCatFile(arg);
} else if (doing_options && cmHasLiteralPrefix(arg, "-")) {
} else if (doing_options && cmHasPrefix(arg, '-')) {
if (arg == "--") {
doing_options = false;
} else {
@@ -2416,13 +2416,13 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
// Parse our own arguments.
std::string intDir;
auto arg = argBeg;
while (arg != argEnd && cmHasLiteralPrefix(*arg, "-")) {
while (arg != argEnd && cmHasPrefix(*arg, '-')) {
if (*arg == "--") {
++arg;
break;
}
if (*arg == "--manifests") {
for (++arg; arg != argEnd && !cmHasLiteralPrefix(*arg, "-"); ++arg) {
for (++arg; arg != argEnd && !cmHasPrefix(*arg, '-'); ++arg) {
this->UserManifests.push_back(*arg);
}
} else if (cmHasLiteralPrefix(*arg, "--intdir=")) {