dead code elim

This commit is contained in:
Luxferre
2026-10-15 23:32:13 +03:00
parent b891a0f66b
commit 2e404c623d
2 changed files with 11 additions and 12 deletions
+11 -2
View File
@@ -134,6 +134,15 @@ Cfg get_cfg(std::string_view path) {
}
int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
/* Strip a single pair of surrounding quotes so a value containing spaces can
* be passed as e.g. "a b" without the quote characters becoming part of the
* stored value. */
std::string vstr(val);
if (vstr.size() >= 2 &&
((vstr.front() == '"' && vstr.back() == '"') ||
(vstr.front() == '\'' && vstr.back() == '\''))) {
vstr = vstr.substr(1, vstr.size() - 2);
}
std::vector<std::string> lines;
{
std::string content;
@@ -157,7 +166,7 @@ int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
std::string_view keyPart = sv.substr(k, eq - k);
while (!keyPart.empty() && std::isspace((unsigned char)keyPart.back())) keyPart.remove_suffix(1);
if (keyPart == key) {
line = sfmt("%s=%s\n", std::string(key).c_str(), std::string(val).c_str());
line = sfmt("%s=%s\n", std::string(key).c_str(), vstr.c_str());
found = true;
}
}
@@ -166,7 +175,7 @@ int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
std::string &last = lines.back();
if (!last.empty() && last.back() != '\n') last += '\n';
}
lines.push_back(sfmt("%s=%s\n", std::string(key).c_str(), std::string(val).c_str()));
lines.push_back(sfmt("%s=%s\n", std::string(key).c_str(), vstr.c_str()));
}
std::string out_buf;
for (auto &line : lines) out_buf += line;