Skip to content

Commit

Permalink
fix other bugs with these regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Jun 15, 2024
1 parent d449888 commit 890dc4f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/frontend/qt_sdl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -571,8 +576,7 @@ toml::value& Table::ResolvePath(const std::string& path)

template<typename T> T Table::FindDefault(const std::string& path, T def, DefaultList<T> 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)
Expand Down Expand Up @@ -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;
Expand All @@ -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] == ']')
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down Expand Up @@ -715,8 +717,6 @@ bool Load()
//RootTable = toml::table();
}

//

return true;
}

Expand Down

0 comments on commit 890dc4f

Please sign in to comment.