From 33b2030f975fcdc8cb3861267dbc47b8a22a0a16 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Tue, 16 Sep 2025 16:10:16 +0200 Subject: [PATCH] Support global keys in ini --- include/Utils.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/include/Utils.h b/include/Utils.h index c0f4e21..28f0986 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -108,8 +109,8 @@ namespace Utils { return result; } #endif - inline std::map> ParseINI(const std::string& contents) { - std::map> ini; + inline std::map, std::string>> ParseINI(const std::string& contents) { + std::map, std::string>> ini; std::string currentSection; auto sections = Split(contents, "\n"); @@ -136,18 +137,19 @@ namespace Utils { if (line[0] == '[') { currentSection = line.substr(1, line.find(']') - 1); } else { - - if (currentSection.empty()) { - invalidLineLog(); - continue; - } - std::string key, value; size_t pos = line.find('='); if (pos != std::string::npos) { key = line.substr(0, pos); + + key = key.substr(0, key.find_last_not_of(" \t") + 1); + value = line.substr(pos + 1); - ini[currentSection][key] = value; + if (currentSection.empty()) { + ini[key] = value; + } else { + std::get>(ini[currentSection])[key] = value; + } } else { invalidLineLog(); continue; @@ -157,7 +159,7 @@ namespace Utils { value.erase(0, value.find_first_not_of(" \t")); value.erase(value.find_last_not_of(" \t") + 1); - ini[currentSection][key] = value; + std::get>(ini[currentSection])[key] = value; } }