forked from lix-project/lix
config.cc: extract parts of applyConfigFile into applyConfig
This moves the actual parsing of configuration contents into applyConfig which applyConfigFile is then going to call. By changing this we can now test the configuration file parsing without actually create a file on disk.
This commit is contained in:
parent
93129cf1dd
commit
e1b8c64c04
|
@ -65,11 +65,7 @@ void Config::getSettings(std::map<std::string, SettingInfo> & res, bool override
|
||||||
res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description});
|
res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractConfig::applyConfigFile(const Path & path)
|
void AbstractConfig::applyConfig(const std::string & contents, const std::string & path) {
|
||||||
{
|
|
||||||
try {
|
|
||||||
string contents = readFile(path);
|
|
||||||
|
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
|
|
||||||
while (pos < contents.size()) {
|
while (pos < contents.size()) {
|
||||||
|
@ -119,6 +115,13 @@ void AbstractConfig::applyConfigFile(const Path & path)
|
||||||
|
|
||||||
set(name, concatStringsSep(" ", Strings(i, tokens.end()))); // FIXME: slow
|
set(name, concatStringsSep(" ", Strings(i, tokens.end()))); // FIXME: slow
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractConfig::applyConfigFile(const Path & path)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
string contents = readFile(path);
|
||||||
|
applyConfig(contents, path);
|
||||||
} catch (SysError &) { }
|
} catch (SysError &) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
|
|
||||||
virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) = 0;
|
virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) = 0;
|
||||||
|
|
||||||
|
void applyConfig(const std::string & contents, const std::string & path = "<unknown>");
|
||||||
void applyConfigFile(const Path & path);
|
void applyConfigFile(const Path & path);
|
||||||
|
|
||||||
virtual void resetOverriden() = 0;
|
virtual void resetOverriden() = 0;
|
||||||
|
|
Loading…
Reference in a new issue