diff --git a/include/configreader.h b/include/configreader.h index c8fc97d06..d053d16d0 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -129,7 +129,7 @@ public: /** Get the value of an option, using def if it does not exist */ bool getBool(const std::string& key, bool def = false) const; /** Get the value of an option, using def if it does not exist */ - unsigned char getCharacter(const std::string& key, unsigned char def = '\0') const; + unsigned char getCharacter(const std::string& key, unsigned char def = '\0', bool emptynul = false) const; /** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format, * using a default value if it does not exist or is out of bounds. diff --git a/src/configparser.cpp b/src/configparser.cpp index 8cdd1f7f5..457840b71 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -732,12 +732,15 @@ bool ConfigTag::getBool(const std::string& key, bool def) const return def; } -unsigned char ConfigTag::getCharacter(const std::string& key, unsigned char def) const +unsigned char ConfigTag::getCharacter(const std::string& key, unsigned char def, bool emptynul) const { std::string result; - if (!readString(key, result) || result.size() != 1) + if (!readString(key, result)) return def; + if (result.size() != 1) + return result.empty() && emptynul ? 0 : def; + return result[0]; }