configuration: better boolean parsing

This commit is contained in:
Matej Sekoranja
2012-10-12 12:14:41 +02:00
parent 5f08c6e37c
commit e264f5f51d
2 changed files with 18 additions and 7 deletions
+14
View File
@@ -248,6 +248,7 @@ SystemConfigurationImpl::~SystemConfigurationImpl()
bool SystemConfigurationImpl::getPropertyAsBoolean(const string &name, const bool defaultValue)
{
/*
bool retval;
_ibuffer.clear();
_obuffer.clear();
@@ -259,6 +260,19 @@ bool SystemConfigurationImpl::getPropertyAsBoolean(const string &name, const boo
return defaultValue;
else
return retval;
*/
string value = getPropertyAsString(name, defaultValue ? "1" : "0");
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
bool isTrue = (value == "1") || (value == "true") || (value == "yes");
bool isFalse = (value == "0") || (value == "false") || (value == "no");
// invalid value
if (!(isTrue || isFalse))
return defaultValue;
else
return isTrue == true;
}
int32 SystemConfigurationImpl::getPropertyAsInteger(const string &name, const int32 defaultValue)