From 890dc4f228538adefc439c5272543f3843a0dfdf Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2024 19:23:18 +0200 Subject: [PATCH] fix other bugs with these regexes --- src/frontend/qt_sdl/Config.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index f88bc6fa81..8b4d18626d 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -318,6 +318,13 @@ LegacyEntry LegacyFile[] = }; +static std::string GetDefaultKey(std::string path) +{ + std::regex re("(Instance|Window)(\\d+)\\."); + return std::regex_replace(path, re, "$1*."); +} + + Array::Array(toml::value& data) : Data(data) { } @@ -484,8 +491,7 @@ int Table::GetInt(const std::string& path) int ret = (int)tval.as_integer(); - std::regex rng_re("(\\d+)"); - std::string rngkey = std::regex_replace(PathPrefix+path, rng_re, "*"); + std::string rngkey = GetDefaultKey(PathPrefix+path); if (IntRanges.count(rngkey) != 0) { auto& range = IntRanges[rngkey]; @@ -524,8 +530,7 @@ std::string Table::GetString(const std::string& path) void Table::SetInt(const std::string& path, int val) { - std::regex rng_re("(\\d+)"); - std::string rngkey = std::regex_replace(PathPrefix+path, rng_re, "*"); + std::string rngkey = GetDefaultKey(PathPrefix+path); if (IntRanges.count(rngkey) != 0) { auto& range = IntRanges[rngkey]; @@ -571,8 +576,7 @@ toml::value& Table::ResolvePath(const std::string& path) template T Table::FindDefault(const std::string& path, T def, DefaultList list) { - std::regex def_re("(\\d+)"); - std::string defkey = std::regex_replace(PathPrefix+path, def_re, "*"); + std::string defkey = GetDefaultKey(PathPrefix+path); T ret = def; while (list.count(defkey) == 0) @@ -604,7 +608,7 @@ bool LoadLegacyFile(int inst) } if (!f) return true; -printf("PARSING LEGACY INI %d\n", inst); + toml::value* root;// = GetLocalTable(inst); if (inst == -1) root = &RootTable; @@ -629,16 +633,15 @@ printf("PARSING LEGACY INI %d\n", inst); { if (!(entry->InstanceUnique ^ (inst == -1))) break; -printf("entry: %s -> %s, %d\n", entry->Name, entry->TOMLPath, entry->InstanceUnique); + std::string path = entry->TOMLPath; toml::value* table = root; size_t sep; while ((sep = path.find('.')) != std::string::npos) - {printf("%s->", path.substr(0,sep).c_str()); + { table = &(*table)[path.substr(0, sep)]; path = path.substr(sep+1); } - printf("%s\n", path.c_str()); int arrayid = -1; if (path[path.size()-1] == ']') @@ -647,7 +650,7 @@ printf("entry: %s -> %s, %d\n", entry->Name, entry->TOMLPath, entry->InstanceUni arrayid = std::stoi(path.substr(tmp+1, path.size()-tmp-2)); path = path.substr(0, tmp); } -printf("path %s id %d\n", path.c_str(), arrayid); + toml::value& val = (*table)[path]; switch (entry->Type) @@ -673,7 +676,6 @@ printf("path %s id %d\n", path.c_str(), arrayid); while (val.size() < arrayid+1) val.push_back(""); val[arrayid] = entryval; - //val.push_back(entryval); break; } @@ -715,8 +717,6 @@ bool Load() //RootTable = toml::table(); } - // - return true; }