#include <cctype>
#include <algorithm>
+static Settings main_settings;
+Settings *g_settings = &main_settings;
+std::string g_settings_path;
Settings::~Settings()
{
bool Settings::checkNameValid(const std::string &name)
{
- size_t pos = name.find_first_of("\t\n\v\f\r\b =\"{}#");
- if (pos != std::string::npos) {
- errorstream << "Invalid character '" << name[pos]
- << "' found in setting name" << std::endl;
+ bool valid = name.find_first_of("=\"{}#") == std::string::npos;
+ if (valid) valid = trim(name) == name;
+ if (!valid) {
+ errorstream << "Invalid setting name \"" << name << "\""
+ << std::endl;
return false;
}
return true;
if (value.substr(0, 3) == "\"\"\"" ||
value.find("\n\"\"\"") != std::string::npos) {
errorstream << "Invalid character sequence '\"\"\"' found in"
- " setting value" << std::endl;
+ " setting value!" << std::endl;
return false;
}
return true;
std::string Settings::sanitizeName(const std::string &name)
{
- std::string n(name);
+ std::string n = trim(name);
- for (const char *s = "\t\n\v\f\r\b =\"{}#"; *s; s++)
+ for (const char *s = "=\"{}#"; *s; s++)
n.erase(std::remove(n.begin(), n.end(), *s), n.end());
return n;