diff --git a/apps/opencs/model/filter/parser.cpp b/apps/opencs/model/filter/parser.cpp index b8f125e237..d363b4849d 100644 --- a/apps/opencs/model/filter/parser.cpp +++ b/apps/opencs/model/filter/parser.cpp @@ -17,19 +17,6 @@ #include "textnode.hpp" #include "valuenode.hpp" -namespace -{ - bool isAlpha(char c) - { - return c >= 0 && c <= 255 && std::isalpha(c); - } - - bool isDigit(char c) - { - return c >= 0 && c <= 255 && std::isdigit(c); - } -} - namespace CSMFilter { struct Token @@ -116,7 +103,7 @@ CSMFilter::Token CSMFilter::Parser::getStringToken() { char c = mInput[mIndex]; - if (isAlpha(c) || c==':' || c=='_' || (!string.empty() && isDigit(c)) || c=='"' || + if (std::isalpha (c) || c==':' || c=='_' || (!string.empty() && std::isdigit (c)) || c=='"' || (!string.empty() && string[0]=='"')) string += c; else @@ -163,7 +150,7 @@ CSMFilter::Token CSMFilter::Parser::getNumberToken() { char c = mInput[mIndex]; - if (isDigit(c)) + if (std::isdigit (c)) { string += c; hasDigit = true; @@ -238,10 +225,10 @@ CSMFilter::Token CSMFilter::Parser::getNextToken() case '!': ++mIndex; return Token (Token::Type_OneShot); } - if (c=='"' || c=='_' || isAlpha(c) || c==':') + if (c=='"' || c=='_' || std::isalpha (c) || c==':') return getStringToken(); - if (c=='-' || c=='.' || isDigit(c)) + if (c=='-' || c=='.' || std::isdigit (c)) return getNumberToken(); error(); diff --git a/components/lua/configuration.cpp b/components/lua/configuration.cpp index d059d1716f..4598ed2508 100644 --- a/components/lua/configuration.cpp +++ b/components/lua/configuration.cpp @@ -30,11 +30,6 @@ namespace LuaUtil {"POTION", ESM::LuaScriptCfg::sPotion}, {"WEAPON", ESM::LuaScriptCfg::sWeapon}, }; - - bool isSpace(int c) - { - return c >= 0 && c <= 255 && std::isspace(c); - } } const std::vector ScriptsConfiguration::sEmpty; @@ -106,11 +101,11 @@ namespace LuaUtil if (!line.empty() && line.back() == '\r') line = line.substr(0, line.size() - 1); - while (!line.empty() && isSpace(line[0])) + while (!line.empty() && std::isspace(line[0])) line = line.substr(1); if (line.empty() || line[0] == '#') // Skip empty lines and comments continue; - while (!line.empty() && isSpace(line.back())) + while (!line.empty() && std::isspace(line.back())) line = line.substr(0, line.size() - 1); if (!Misc::StringUtils::ciEndsWith(line, ".lua")) @@ -123,7 +118,7 @@ namespace LuaUtil throw std::runtime_error(Misc::StringUtils::format("No flags found in: %s", std::string(line))); std::string_view flagsStr = line.substr(0, semicolonPos); std::string_view scriptPath = line.substr(semicolonPos + 1); - while (isSpace(scriptPath[0])) + while (std::isspace(scriptPath[0])) scriptPath = scriptPath.substr(1); // Parse flags @@ -131,10 +126,10 @@ namespace LuaUtil size_t flagsPos = 0; while (true) { - while (flagsPos < flagsStr.size() && (isSpace(flagsStr[flagsPos]) || flagsStr[flagsPos] == ',')) + while (flagsPos < flagsStr.size() && (std::isspace(flagsStr[flagsPos]) || flagsStr[flagsPos] == ',')) flagsPos++; size_t startPos = flagsPos; - while (flagsPos < flagsStr.size() && !isSpace(flagsStr[flagsPos]) && flagsStr[flagsPos] != ',') + while (flagsPos < flagsStr.size() && !std::isspace(flagsStr[flagsPos]) && flagsStr[flagsPos] != ',') flagsPos++; if (startPos == flagsPos) break; diff --git a/components/misc/stringops.hpp b/components/misc/stringops.hpp index a0ec9f62dd..c8d236a9d0 100644 --- a/components/misc/stringops.hpp +++ b/components/misc/stringops.hpp @@ -184,10 +184,10 @@ public: static inline void trim(std::string &s) { - const auto notSpace = [](int ch) + const auto notSpace = [](char ch) { // TODO Do we care about multibyte whitespace? - return ch < 0 || ch > 255 || !std::isspace(ch); + return !std::isspace(ch); }; // left trim s.erase(s.begin(), std::find_if(s.begin(), s.end(), notSpace)); diff --git a/components/settings/parser.cpp b/components/settings/parser.cpp index f36f190ee2..f2419dfdd6 100644 --- a/components/settings/parser.cpp +++ b/components/settings/parser.cpp @@ -311,7 +311,7 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::string& file, con bool Settings::SettingsFileParser::skipWhiteSpace(size_t& i, std::string& str) { - while (i < str.size() && str[i] >= 0 && str[i] <= 255 && std::isspace(str[i], std::locale::classic())) + while (i < str.size() && std::isspace(str[i], std::locale::classic())) { ++i; }