From c3c3b10d60497e64fc71764ac025bd16e8b6cb4a Mon Sep 17 00:00:00 2001 From: John Franklin Rickard Date: Thu, 22 Jan 2026 17:55:59 +0100 Subject: [PATCH] cmGlobalGenerator: Change parameter to string_view --- Source/cmCoreTryCompile.cxx | 2 +- Source/cmGlobalGenerator.cxx | 15 ++++++++------- Source/cmGlobalGenerator.h | 4 ++-- Source/cmLocalVisualStudio7Generator.cxx | 2 +- Source/cmSourceFile.cxx | 2 +- Source/cmSourceFileLocation.cxx | 2 +- Source/cmVisualStudio10TargetGenerator.cxx | 5 ++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index e07fdbe47c..d5ac27e8fe 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -575,7 +575,7 @@ cm::optional cmCoreTryCompile::TryCompileCode( for (auto const& source : sources) { auto const& si = source.first; std::string ext = cmSystemTools::GetFilenameLastExtension(si); - std::string lang = gg->GetLanguageFromExtension(ext.c_str()); + std::string lang = gg->GetLanguageFromExtension(ext); if (!lang.empty()) { testLangs.insert(lang); } else { diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1decc42f77..4858509145 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1100,17 +1100,18 @@ std::string cmGlobalGenerator::GetLanguageOutputExtension( return ""; } -std::string cmGlobalGenerator::GetLanguageFromExtension(char const* ext) const +std::string cmGlobalGenerator::GetLanguageFromExtension( + cm::string_view ext) const { // if there is an extension and it starts with . then move past the // . because the extensions are not stored with a . in the map - if (!ext) { + if (ext.empty()) { return ""; } - if (*ext == '.') { - ++ext; + if (ext.front() == '.') { + ext = ext.substr(1); } - auto const it = this->ExtensionToLanguage.find(ext); + auto const it = this->ExtensionToLanguage.find(std::string(ext)); if (it != this->ExtensionToLanguage.end()) { return it->second; } @@ -1239,12 +1240,12 @@ std::string cmGlobalGenerator::GetSafeGlobalSetting( return this->Makefiles[0]->GetDefinition(name); } -bool cmGlobalGenerator::IgnoreFile(char const* ext) const +bool cmGlobalGenerator::IgnoreFile(cm::string_view ext) const { if (!this->GetLanguageFromExtension(ext).empty()) { return false; } - return (this->IgnoreExtensions.count(ext) > 0); + return (this->IgnoreExtensions.count(std::string(ext)) > 0); } bool cmGlobalGenerator::GetLanguageEnabled(std::string const& l) const diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 603cccc7c9..f9c5642292 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -359,9 +359,9 @@ public: bool GetToolSupportsColor() const { return this->ToolSupportsColor; } //! return the language for the given extension - std::string GetLanguageFromExtension(char const* ext) const; + std::string GetLanguageFromExtension(cm::string_view ext) const; //! is an extension to be ignored - bool IgnoreFile(char const* ext) const; + bool IgnoreFile(cm::string_view ext) const; //! What is the preference for linkers and this language (None or Preferred) int GetLinkerPreference(std::string const& lang) const; //! What is the object file extension for a given source file? diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 8ab46e7f59..a34820bca4 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1487,7 +1487,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( cmLVS7GFileConfig fc; std::string lang = - lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str()); + lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension()); std::string const& sourceLang = lg->GetSourceFileLanguage(sf); bool needForceLang = false; // source file does not match its extension language diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 430f9c5fe5..8706c7bb76 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -287,7 +287,7 @@ void cmSourceFile::CheckLanguage(std::string const& ext) // Try to identify the source file language from the extension. cmMakefile const* mf = this->Location.GetMakefile(); cmGlobalGenerator* gg = mf->GetGlobalGenerator(); - std::string l = gg->GetLanguageFromExtension(ext.c_str()); + std::string l = gg->GetLanguageFromExtension(ext); if (!l.empty()) { this->Language = l; } diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index fd2fd378a8..3ad4934799 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -112,7 +112,7 @@ void cmSourceFileLocation::UpdateExtension(std::string const& name) cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); cmMakefile const* mf = this->Makefile; auto* cm = mf->GetCMakeInstance(); - if (!gg->GetLanguageFromExtension(ext.c_str()).empty() || + if (!gg->GetLanguageFromExtension(ext).empty() || cm->IsAKnownExtension(ext)) { // This is a known extension. Use the given filename with extension. this->Name = cmSystemTools::GetFilenameName(name); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index fac0f752ac..f6cfc3c4d8 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2835,9 +2835,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( // Force language if the file extension does not match. // Note that MSVC treats the upper-case '.C' extension as C and not C++. std::string const ext = sf.GetExtension(); - std::string const extLang = ext == "C"_s - ? "C" - : this->GlobalGenerator->GetLanguageFromExtension(ext.c_str()); + std::string const extLang = + ext == "C"_s ? "C" : this->GlobalGenerator->GetLanguageFromExtension(ext); std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf); char const* compileAs = nullptr; if (lang != extLang) {