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)
{
}
@ -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<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)
@ -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;
}