Make character classification locale-independent

Use ASCII-only ctype operations provided by KWSys String.
These match the "C" locale in which `cmake` has long run.
This commit is contained in:
Brad King
2026-02-11 11:55:54 -05:00
parent ea47c154e5
commit 6ec707312d
28 changed files with 114 additions and 121 deletions
+4 -6
View File
@@ -4,7 +4,6 @@
#include "cmCPackAppImageGenerator.h"
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <utility>
#include <vector>
@@ -14,6 +13,7 @@
#include <sys/types.h>
#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
+5 -4
View File
@@ -11,6 +11,7 @@
#include <cmext/algorithm>
#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 <person@domain.com> 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);
+3 -1
View File
@@ -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);
+2 -1
View File
@@ -72,6 +72,7 @@
# include <windows.h>
# 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
@@ -4,7 +4,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <initializer_list>
#include <map>
@@ -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<std::pair<std::string, std::string>> 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<std::pair<std::string, std::string>> 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<std::pair<std::string, std::string>> 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<std::string, std::string> GetOSReleaseVariables(
auto const& filename = cmSystemTools::GetFilenameName(filepath);
// NOTE Minimum filename length expected:
// NNN-<at-least-one-char-name>.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),
+2 -2
View File
@@ -3,7 +3,6 @@
#include "cmCTest.h"
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cstdint>
#include <cstdio>
@@ -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<char>(strtoul(buf, nullptr, 16)));
c += 2;
+3 -3
View File
@@ -2,11 +2,11 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#pragma once
#include <cctype>
#include <cm/optional>
#include <cm/string_view>
#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]));
}
};
+2 -2
View File
@@ -3,13 +3,13 @@
#include "cmDocumentation.h"
#include <algorithm>
#include <cctype>
#include <cstring>
#include <utility>
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
#include "cmsys/String.h"
#if !defined(CMAKE_BOOTSTRAP)
# include <memory>
@@ -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;
}
+3 -1
View File
@@ -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)
+3 -7
View File
@@ -4,13 +4,14 @@ file LICENSE.rst or https://cmake.org/licensing for details. */
#include <algorithm>
#include <array>
#include <cctype>
#include <cstdlib>
#include <utility>
#include <cm/string_view>
#include <cmext/string_view>
#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<unsigned char>(ch));
}
std::string processObjectKindVersions(cmFileAPI& fileApi,
cmFileAPI::ObjectKind objectKind,
cm::string_view keyword,
@@ -103,7 +99,7 @@ bool handleQueryCommand(std::vector<std::string> 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;
}
+5 -4
View File
@@ -4,7 +4,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@@ -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<std::string> const& args,
}
if (c >= 0 && c <= 0xFF &&
(isprint(c) || c == '\t' || (c == '\n' && newline_consume))) {
(cmsysString_isprint(static_cast<char>(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<std::string> 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<std::string> 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();
+3 -3
View File
@@ -5,7 +5,6 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <cstdio>
#include <cstring>
@@ -20,6 +19,8 @@
#include <cmext/algorithm>
#include <cmext/string_view>
#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(
+2 -2
View File
@@ -4,7 +4,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <functional>
#include <iterator>
@@ -23,6 +22,7 @@
#include <cm3p/json/writer.h>
#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];
+2 -2
View File
@@ -3,7 +3,6 @@
#include "cmGraphVizWriter.h"
#include <algorithm>
#include <cctype>
#include <iostream>
#include <memory>
#include <set>
@@ -13,6 +12,7 @@
#include <cm/memory>
#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<char>{ '.', '-', '_' };
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;
}
}
+3 -2
View File
@@ -2,10 +2,11 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmHexFileConverter.h"
#include <cctype>
#include <cstdio>
#include <cstring>
#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;
}
}
+4 -6
View File
@@ -3,7 +3,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmInstrumentationCommand.h"
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <functional>
#include <set>
@@ -14,6 +13,8 @@ file LICENSE.rst or https://cmake.org/licensing for details. */
#include <cm3p/json/reader.h>
#include <cm3p/json/value.h>
#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<unsigned char>(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;
}
+4 -4
View File
@@ -5,7 +5,6 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <initializer_list>
@@ -23,6 +22,7 @@
#include <cmext/string_view>
#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(
+6 -6
View File
@@ -6,7 +6,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -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: '",
+3 -2
View File
@@ -4,7 +4,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <set>
#include <vector>
@@ -13,6 +12,8 @@
# include <utility>
#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<int>(c))));
return c && (c == '_' || cmsysString_isalpha((static_cast<int>(c))));
}
bool cmOutputConverter::Shell_CharNeedsQuotes(char c, int flags)
+1 -3
View File
@@ -13,8 +13,6 @@
#include <cmext/string_view>
#ifdef _WIN32
# include <cctype>
# include <windows.h>
# include <cmsys/String.h>
@@ -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] != '/') {
+22 -20
View File
@@ -4,7 +4,6 @@
#include "cmPkgConfigResolver.h"
#include <algorithm>
#include <cctype>
#include <cstring>
#include <iterator>
#include <string>
@@ -15,6 +14,8 @@
#include <cm/optional>
#include <cm/string_view>
#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<cm::string_view> cmPkgConfigResolver::TokenizeFlags(
std::vector<cm::string_view> 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<cm::string_view> 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<cmPkgConfigDependency> 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<cmPkgConfigDependency> 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<cmPkgConfigDependency> 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;
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmPlaceholderExpander.h"
#include <cctype>
#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
+3 -2
View File
@@ -3,12 +3,13 @@
#include "cmPolicies.h"
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <vector>
#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;
}
}
+3 -2
View File
@@ -8,6 +8,7 @@
#include <utility>
#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()) {
+2 -2
View File
@@ -3,7 +3,6 @@
#include "cmScanDepFormat.h"
#include <cctype>
#include <cstdio>
#include <utility>
@@ -16,6 +15,7 @@
#include <cm3p/json/writer.h>
#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];
+6 -6
View File
@@ -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 == '-') {
-10
View File
@@ -4,7 +4,6 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <cctype>
#include <cstring>
#include <initializer_list>
#include <iterator>
@@ -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<unsigned char>(ch));
}
/** Returns a string that has whitespace removed from the start and the end. */
std::string cmTrimWhitespace(cm::string_view str);
+9 -9
View File
@@ -77,7 +77,6 @@
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cstdint>
#include <cstdio>
@@ -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. */