From 7b624333fb8ba1156025f605bf3e7eec7395151b Mon Sep 17 00:00:00 2001 From: dashodanger Date: Mon, 24 Jun 2024 17:02:49 -0600 Subject: [PATCH] CI fixes --- source/images.h | 4 ++-- source/m_cookie.cc | 56 ++++++++++++++++++++++++++++------------------ source/m_cookie.h | 2 +- source/sys_macro.h | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/source/images.h b/source/images.h index 4cb8e3f55..c7fa60b43 100644 --- a/source/images.h +++ b/source/images.h @@ -3,7 +3,7 @@ #pragma once #ifndef _WIN32 -static constexpr char *obsidian_icon[] = { +static constexpr const char *obsidian_icon[] = { "64 64 928 2", " c #000000", ". c #010101", @@ -1065,7 +1065,7 @@ static constexpr char *obsidian_icon[] = { #endif /* XPM */ -static constexpr char *clippy_xpm[] = { +static constexpr const char *clippy_xpm[] = { "476 225 956 2", " c None", ". c #51514F", diff --git a/source/m_cookie.cc b/source/m_cookie.cc index 196bb91e3..8e15c309c 100644 --- a/source/m_cookie.cc +++ b/source/m_cookie.cc @@ -113,44 +113,56 @@ static void Cookie_SetValue(std::string name, const std::string &value) ob_set_config(name, value); } -static bool Cookie_ParseLine(std::string &buf) +static bool Cookie_ParseLine(std::string_view buf) { - if (buf.find('=') == std::string::npos) + if (buf.find('=') == std::string_view::npos) { // Skip blank lines, comments, etc return true; } - while (IsSpaceASCII(buf[0])) + while (!buf.empty() && IsSpaceASCII(buf.front())) { - buf.erase(buf.begin()); + buf.remove_prefix(1); } - if (!(isalpha(buf.front()) || buf.front() == '@')) + if (buf.empty() || !(IsAlphaASCII(buf.front()) || buf.front() == '@')) { - LogPrint("Weird config line: [%s]\n", buf.c_str()); + LogPrint("Weird config line: [%s]\n", std::string(buf).c_str()); return false; } - std::string::size_type pos = buf.find('='); + std::string_view::size_type pos = buf.find('='); - while (pos > 0 && IsSpaceASCII(buf[pos - 1])) + // Shouldn't happen but still + if (pos == std::string_view::npos) { - buf.erase(buf.begin() + (pos - 1)); - pos--; - } - while (pos + 1 < buf.size() && IsSpaceASCII(buf[pos + 1])) - { - buf.erase(buf.begin() + (pos + 1)); + LogPrint("Malformed config line: [%s]\n", std::string(buf).c_str()); + return false; } - while (IsSpaceASCII(buf[buf.size() - 1])) + + std::string name = std::string(buf.substr(0, pos)); + + if (pos + 1 >= buf.size()) { - buf.erase(buf.end() - 1); + LogPrint("Value missing!\n"); + return false; } - std::string name = buf.substr(0, pos); - std::string value = buf.substr(pos + 1); + std::string value = std::string(buf.substr(pos+1)); + while (!name.empty() && IsSpaceASCII(name.back())) + { + name.pop_back(); + } + while (!value.empty() && IsSpaceASCII(value.front())) + { + value.erase(value.begin()); + } + while (!value.empty() && IsSpaceASCII(value.back())) + { + value.pop_back(); + } if (name.empty() || value.empty()) { LogPrint("Name or value missing!\n"); @@ -226,7 +238,7 @@ bool Cookie_Load(const std::string &filename) return true; } -bool Cookie_LoadString(const std::string &str, bool _keep_seed) +bool Cookie_LoadString(std::string_view str, bool _keep_seed) { context = cookie_context_e::Load; keep_seed = _keep_seed; @@ -235,12 +247,12 @@ bool Cookie_LoadString(const std::string &str, bool _keep_seed) LogPrint("Reading config data...\n"); - std::string::size_type oldpos = 0; - std::string::size_type pos = 0; + std::string_view::size_type oldpos = 0; + std::string_view::size_type pos = 0; while (pos != std::string::npos) { pos = str.find('\n', oldpos); - if (pos != std::string::npos) + if (pos != std::string_view::npos) { Cookie_ParseLine(str.substr(oldpos, pos - oldpos)); oldpos = pos + 1; diff --git a/source/m_cookie.h b/source/m_cookie.h index d7a24064d..8a2cd7ece 100644 --- a/source/m_cookie.h +++ b/source/m_cookie.h @@ -28,7 +28,7 @@ bool Cookie_Load(const std::string &filename); bool Cookie_Save(const std::string &filename); -bool Cookie_LoadString(const std::string &str, bool _keep_seed); +bool Cookie_LoadString(std::string_view str, bool _keep_seed); void Cookie_ParseArguments(void); diff --git a/source/sys_macro.h b/source/sys_macro.h index a0f725f3f..8ea9256b0 100644 --- a/source/sys_macro.h +++ b/source/sys_macro.h @@ -24,7 +24,7 @@ #include #include -constexpr char *BLANKOUT = " " +constexpr const char *BLANKOUT = " " " " " ";