fix other bugs with these regexes

This commit is contained in:
Arisotura 2024-06-15 19:23:18 +02:00
parent d449888405
commit 890dc4f228
1 changed files with 14 additions and 14 deletions

View File

@ -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) Array::Array(toml::value& data) : Data(data)
{ {
} }
@ -484,8 +491,7 @@ int Table::GetInt(const std::string& path)
int ret = (int)tval.as_integer(); int ret = (int)tval.as_integer();
std::regex rng_re("(\\d+)"); std::string rngkey = GetDefaultKey(PathPrefix+path);
std::string rngkey = std::regex_replace(PathPrefix+path, rng_re, "*");
if (IntRanges.count(rngkey) != 0) if (IntRanges.count(rngkey) != 0)
{ {
auto& range = IntRanges[rngkey]; 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) void Table::SetInt(const std::string& path, int val)
{ {
std::regex rng_re("(\\d+)"); std::string rngkey = GetDefaultKey(PathPrefix+path);
std::string rngkey = std::regex_replace(PathPrefix+path, rng_re, "*");
if (IntRanges.count(rngkey) != 0) if (IntRanges.count(rngkey) != 0)
{ {
auto& range = IntRanges[rngkey]; auto& range = IntRanges[rngkey];
@ -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) template<typename T> T Table::FindDefault(const std::string& path, T def, DefaultList<T> list)
{ {
std::regex def_re("(\\d+)"); std::string defkey = GetDefaultKey(PathPrefix+path);
std::string defkey = std::regex_replace(PathPrefix+path, def_re, "*");
T ret = def; T ret = def;
while (list.count(defkey) == 0) while (list.count(defkey) == 0)
@ -604,7 +608,7 @@ bool LoadLegacyFile(int inst)
} }
if (!f) return true; if (!f) return true;
printf("PARSING LEGACY INI %d\n", inst);
toml::value* root;// = GetLocalTable(inst); toml::value* root;// = GetLocalTable(inst);
if (inst == -1) if (inst == -1)
root = &RootTable; root = &RootTable;
@ -629,16 +633,15 @@ printf("PARSING LEGACY INI %d\n", inst);
{ {
if (!(entry->InstanceUnique ^ (inst == -1))) if (!(entry->InstanceUnique ^ (inst == -1)))
break; break;
printf("entry: %s -> %s, %d\n", entry->Name, entry->TOMLPath, entry->InstanceUnique);
std::string path = entry->TOMLPath; std::string path = entry->TOMLPath;
toml::value* table = root; toml::value* table = root;
size_t sep; size_t sep;
while ((sep = path.find('.')) != std::string::npos) while ((sep = path.find('.')) != std::string::npos)
{printf("%s->", path.substr(0,sep).c_str()); {
table = &(*table)[path.substr(0, sep)]; table = &(*table)[path.substr(0, sep)];
path = path.substr(sep+1); path = path.substr(sep+1);
} }
printf("%s\n", path.c_str());
int arrayid = -1; int arrayid = -1;
if (path[path.size()-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)); arrayid = std::stoi(path.substr(tmp+1, path.size()-tmp-2));
path = path.substr(0, tmp); path = path.substr(0, tmp);
} }
printf("path %s id %d\n", path.c_str(), arrayid);
toml::value& val = (*table)[path]; toml::value& val = (*table)[path];
switch (entry->Type) switch (entry->Type)
@ -673,7 +676,6 @@ printf("path %s id %d\n", path.c_str(), arrayid);
while (val.size() < arrayid+1) while (val.size() < arrayid+1)
val.push_back(""); val.push_back("");
val[arrayid] = entryval; val[arrayid] = entryval;
//val.push_back(entryval);
break; break;
} }
@ -715,8 +717,6 @@ bool Load()
//RootTable = toml::table(); //RootTable = toml::table();
} }
//
return true; return true;
} }