mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-08 03:41:11 -04:00
Merge branch 'ini-importer-tidying' into 'master'
INI importer tidying See merge request OpenMW/openmw!4519
This commit is contained in:
commit
5c60168b16
@ -11,6 +11,23 @@
|
|||||||
|
|
||||||
namespace sfs = std::filesystem;
|
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()
|
MwIniImporter::MwIniImporter()
|
||||||
: mVerbose(false)
|
: mVerbose(false)
|
||||||
, mEncoding(ToUTF8::WINDOWS_1250)
|
, mEncoding(ToUTF8::WINDOWS_1250)
|
||||||
@ -352,12 +369,10 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat
|
|||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
|
// ignore comments - keep in sync with configfileparser.cpp
|
||||||
// we cant say comment by only looking at first char anymore
|
if (line.find('#') == line.find_first_not_of(" \t\r\n"))
|
||||||
int comment_pos = static_cast<int>(line.find('#'));
|
|
||||||
if (comment_pos > 0)
|
|
||||||
{
|
{
|
||||||
line = line.substr(0, comment_pos);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.empty())
|
if (line.empty())
|
||||||
@ -373,6 +388,8 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat
|
|||||||
|
|
||||||
std::string key(line.substr(0, pos));
|
std::string key(line.substr(0, pos));
|
||||||
std::string value(line.substr(pos + 1));
|
std::string value(line.substr(pos + 1));
|
||||||
|
key = trim_ws(key);
|
||||||
|
value = trim_ws(value);
|
||||||
|
|
||||||
if (map.find(key) == map.end())
|
if (map.find(key) == map.end())
|
||||||
{
|
{
|
||||||
|
@ -126,12 +126,20 @@ int wmain(int argc, wchar_t* wargv[])
|
|||||||
MwIniImporter importer;
|
MwIniImporter importer;
|
||||||
importer.setVerbose(vm.count("verbose") != 0);
|
importer.setVerbose(vm.count("verbose") != 0);
|
||||||
|
|
||||||
|
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
||||||
|
|
||||||
// Font encoding settings
|
// 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));
|
importer.setInputEncoding(ToUTF8::calculateEncoding(encoding));
|
||||||
|
|
||||||
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
||||||
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
|
||||||
|
|
||||||
if (!vm.count("fonts"))
|
if (!vm.count("fonts"))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user