diff --git a/Source/CPack/cmCPackAppImageGenerator.cxx b/Source/CPack/cmCPackAppImageGenerator.cxx index c6d4d8a919..03dffab464 100644 --- a/Source/CPack/cmCPackAppImageGenerator.cxx +++ b/Source/CPack/cmCPackAppImageGenerator.cxx @@ -4,7 +4,6 @@ #include "cmCPackAppImageGenerator.h" #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include "cmsys/FStream.hxx" +#include "cmsys/String.h" #include "cmCPackLog.h" #include "cmELF.h" @@ -340,11 +340,9 @@ namespace { // Trim leading and trailing whitespace from a string std::string trim(std::string const& str) { - auto start = std::find_if_not( - str.begin(), str.end(), [](unsigned char c) { return std::isspace(c); }); - auto end = std::find_if_not(str.rbegin(), str.rend(), [](unsigned char c) { - return std::isspace(c); - }).base(); + auto start = std::find_if_not(str.begin(), str.end(), cmsysString_isspace); + auto end = + std::find_if_not(str.rbegin(), str.rend(), cmsysString_isspace).base(); return (start < end) ? std::string(start, end) : std::string(); } } // namespace diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 52adedd925..fdb0bb74ec 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -11,6 +11,7 @@ #include #include "cmsys/FStream.hxx" +#include "cmsys/String.h" #include "cmCTest.h" #include "cmCTestVC.h" @@ -412,14 +413,14 @@ protected: char const* ConsumeSpace(char const* c) { - while (*c && cmIsSpace(*c)) { + while (*c && cmsysString_isspace(*c)) { ++c; } return c; } char const* ConsumeField(char const* c) { - while (*c && !cmIsSpace(*c)) { + while (*c && !cmsysString_isspace(*c)) { ++c; } return c; @@ -479,7 +480,7 @@ private: { // Person Name 1234567890 +0000 char const* c = str; - while (*c && cmIsSpace(*c)) { + while (*c && cmsysString_isspace(*c)) { ++c; } @@ -488,7 +489,7 @@ private: ++c; } char const* name_last = c; - while (name_last != name_first && cmIsSpace(*(name_last - 1))) { + while (name_last != name_first && cmsysString_isspace(*(name_last - 1))) { --name_last; } person.Name.assign(name_first, name_last - name_first); diff --git a/Source/QtDialog/RegexExplorer.cxx b/Source/QtDialog/RegexExplorer.cxx index 9065f66d2f..b0333cf490 100644 --- a/Source/QtDialog/RegexExplorer.cxx +++ b/Source/QtDialog/RegexExplorer.cxx @@ -2,6 +2,8 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "RegexExplorer.h" +#include "cmsys/String.h" + RegexExplorer::RegexExplorer(QWidget* p) : QDialog(p) , m_matched(false) @@ -147,7 +149,7 @@ bool RegexExplorer::stripEscapes(std::string& source) } else if (nextc == 'n') { result.append(1, '\n'); in++; - } else if (isalnum(nextc) || nextc == '\0') { + } else if (cmsysString_isalnum(nextc) || nextc == '\0') { return false; } else { result.append(1, nextc); diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx index bbcb0bccc9..59680aa4fd 100644 --- a/Source/bindexplib.cxx +++ b/Source/bindexplib.cxx @@ -72,6 +72,7 @@ # include # include "cmsys/Encoding.hxx" +# include "cmsys/String.h" #endif #include "cmsys/FStream.hxx" @@ -261,7 +262,7 @@ public: } // clear out any leading spaces - while (isspace(symbol[0])) + while (cmsysString_isspace(symbol[0])) symbol.erase(0, 1); // if it starts with _ and has an @ then it is a __cdecl // so remove the @ stuff for the export diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 9674c520be..514f00c25c 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" +#include "cmsys/String.h" #include "cmsys/SystemInformation.hxx" #include "cmArgumentParser.h" @@ -218,10 +218,10 @@ cm::optional> ParseOSReleaseLine( for (auto ch : line) { switch (state) { case PARSE_KEY_1ST: - if (std::isalpha(ch) || ch == '_') { + if (cmsysString_isalpha(ch) || ch == '_') { key += ch; state = PARSE_KEY; - } else if (!cmIsSpace(ch)) { + } else if (!cmsysString_isspace(ch)) { state = IGNORE_REST; } break; @@ -229,7 +229,7 @@ cm::optional> ParseOSReleaseLine( case PARSE_KEY: if (ch == '=') { state = FOUND_EQ; - } else if (std::isalnum(ch) || ch == '_') { + } else if (cmsysString_isalnum(ch) || ch == '_') { key += ch; } else { state = IGNORE_REST; @@ -281,7 +281,7 @@ cm::optional> ParseOSReleaseLine( break; case PARSE_VALUE: - if (ch == '#' || cmIsSpace(ch)) { + if (ch == '#' || cmsysString_isspace(ch)) { state = IGNORE_REST; } else { value += ch; @@ -355,8 +355,8 @@ std::map GetOSReleaseVariables( auto const& filename = cmSystemTools::GetFilenameName(filepath); // NOTE Minimum filename length expected: // NNN-.cmake --> 11 - return (filename.size() < 11) || !std::isdigit(filename[0]) || - !std::isdigit(filename[1]) || !std::isdigit(filename[2]) || + return (filename.size() < 11) || !cmsysString_isdigit(filename[0]) || + !cmsysString_isdigit(filename[1]) || !cmsysString_isdigit(filename[2]) || filename[3] != '-'; }; scripts.erase(std::remove_if(scripts.begin(), scripts.end(), checkName), diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 3b8232561b..ed1516f9a1 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -3,7 +3,6 @@ #include "cmCTest.h" #include -#include #include #include #include @@ -300,7 +299,8 @@ std::string cmCTest::DecodeURL(std::string const& in) { std::string out; for (char const* c = in.c_str(); *c; ++c) { - if (*c == '%' && isxdigit(*(c + 1)) && isxdigit(*(c + 2))) { + if (*c == '%' && cmsysString_isxdigit(*(c + 1)) && + cmsysString_isxdigit(*(c + 2))) { char buf[3] = { *(c + 1), *(c + 2), 0 }; out.append(1, static_cast(strtoul(buf, nullptr, 16))); c += 2; diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index f11d1fb1a1..4c88f23491 100644 --- a/Source/cmCommandLineArgument.h +++ b/Source/cmCommandLineArgument.h @@ -2,11 +2,11 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #pragma once -#include - #include #include +#include "cmsys/String.h" + #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -288,6 +288,6 @@ private: static bool IsFlag(cm::string_view arg) { return !arg.empty() && arg[0] == '-' && - !(arg.size() >= 2 && std::isdigit(arg[1])); + !(arg.size() >= 2 && cmsysString_isdigit(arg[1])); } }; diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 35cf9e4bd5..66e3730dcf 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -3,13 +3,13 @@ #include "cmDocumentation.h" #include -#include #include #include #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #if !defined(CMAKE_BOOTSTRAP) # include @@ -516,7 +516,7 @@ void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern) std::string line; cmsys::ifstream fin(f.c_str()); while (fin && cmSystemTools::GetLineFromStream(fin, line)) { - if (!line.empty() && (isalnum(line[0]) || line[0] == '<')) { + if (!line.empty() && (cmsysString_isalnum(line[0]) || line[0] == '<')) { names.push_back(line); break; } diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 7050f0db9a..63dcb6079a 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -24,6 +24,8 @@ # include "cm_fileno.hxx" #endif +#include "cmsys/String.h" + #include "cmArgumentParser.h" #include "cmExecutionStatus.h" #include "cmList.h" @@ -40,7 +42,7 @@ namespace { bool cmExecuteProcessCommandIsWhitespace(char c) { - return (cmIsSpace(c) || c == '\n' || c == '\r'); + return (cmsysString_isspace(c) || c == '\n' || c == '\r'); } FILE* FopenCLOEXEC(std::string const& path, char const* mode) diff --git a/Source/cmFileAPICommand.cxx b/Source/cmFileAPICommand.cxx index dbd8f05199..091fbc8c8a 100644 --- a/Source/cmFileAPICommand.cxx +++ b/Source/cmFileAPICommand.cxx @@ -4,13 +4,14 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include #include -#include #include #include #include #include +#include "cmsys/String.h" + #include "cmArgumentParser.h" #include "cmArgumentParserTypes.h" #include "cmExecutionStatus.h" @@ -23,11 +24,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ namespace { -bool isCharDigit(char ch) -{ - return std::isdigit(static_cast(ch)); -} - std::string processObjectKindVersions(cmFileAPI& fileApi, cmFileAPI::ObjectKind objectKind, cm::string_view keyword, @@ -103,7 +99,7 @@ bool handleQueryCommand(std::vector const& args, } if (!std::all_of(arguments.ApiVersion.begin(), arguments.ApiVersion.end(), - isCharDigit)) { + cmsysString_isdigit)) { status.SetError("QUERY given non-integer API_VERSION."); return false; } diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 72a62b2078..16cd19bf8b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -26,6 +25,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cm_sys_stat.h" @@ -519,7 +519,8 @@ bool HandleStringsCommand(std::vector const& args, } if (c >= 0 && c <= 0xFF && - (isprint(c) || c == '\t' || (c == '\n' && newline_consume))) { + (cmsysString_isprint(static_cast(c)) || c == '\t' || + (c == '\n' && newline_consume))) { // This is an ASCII character that may be part of a string. // Cast added to avoid compiler warning. Cast is ok because // c is guaranteed to fit in char by the above if... @@ -3767,7 +3768,7 @@ bool HandleArchiveCreateCommand(std::vector const& args, if (!parsedArgs.CompressionLevel.empty()) { if (parsedArgs.CompressionLevel.size() != 1 && - !std::isdigit(parsedArgs.CompressionLevel[0])) { + !cmsysString_isdigit(parsedArgs.CompressionLevel[0])) { status.SetError( cmStrCat("compression level ", parsedArgs.CompressionLevel, " for ", parsedArgs.Compression, " should be in range ", @@ -3800,7 +3801,7 @@ bool HandleArchiveCreateCommand(std::vector const& args, constexpr int minThreads = 0; if (!parsedArgs.Threads.empty()) { if (parsedArgs.Threads.size() != 1 && - !std::isdigit(parsedArgs.Threads[0])) { + !cmsysString_isdigit(parsedArgs.Threads[0])) { status.SetError(cmStrCat("number of threads ", parsedArgs.Threads, " should be at least ", minThreads)); cmSystemTools::SetFatalErrorOccurred(); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c5f4e35aad..c94f025ec9 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +19,8 @@ #include #include +#include "cmsys/String.h" + #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" // IWYU pragma: keep #include "cmCryptoHash.h" @@ -3953,8 +3954,7 @@ std::string cmGeneratorTarget::GetLinkerTool(std::string const& lang, if (linkerType != "DEFAULT"_s) { auto isCMakeLinkerType = [](std::string const& type) -> bool { - return std::all_of(type.cbegin(), type.cend(), - [](char c) { return std::isupper(c); }); + return std::all_of(type.cbegin(), type.cend(), cmsysString_isupper); }; if (isCMakeLinkerType(linkerType)) { this->LocalGenerator->IssueMessage( diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 46bb45efdd..b14564174d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include #include "cmsys/FStream.hxx" +#include "cmsys/String.h" #include "cmCustomCommand.h" #include "cmCxxModuleMapper.h" @@ -172,7 +172,7 @@ std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name) // "." and all invalid characters as hexadecimal. std::string encoded; for (char i : name) { - if (isalnum(i) || i == '_' || i == '-') { + if (cmsysString_isalnum(i) || i == '_' || i == '-') { encoded += i; } else { char buf[16]; diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 53c9659670..baba225b2a 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -3,7 +3,6 @@ #include "cmGraphVizWriter.h" #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" @@ -602,7 +602,7 @@ std::string cmGraphVizWriter::PathSafeString(std::string const& str) auto const extra_chars = std::set{ '.', '-', '_' }; for (char c : str) { - if (std::isalnum(c) || extra_chars.find(c) != extra_chars.cend()) { + if (cmsysString_isalnum(c) || extra_chars.find(c) != extra_chars.cend()) { pathSafeStr += c; } } diff --git a/Source/cmHexFileConverter.cxx b/Source/cmHexFileConverter.cxx index a028bb45e7..3036473e01 100644 --- a/Source/cmHexFileConverter.cxx +++ b/Source/cmHexFileConverter.cxx @@ -2,10 +2,11 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmHexFileConverter.h" -#include #include #include +#include "cmsys/String.h" + #include "cmSystemTools.h" #define INTEL_HEX_MIN_LINE_LENGTH (1 + 8 + 2) @@ -163,7 +164,7 @@ cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType( } for (unsigned int i = 1; i < slen; i++) { - if (!isxdigit(buf[i])) { + if (!cmsysString_isxdigit(buf[i])) { return Binary; } } diff --git a/Source/cmInstrumentationCommand.cxx b/Source/cmInstrumentationCommand.cxx index 182deca708..0b0d0f8c9c 100644 --- a/Source/cmInstrumentationCommand.cxx +++ b/Source/cmInstrumentationCommand.cxx @@ -3,7 +3,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmInstrumentationCommand.h" #include -#include #include #include #include @@ -14,6 +13,8 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include #include +#include "cmsys/String.h" + #include "cmArgumentParser.h" #include "cmArgumentParserTypes.h" #include "cmExecutionStatus.h" @@ -27,14 +28,11 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ namespace { -bool isCharDigit(char ch) -{ - return std::isdigit(static_cast(ch)); -} bool validateVersion(std::string const& key, std::string const& versionString, int& version, cmExecutionStatus& status) { - if (!std::all_of(versionString.begin(), versionString.end(), isCharDigit)) { + if (!std::all_of(versionString.begin(), versionString.end(), + cmsysString_isdigit)) { status.SetError(cmStrCat("given a non-integer ", key, '.')); return false; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5ce085125a..4a8c3d2ace 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmAlgorithms.h" #include "cmCMakePath.h" @@ -2556,7 +2556,8 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags, void cmLocalGenerator::AppendFlags(std::string& flags, std::string const& newFlags) const { - bool allSpaces = std::all_of(newFlags.begin(), newFlags.end(), cmIsSpace); + bool allSpaces = + std::all_of(newFlags.begin(), newFlags.end(), cmsysString_isspace); if (!newFlags.empty() && !allSpaces) { if (!flags.empty()) { @@ -3489,8 +3490,7 @@ void cmLocalGenerator::AppendLinkerTypeFlags(std::string& flags, } } else if (linkerType != "DEFAULT"_s) { auto isCMakeLinkerType = [](std::string const& type) -> bool { - return std::all_of(type.cbegin(), type.cend(), - [](char c) { return std::isupper(c); }); + return std::all_of(type.cbegin(), type.cend(), cmsysString_isupper); }; if (isCMakeLinkerType(linkerType)) { this->IssueMessage( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a78fc1e74f..6ff3489e9c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -28,6 +27,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -1299,8 +1299,8 @@ static void s_RemoveDefineFlag(std::string const& flag, std::string& dflags) for (std::string::size_type lpos = dflags.find(flag, 0); lpos != std::string::npos; lpos = dflags.find(flag, lpos)) { std::string::size_type rpos = lpos + len; - if ((lpos <= 0 || cmIsSpace(dflags[lpos - 1])) && - (rpos >= dflags.size() || cmIsSpace(dflags[rpos]))) { + if ((lpos <= 0 || cmsysString_isspace(dflags[lpos - 1])) && + (rpos >= dflags.size() || cmsysString_isspace(dflags[rpos]))) { dflags.erase(lpos, len); } else { ++lpos; @@ -2705,7 +2705,7 @@ MessageType cmMakefile::ExpandVariablesInStringImpl( last = next + 1; } else if (nextc == ';' && openstack.empty()) { // Handled in ExpandListArgument; pass the backslash literally. - } else if (isalnum(nextc) || nextc == '\0') { + } else if (cmsysString_isalnum(nextc) || nextc == '\0') { errorstr += "Invalid character escape '\\"; if (nextc) { errorstr += nextc; @@ -2773,8 +2773,8 @@ MessageType cmMakefile::ExpandVariablesInStringImpl( CM_FALLTHROUGH; default: { if (!openstack.empty() && - !(isalnum(inc) || inc == '_' || inc == '/' || inc == '.' || - inc == '+' || inc == '-')) { + !(cmsysString_isalnum(inc) || inc == '_' || inc == '/' || + inc == '.' || inc == '+' || inc == '-')) { errorstr += cmStrCat("Invalid character ('", inc); result.append(last, in - last); errorstr += cmStrCat("') in a variable name: '", diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index ddae68c92a..c72dbe45f0 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -13,6 +12,8 @@ # include #endif +#include "cmsys/String.h" + #include "cmList.h" #include "cmState.h" #include "cmStateDirectory.h" @@ -425,7 +426,7 @@ static bool Shell_CharNeedsQuotesOnWindows(char c) static bool Shell_CharIsMakeVariableName(char c) { - return c && (c == '_' || isalpha((static_cast(c)))); + return c && (c == '_' || cmsysString_isalpha((static_cast(c)))); } bool cmOutputConverter::Shell_CharNeedsQuotes(char c, int flags) diff --git a/Source/cmPathResolver.cxx b/Source/cmPathResolver.cxx index f67dcbd396..f384dbfe02 100644 --- a/Source/cmPathResolver.cxx +++ b/Source/cmPathResolver.cxx @@ -13,8 +13,6 @@ #include #ifdef _WIN32 -# include - # include # include @@ -97,7 +95,7 @@ private: Root ClassifyRoot(cm::string_view p) { #ifdef _WIN32 - if (p.size() >= 2 && std::isalpha(p[0]) && p[1] == ':') { + if (p.size() >= 2 && cmsysString_isalpha(p[0]) && p[1] == ':') { return Root::Drive; } if (p.size() >= 3 && p[0] == '/' && p[1] == '/' && p[2] != '/') { diff --git a/Source/cmPkgConfigResolver.cxx b/Source/cmPkgConfigResolver.cxx index 8be5f3408a..54598c80b3 100644 --- a/Source/cmPkgConfigResolver.cxx +++ b/Source/cmPkgConfigResolver.cxx @@ -4,7 +4,6 @@ #include "cmPkgConfigResolver.h" #include -#include #include #include #include @@ -15,6 +14,8 @@ #include #include +#include "cmsys/String.h" + #include "cmPkgConfigParser.h" #include "cmStringAlgorithms.h" @@ -24,7 +25,7 @@ void TrimBack(std::string& str) { if (!str.empty()) { auto it = str.end() - 1; - for (; std::isspace(*it); --it) { + for (; cmsysString_isspace(*it); --it) { if (it == str.begin()) { str.clear(); return; @@ -45,11 +46,11 @@ std::string AppendAndTrim(std::string& str, cm::string_view sv) auto begin = str.begin() + size; auto cur = str.end() - 1; - while (cur != begin && std::isspace(*cur)) { + while (cur != begin && cmsysString_isspace(*cur)) { --cur; } - if (std::isspace(*cur)) { + if (cmsysString_isspace(*cur)) { return {}; } @@ -59,7 +60,8 @@ std::string AppendAndTrim(std::string& str, cm::string_view sv) cm::string_view TrimFlag(cm::string_view flag) { std::size_t trim_size = 2; - for (auto c = flag.rbegin(); c != flag.rend() && std::isspace(*c); ++c) { + for (auto c = flag.rbegin(); c != flag.rend() && cmsysString_isspace(*c); + ++c) { ++trim_size; } return { flag.data() + 2, flag.size() - trim_size }; @@ -406,7 +408,7 @@ std::vector cmPkgConfigResolver::TokenizeFlags( std::vector result; auto it = flagline.begin(); - while (it != flagline.end() && std::isspace(*it)) { + while (it != flagline.end() && cmsysString_isspace(*it)) { ++it; } @@ -414,11 +416,11 @@ std::vector cmPkgConfigResolver::TokenizeFlags( char const* start = &(*it); std::size_t len = 0; - for (; it != flagline.end() && !std::isspace(*it); ++it) { + for (; it != flagline.end() && !cmsysString_isspace(*it); ++it) { ++len; } - for (; it != flagline.end() && std::isspace(*it); ++it) { + for (; it != flagline.end() && cmsysString_isspace(*it); ++it) { ++len; } @@ -665,12 +667,12 @@ cmPkgConfigVersionReq cmPkgConfigResolver::ParseVersion( return result; } - if (!std::isspace(*cur)) { + if (!cmsysString_isspace(*cur)) { break; } } - for (; cur != end && !std::isspace(*cur) && *cur != ','; ++cur) { + for (; cur != end && !cmsysString_isspace(*cur) && *cur != ','; ++cur) { result.Version += *cur; } @@ -687,7 +689,7 @@ std::vector cmPkgConfigResolver::ParseDependencies( auto end = deps.end(); while (cur != end) { - while ((std::isspace(*cur) || *cur == ',')) { + while ((cmsysString_isspace(*cur) || *cur == ',')) { if (++cur == end) { return result; } @@ -696,7 +698,7 @@ std::vector cmPkgConfigResolver::ParseDependencies( result.emplace_back(); auto& dep = result.back(); - while (!std::isspace(*cur) && *cur != ',') { + while (!cmsysString_isspace(*cur) && *cur != ',') { dep.Name += *cur; if (++cur == end) { return result; @@ -713,7 +715,7 @@ std::vector cmPkgConfigResolver::ParseDependencies( return true; } - if (!std::isspace(*cur)) { + if (!cmsysString_isspace(*cur)) { return false; } } @@ -769,11 +771,11 @@ bool cmPkgConfigResolver::CheckVersion(cmPkgConfigVersionReq const& desired, auto b_end = provided.end(); while (a_cur != a_end && b_cur != b_end) { - while (a_cur != a_end && !std::isalnum(*a_cur) && *a_cur != '~') { + while (a_cur != a_end && !cmsysString_isalnum(*a_cur) && *a_cur != '~') { ++a_cur; } - while (b_cur != b_end && !std::isalnum(*b_cur) && *b_cur != '~') { + while (b_cur != b_end && !cmsysString_isalnum(*b_cur) && *b_cur != '~') { ++b_cur; } @@ -799,23 +801,23 @@ bool cmPkgConfigResolver::CheckVersion(cmPkgConfigVersionReq const& desired, auto b_seg = b_cur; bool is_num; - if (std::isdigit(*a_cur)) { + if (cmsysString_isdigit(*a_cur)) { is_num = true; - while (a_cur != a_end && std::isdigit(*a_cur)) { + while (a_cur != a_end && cmsysString_isdigit(*a_cur)) { ++a_cur; } - while (b_cur != b_end && std::isdigit(*b_cur)) { + while (b_cur != b_end && cmsysString_isdigit(*b_cur)) { ++b_cur; } } else { is_num = false; - while (a_cur != a_end && std::isalpha(*a_cur)) { + while (a_cur != a_end && cmsysString_isalpha(*a_cur)) { ++a_cur; } - while (b_cur != b_end && std::isalpha(*b_cur)) { + while (b_cur != b_end && cmsysString_isalpha(*b_cur)) { ++b_cur; } } diff --git a/Source/cmPlaceholderExpander.cxx b/Source/cmPlaceholderExpander.cxx index f5dc544373..aea427b681 100644 --- a/Source/cmPlaceholderExpander.cxx +++ b/Source/cmPlaceholderExpander.cxx @@ -2,7 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmPlaceholderExpander.h" -#include +#include "cmsys/String.h" std::string& cmPlaceholderExpander::ExpandVariables(std::string& s) { @@ -23,7 +23,7 @@ std::string& cmPlaceholderExpander::ExpandVariables(std::string& s) char c = s[start + 1]; // if the next char after the < is not A-Za-z then // skip it and try to find the next < in the string - if (!isalpha(c)) { + if (!cmsysString_isalpha(c)) { start = s.find('<', start + 1); } else { // extract the var diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 45838630b3..337f220059 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -3,12 +3,13 @@ #include "cmPolicies.h" #include -#include #include #include #include #include +#include "cmsys/String.h" + #include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -32,7 +33,7 @@ static bool stringToId(char const* input, cmPolicies::PolicyID& pid) return true; } for (int i = 3; i < 7; ++i) { - if (!isdigit(*(input + i))) { + if (!cmsysString_isdigit(*(input + i))) { return false; } } diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index 51245d67bb..e49037099e 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -8,6 +8,7 @@ #include #include "cmsys/FStream.hxx" +#include "cmsys/String.h" #include "cmAlgorithms.h" #include "cmRange.h" @@ -158,7 +159,7 @@ void cmRST::ProcessLine(std::string const& line) // A line starting in .. is an explicit markup start. if (line == ".." || (line.size() >= 3 && line[0] == '.' && line[1] == '.' && - cmIsSpace(line[2]))) { + cmsysString_isspace(line[2]))) { this->Reset(); this->MarkupType = (line.find_first_not_of(" \t", 2) == std::string::npos ? Markup::Empty @@ -218,7 +219,7 @@ void cmRST::ProcessLine(std::string const& line) } // Indented lines following an explicit markup start are explicit markup. else if (this->MarkupType != Markup::None && - (line.empty() || cmIsSpace(line[0]))) { + (line.empty() || cmsysString_isspace(line[0]))) { this->MarkupType = Markup::Normal; // Record markup lines if the start line was recorded. if (!this->MarkupLines.empty()) { diff --git a/Source/cmScanDepFormat.cxx b/Source/cmScanDepFormat.cxx index bd3827388f..00165447e9 100644 --- a/Source/cmScanDepFormat.cxx +++ b/Source/cmScanDepFormat.cxx @@ -3,7 +3,6 @@ #include "cmScanDepFormat.h" -#include #include #include @@ -16,6 +15,7 @@ #include #include "cmsys/FStream.hxx" +#include "cmsys/String.h" #include "cmGeneratedFileStream.h" #include "cmStringAlgorithms.h" @@ -38,7 +38,7 @@ static Json::Value EncodeFilename(std::string const& path) data.reserve(path.size()); for (auto const& byte : path) { - if (std::iscntrl(byte)) { + if (cmsysString_iscntrl(byte)) { // Control characters. data.append("\\u"); char buf[5]; diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx index c2f3a55c57..e13c22691b 100644 --- a/Source/cmStringAlgorithms.cxx +++ b/Source/cmStringAlgorithms.cxx @@ -27,7 +27,7 @@ std::string cmTrimWhitespace(cm::string_view str) // because the qualification of `auto` is platform-dependent. // NOLINTNEXTLINE(readability-qualified-auto) auto start = str.begin(); - while (start != str.end() && cmIsSpace(*start)) { + while (start != str.end() && cmsysString_isspace(*start)) { ++start; } if (start == str.end()) { @@ -35,7 +35,7 @@ std::string cmTrimWhitespace(cm::string_view str) } // NOLINTNEXTLINE(readability-qualified-auto) auto stop = str.end() - 1; - while (cmIsSpace(*stop)) { + while (cmsysString_isspace(*stop)) { --stop; } return std::string(start, stop + 1); @@ -46,14 +46,14 @@ cm::string_view cmStripWhitespace(cm::string_view str) std::string::size_type const l = str.size(); std::string::size_type s = 0; - while (s < l && cmIsSpace(str[s])) { + while (s < l && cmsysString_isspace(str[s])) { ++s; } if (s == l) { return cm::string_view{}; } std::string::size_type e = l - 1; - while (cmIsSpace(str[e])) { + while (cmsysString_isspace(str[e])) { --e; } return str.substr(s, e + 1 - s); @@ -198,7 +198,7 @@ bool cmStrToULong(char const* str, unsigned long* value) { errno = 0; char* endp; - while (cmIsSpace(*str)) { + while (cmsysString_isspace(*str)) { ++str; } if (*str == '-') { @@ -230,7 +230,7 @@ bool cmStrToULongLong(char const* str, unsigned long long* value) { errno = 0; char* endp; - while (cmIsSpace(*str)) { + while (cmsysString_isspace(*str)) { ++str; } if (*str == '-') { diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index d847ece5bd..966091afd3 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -4,7 +4,6 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include #include #include #include @@ -50,15 +49,6 @@ private: */ bool cmStrCaseEq(cm::string_view a, cm::string_view b); -/** Returns true if the character @a ch is a whitespace character. **/ -inline bool cmIsSpace(char ch) -{ - // isspace takes 'int' but documents that the value must be representable - // by 'unsigned char', or be EOF. Cast to 'unsigned char' to avoid sign - // extension while converting to 'int'. - return std::isspace(static_cast(ch)); -} - /** Returns a string that has whitespace removed from the start and the end. */ std::string cmTrimWhitespace(cm::string_view str); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index cb088e9e13..780c83a186 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -77,7 +77,6 @@ #include #include -#include #include #include #include @@ -101,10 +100,10 @@ #include "cmsys/Directory.hxx" #ifdef _WIN32 # include "cmsys/Encoding.hxx" -# include "cmsys/String.h" #endif #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmsys/String.h" #include "cmsys/System.h" #if defined(_WIN32) @@ -575,7 +574,7 @@ void cmSystemTools::ParseWindowsCommandLine(char const* command, } else { arg.append(backslashes, '\\'); backslashes = 0; - if (cmIsSpace(*c)) { + if (cmsysString_isspace(*c)) { if (in_quotes) { arg.append(1, *c); } else if (in_argument) { @@ -734,7 +733,7 @@ bool cmSystemTools::SplitProgramFromArgs(std::string const& command, char const* c = command.c_str(); // Skip leading whitespace. - while (cmIsSpace(*c)) { + while (cmsysString_isspace(*c)) { ++c; } @@ -764,7 +763,7 @@ bool cmSystemTools::SplitProgramFromArgs(std::string const& command, in_double = true; } else if (*c == '\'') { in_single = true; - } else if (cmIsSpace(*c)) { + } else if (cmsysString_isspace(*c)) { break; } else { program += *c; @@ -3865,7 +3864,7 @@ static size_t cm_strverscmp_find_first_difference_or_end(char const* lhs, static size_t cm_strverscmp_find_digits_begin(char const* s, size_t i) { /* Step back until we are not preceded by a digit. */ - while (i > 0 && isdigit(s[i - 1])) { + while (i > 0 && cmsysString_isdigit(s[i - 1])) { --i; } return i; @@ -3874,7 +3873,7 @@ static size_t cm_strverscmp_find_digits_begin(char const* s, size_t i) static size_t cm_strverscmp_find_digits_end(char const* s, size_t i) { /* Step forward over digits. */ - while (isdigit(s[i])) { + while (cmsysString_isdigit(s[i])) { ++i; } return i; @@ -3884,7 +3883,7 @@ static size_t cm_strverscmp_count_leading_zeros(char const* s, size_t b) { size_t i = b; /* Step forward over zeros that are followed by another digit. */ - while (s[i] == '0' && isdigit(s[i + 1])) { + while (s[i] == '0' && cmsysString_isdigit(s[i + 1])) { ++i; } return i - b; @@ -3896,7 +3895,8 @@ static int cm_strverscmp(char const* lhs, char const* rhs) if (lhs[i] != rhs[i]) { /* The strings differ starting at 'i'. Check for a digit sequence. */ size_t const b = cm_strverscmp_find_digits_begin(lhs, i); - if (b != i || (isdigit(lhs[i]) && isdigit(rhs[i]))) { + if (b != i || + (cmsysString_isdigit(lhs[i]) && cmsysString_isdigit(rhs[i]))) { /* A digit sequence starts at 'b', preceding or at 'i'. */ /* Look for leading zeros, implying a leading decimal point. */