Allow ConfigTag::getCharacter to return NUL for an empty field.

This commit is contained in:
Sadie Powell 2024-10-16 11:39:59 +01:00
parent 4ad5257918
commit a9a6411051
2 changed files with 6 additions and 3 deletions

View File

@ -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.

View File

@ -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];
}