1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-14 01:19:59 +00:00

Merge branch 'ini-importer-tidying' into 'master'

INI importer tidying

See merge request OpenMW/openmw!4519
This commit is contained in:
AnyOldName3 2025-03-12 18:47:08 +00:00
commit c2460faba5
2 changed files with 32 additions and 7 deletions

View File

@ -11,6 +11,23 @@
namespace sfs = std::filesystem;
namespace
{
// from configfileparser.cpp
std::string trim_ws(const std::string& s)
{
std::string::size_type n, n2;
n = s.find_first_not_of(" \t\r\n");
if (n == std::string::npos)
return std::string();
else
{
n2 = s.find_last_not_of(" \t\r\n");
return s.substr(n, n2 - n + 1);
}
}
}
MwIniImporter::MwIniImporter()
: mVerbose(false)
, mEncoding(ToUTF8::WINDOWS_1250)
@ -352,12 +369,10 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat
std::string line;
while (std::getline(file, line))
{
// we cant say comment by only looking at first char anymore
int comment_pos = static_cast<int>(line.find('#'));
if (comment_pos > 0)
// ignore comments - keep in sync with configfileparser.cpp
if (line.find('#') == line.find_first_not_of(" \t\r\n"))
{
line = line.substr(0, comment_pos);
continue;
}
if (line.empty())
@ -373,6 +388,8 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat
std::string key(line.substr(0, pos));
std::string value(line.substr(pos + 1));
key = trim_ws(key);
value = trim_ws(key);
if (map.find(key) == map.end())
{

View File

@ -126,12 +126,20 @@ int wmain(int argc, wchar_t* wargv[])
MwIniImporter importer;
importer.setVerbose(vm.count("verbose") != 0);
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
// Font encoding settings
std::string encoding(vm["encoding"].as<std::string>());
std::string encoding;
if (vm["encoding"].defaulted() && cfg.contains("encoding") && !cfg["encoding"].empty())
encoding = cfg["encoding"].back();
else
{
encoding = vm["encoding"].as<std::string>();
cfg["encoding"] = { encoding };
}
importer.setInputEncoding(ToUTF8::calculateEncoding(encoding));
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
if (!vm.count("fonts"))
{