summaryrefslogtreecommitdiff
path: root/Source/Core/Common/StringUtil.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2016-07-12 11:42:41 +0200
committerLéo Lam <leo@innovatetechnologi.es>2016-07-13 13:50:48 +0200
commit213373f5f9c582dfcce07f4cde3eaa41e96f034a (patch)
tree4b05ee7a87c18f08eac5c267d76f5794ed247ccd /Source/Core/Common/StringUtil.cpp
parent5e829f45271bcd6a13ff541308c1599fb8eb2cfd (diff)
StringUtil: Make TryParse parse floats as booleans
This is needed to keep compatibility with old configuration files which didn't store booleans as booleans, but as floats/doubles.
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
-rw-r--r--Source/Core/Common/StringUtil.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp
index 6f50afce3e..ff6c6074cf 100644
--- a/Source/Core/Common/StringUtil.cpp
+++ b/Source/Core/Common/StringUtil.cpp
@@ -247,9 +247,11 @@ bool TryParse(const std::string& str, u32* const output)
bool TryParse(const std::string& str, bool* const output)
{
- if ("1" == str || !strcasecmp("true", str.c_str()))
+ float value;
+ const bool is_valid_float = TryParse(str, &value);
+ if ((is_valid_float && value == 1) || !strcasecmp("true", str.c_str()))
*output = true;
- else if ("0" == str || !strcasecmp("false", str.c_str()))
+ else if ((is_valid_float && value == 0) || !strcasecmp("false", str.c_str()))
*output = false;
else
return false;