diff --git a/Source/CPack/cmCPackInnoSetupGenerator.cxx b/Source/CPack/cmCPackInnoSetupGenerator.cxx index 9522e86b6f..4b8533bb5e 100644 --- a/Source/CPack/cmCPackInnoSetupGenerator.cxx +++ b/Source/CPack/cmCPackInnoSetupGenerator.cxx @@ -4,12 +4,12 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmCPackInnoSetupGenerator.h" #include -#include #include #include #include #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmCPackComponentGroup.h" #include "cmCPackLog.h" @@ -116,7 +116,7 @@ int cmCPackInnoSetupGenerator::PackageFiles() if (cmSystemTools::LowerCase(i) == "english") { params["MessagesFile"] = "\"compiler:Default.isl\""; } else { - i[0] = static_cast(std::toupper(static_cast(i[0]))); + i[0] = static_cast(cmsysString_toupper(i[0])); params["MessagesFile"] = cmStrCat("\"compiler:Languages\\", i, ".isl\""); } diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 19cbee1159..2bc60c2746 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -3,12 +3,13 @@ #include "cmCPackRPMGenerator.h" #include -#include #include #include #include #include +#include "cmsys/String.h" + #include "cmCPackComponentGroup.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" @@ -143,7 +144,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) ++compIt) { std::string component(compIt->first); std::transform(component.begin(), component.end(), component.begin(), - [](unsigned char c) { return std::toupper(c); }); + cmsysString_toupper); if (this->IsOn("CPACK_RPM_" + compIt->first + "_DEBUGINFO_PACKAGE") || this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) { @@ -157,7 +158,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) compGIt != this->ComponentGroups.end(); ++compGIt) { std::string component(compGIt->first); std::transform(component.begin(), component.end(), component.begin(), - [](unsigned char c) { return std::toupper(c); }); + cmsysString_toupper); if (this->IsOn("CPACK_RPM_" + compGIt->first + "_DEBUGINFO_PACKAGE") || this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) { @@ -174,8 +175,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) if (!compIt->second.Group) { std::string component(compIt->first); std::transform(component.begin(), component.end(), - component.begin(), - [](unsigned char c) { return std::toupper(c); }); + component.begin(), cmsysString_toupper); if (this->IsOn("CPACK_RPM_" + compIt->first + "_DEBUGINFO_PACKAGE") || @@ -207,8 +207,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) std::string mainComponentUpper(mainComponent); std::transform(mainComponentUpper.begin(), mainComponentUpper.end(), - mainComponentUpper.begin(), - [](unsigned char c) { return std::toupper(c); }); + mainComponentUpper.begin(), cmsysString_toupper); // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. @@ -220,7 +219,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) compGIt != this->ComponentGroups.end(); ++compGIt) { std::string component(compGIt->first); std::transform(component.begin(), component.end(), component.begin(), - [](unsigned char c) { return std::toupper(c); }); + cmsysString_toupper); if (mainComponentUpper == component) { // main component will be handled last @@ -242,7 +241,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) if (!compIt->second.Group) { std::string component(compIt->first); std::transform(component.begin(), component.end(), component.begin(), - [](unsigned char c) { return std::toupper(c); }); + cmsysString_toupper); if (mainComponentUpper == component) { // main component will be handled last @@ -285,7 +284,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) ++compIt) { std::string component(compIt->first); std::transform(component.begin(), component.end(), component.begin(), - [](unsigned char c) { return std::toupper(c); }); + cmsysString_toupper); if (mainComponentUpper == component) { // main component will be handled last diff --git a/Source/CursesDialog/cmCursesColor.cxx b/Source/CursesDialog/cmCursesColor.cxx index c9add4f0e8..a9e5ff6fe0 100644 --- a/Source/CursesDialog/cmCursesColor.cxx +++ b/Source/CursesDialog/cmCursesColor.cxx @@ -2,12 +2,13 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmCursesColor.h" -#include #include #include #include #include +#include "cmsys/String.h" + #include "cmCursesStandardIncludes.h" bool cmCursesColor::HasColors() @@ -42,7 +43,7 @@ short cmCursesColor::GetColor(char id, short fallback) if (!initialized) { if (auto* v = getenv("CCMAKE_COLORS")) { while (v[0] && v[1] && v[1] == '=') { - auto const n = std::toupper(static_cast(*v)); + char const n = cmsysString_toupper(*v); char buffer[12]; memset(buffer, 0, sizeof(buffer)); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index f503e93039..3b8232561b 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -34,6 +34,7 @@ #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmsys/SystemInformation.hxx" #ifndef _WIN32 # include // IWYU pragma: keep @@ -3702,8 +3703,7 @@ bool cmCTest::ConvertInstrumentationJSONFileToXML(std::string const& fpath, bool generating_test_xml = root["role"] == "test"; if (!generating_test_xml) { std::string element_name = root["role"].asString(); - element_name[0] = static_cast( - std::toupper(static_cast(element_name[0]))); + element_name[0] = static_cast(cmsysString_toupper(element_name[0])); xml.StartElement(element_name); std::vector keys = root.getMemberNames(); for (auto const& key : keys) { @@ -3735,8 +3735,8 @@ bool cmCTest::ConvertInstrumentationJSONFileToXML(std::string const& fpath, std::vector keys = dynamic_information.getMemberNames(); for (auto const& key : keys) { std::string measurement_name = key; - measurement_name[0] = static_cast( - std::toupper(static_cast(measurement_name[0]))); + measurement_name[0] = + static_cast(cmsysString_toupper(measurement_name[0])); xml.StartElement("NamedMeasurement"); xml.Attribute("type", "numeric/double"); diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 324ff30a81..5ff8784f79 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -3,7 +3,6 @@ #include "cmComputeLinkInformation.h" #include -#include #include #include @@ -13,6 +12,8 @@ #include #include +#include "cmsys/String.h" + #include "cmComputeLinkDepends.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -1556,8 +1557,8 @@ std::string cmComputeLinkInformation::NoCaseExpression(std::string const& str) ret += c; } else { ret += '['; - ret += static_cast(tolower(static_cast(c))); - ret += static_cast(toupper(static_cast(c))); + ret += static_cast(cmsysString_tolower(c)); + ret += static_cast(cmsysString_toupper(c)); ret += ']'; } } diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index ad36c4a469..57d2a41e2a 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -3,7 +3,6 @@ #include "cmFindLibraryCommand.h" #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmFindCommon.h" #include "cmGlobalGenerator.h" @@ -349,7 +349,7 @@ void cmFindLibraryHelper::RegexFromLiteral(std::string& out, out += "\\"; } if (dirCase == cmSystemTools::DirCase::Insensitive) { - out += static_cast(tolower(static_cast(ch))); + out += static_cast(cmsysString_tolower(ch)); } else { out += ch; } diff --git a/Source/cmGccDepfileLexerHelper.cxx b/Source/cmGccDepfileLexerHelper.cxx index 3136f69dd1..478a93d393 100644 --- a/Source/cmGccDepfileLexerHelper.cxx +++ b/Source/cmGccDepfileLexerHelper.cxx @@ -12,9 +12,8 @@ #include "LexerParser/cmGccDepfileLexer.h" #ifdef _WIN32 -# include - # include "cmsys/Encoding.h" +# include "cmsys/String.h" #endif bool cmGccDepfileLexerHelper::readFile(char const* filePath) @@ -128,8 +127,7 @@ void cmGccDepfileLexerHelper::sanitizeContent() // Some versions of GNU compilers can escape this character. // c\:\path must be transformed to c:\path if (pit->size() >= 3) { - auto pit0 = static_cast( - std::toupper(static_cast((*pit)[0]))); + auto pit0 = static_cast(cmsysString_toupper((*pit)[0])); if (pit0 >= 'A' && pit0 <= 'Z' && (*pit)[1] == '\\' && (*pit)[2] == ':') { pit->erase(1, 1); diff --git a/Source/cmPathResolver.cxx b/Source/cmPathResolver.cxx index 67d63b94c5..f67dcbd396 100644 --- a/Source/cmPathResolver.cxx +++ b/Source/cmPathResolver.cxx @@ -16,6 +16,8 @@ # include # include + +# include #endif #define MAX_SYMBOLIC_LINKS 32 @@ -171,8 +173,7 @@ std::string ImplBase::GetWorkingDirectoryOnDrive(char letter) std::string d = this->OS.GetWorkingDirectoryOnDrive(letter); std::replace(d.begin(), d.end(), '\\', '/'); if (d.size() >= 3 && - std::toupper(static_cast(d[0])) == - std::toupper(static_cast(letter)) && + cmsysString_toupper(d[0]) == cmsysString_toupper(letter) && d[1] == ':' && d[2] == '/') { d[0] = letter; d.push_back('/'); @@ -182,8 +183,7 @@ std::string ImplBase::GetWorkingDirectoryOnDrive(char letter) // Use the current working directory if the drive matches. d = this->OS.GetWorkingDirectory(); if (d.size() >= 3 && - std::toupper(static_cast(d[0])) == - std::toupper(static_cast(letter)) && + cmsysString_toupper(d[0]) == cmsysString_toupper(letter) && d[1] == ':' && d[2] == '/') { d[0] = letter; d.push_back('/'); @@ -284,7 +284,7 @@ Control Impl::ResolveRoot(Root root) if (Policy::ActualCase == Options::ActualCase::Yes) { // Normalize the drive letter to upper-case. - P[0] = static_cast(std::toupper(static_cast(P[0]))); + P[0] = static_cast(cmsysString_toupper(P[0])); } // The root is a drive letter. The root '/' immediately follows. diff --git a/Source/cmSbomArguments.cxx b/Source/cmSbomArguments.cxx index b9394488b6..76322ab494 100644 --- a/Source/cmSbomArguments.cxx +++ b/Source/cmSbomArguments.cxx @@ -3,10 +3,11 @@ #include "cmSbomArguments.h" #include -#include #include +#include "cmsys/String.h" + #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmStringAlgorithms.h" @@ -99,6 +100,6 @@ std::string cmSbomArguments::GetPackageFileName() const std::string const pkgNameOnDisk = this->GetPackageDirName(); std::string format = GetSbomFileExtension(this->GetFormat()); std::transform(format.begin(), format.end(), format.begin(), - [](unsigned char c) { return std::tolower(c); }); + cmsysString_tolower); return cmStrCat(pkgNameOnDisk, format); } diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx index d46019bf7c..c2f3a55c57 100644 --- a/Source/cmStringAlgorithms.cxx +++ b/Source/cmStringAlgorithms.cxx @@ -8,15 +8,17 @@ #include #include +#include "cmsys/String.h" + bool cmStrCaseEq(cm::string_view s1, cm::string_view s2) { if (s1.size() != s2.size()) { return false; } - return std::equal( - s1.begin(), s1.end(), s2.begin(), - [](unsigned char a, unsigned char b) { return tolower(a) == tolower(b); }); + return std::equal(s1.begin(), s1.end(), s2.begin(), [](char a, char b) { + return cmsysString_tolower(a) == cmsysString_tolower(b); + }); } std::string cmTrimWhitespace(cm::string_view str) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1d15b55007..cb088e9e13 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -101,6 +101,7 @@ #include "cmsys/Directory.hxx" #ifdef _WIN32 # include "cmsys/Encoding.hxx" +# include "cmsys/String.h" #endif #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" @@ -1340,7 +1341,7 @@ std::string cmSystemTools::GetRealPathResolvingWindowsSubst( } // Normalize to upper-case drive letter as cm::PathResolver does. if (resolved_path.size() > 1 && resolved_path[1] == ':') { - resolved_path[0] = toupper(static_cast(resolved_path[0])); + resolved_path[0] = cmsysString_toupper(resolved_path[0]); } return resolved_path; #else @@ -1362,12 +1363,10 @@ std::string cmSystemTools::GetRealPath(std::string const& path, // limitation to otherwise preserve susbt drives. if (resolved_path.size() >= 2 && resolved_path[1] == ':' && path.size() >= 2 && path[1] == ':' && - toupper(static_cast(resolved_path[0])) != - toupper(static_cast(path[0]))) { + cmsysString_toupper(resolved_path[0]) != cmsysString_toupper(path[0])) { // FIXME: Add thread_local or mutex if we use threads. static std::map substMap; - char const drive = - static_cast(toupper(static_cast(path[0]))); + char const drive = static_cast(cmsysString_toupper(path[0])); std::string maybe_subst = cmStrCat(drive, ":/"); auto smi = substMap.find(drive); if (smi == substMap.end()) { diff --git a/Source/cmWindowsRegistry.cxx b/Source/cmWindowsRegistry.cxx index 9d9de8c3a3..ecce2f55d3 100644 --- a/Source/cmWindowsRegistry.cxx +++ b/Source/cmWindowsRegistry.cxx @@ -4,7 +4,6 @@ #include "cmWindowsRegistry.h" -#include #include #include #include @@ -13,6 +12,7 @@ #include #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #if defined(_WIN32) && !defined(__CYGWIN__) # include @@ -47,8 +47,8 @@ int Strucmp(cm::string_view l, cm::string_view r) cm::string_view::size_type ri = 0; do { - lc = std::tolower(static_cast(l[li++])); - rc = std::tolower(static_cast(r[ri++])); + lc = cmsysString_tolower(l[li++]); + rc = cmsysString_tolower(r[ri++]); } while (lc == rc && li < l.size() && ri < r.size()); return lc == rc ? static_cast(l.size() - r.size()) : lc - rc; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 42fe88a8ce..35346afd38 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -20,6 +19,8 @@ #include +#include "cmsys/String.h" + #include "cmBuildArgs.h" #include "cmBuildOptions.h" #include "cmCommandLineArgument.h" @@ -500,8 +501,7 @@ int do_build(int ac, char const* const* av) }; auto resolvePackagesLambda = [&](std::string const& value) -> bool { std::string v = value; - std::transform(v.begin(), v.end(), v.begin(), - [](unsigned char c) { return std::tolower(c); }); + std::transform(v.begin(), v.end(), v.begin(), cmsysString_tolower); if (v == "on") { resolveMode = PackageResolveMode::Force; } else if (v == "only") { diff --git a/Tests/CMakeLib/testPathResolver.cxx b/Tests/CMakeLib/testPathResolver.cxx index 6a38c3148c..ce759e50d5 100644 --- a/Tests/CMakeLib/testPathResolver.cxx +++ b/Tests/CMakeLib/testPathResolver.cxx @@ -9,7 +9,7 @@ #include #ifdef _WIN32 -# include +# include #endif #include @@ -92,8 +92,7 @@ public: std::string GetWorkingDirectoryOnDrive(char letter) override { std::string result; - auto i = this->WorkDirOnDrive.find( - std::tolower(static_cast(letter))); + auto i = this->WorkDirOnDrive.find(cmsysString_tolower(letter)); if (i != this->WorkDirOnDrive.end()) { result = i->second; } diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx index ea843d9922..50ad761b54 100644 --- a/Tests/CMakeLib/testUVProcessChainHelper.cxx +++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx @@ -1,4 +1,3 @@ -#include #include #include #include @@ -7,6 +6,7 @@ #include #include +#include "cmsys/String.h" #include "cmsys/SystemTools.hxx" #ifdef _WIN32 @@ -41,7 +41,7 @@ int main(int argc, char** argv) std::this_thread::sleep_for(std::chrono::milliseconds(12000)); std::string input = getStdin(); for (auto& c : input) { - c = static_cast(std::toupper(static_cast(c))); + c = static_cast(cmsysString_toupper(c)); } std::cout << input << std::flush; std::cerr << "2" << std::flush;