aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-08-28 23:35:12 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-04 12:06:26 +0100
commit1303ca0e7e837da7aa656744ee9b8f65865b508a (patch)
treef77ddc8ebb8eaa8e13be432d8065d62b45981a78 /src/common
parent663ec927947c77a1668515334cf0f2e8c7673d31 (diff)
Common/Utilities: Make StringTo<bool>'s signature match that of the other integral types, making for easier templating. Default behavior unchanged.
(cherry picked from commit f54cec4db7c67b623383c140159e1171876ace89)
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Utilities/StringConvert.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/common/Utilities/StringConvert.h b/src/common/Utilities/StringConvert.h
index fbdc41f6aef..f264c0222fa 100644
--- a/src/common/Utilities/StringConvert.h
+++ b/src/common/Utilities/StringConvert.h
@@ -146,13 +146,24 @@ namespace Trinity::Impl::StringConvertImpl
template <>
struct For<bool, void>
{
- static Optional<bool> FromString(std::string_view str)
+ static Optional<bool> FromString(std::string_view str, int strict = 0) /* this is int to match the signature for "proper" integral types */
{
- if ((str == "1") || StringEqualI(str, "y") || StringEqualI(str, "on") || StringEqualI(str, "yes") || StringEqualI(str, "true"))
- return true;
- if ((str == "0") || StringEqualI(str, "n") || StringEqualI(str, "off") || StringEqualI(str, "no") || StringEqualI(str, "false"))
- return false;
- return std::nullopt;
+ if (strict)
+ {
+ if (str == "1")
+ return true;
+ if (str == "0")
+ return false;
+ return std::nullopt;
+ }
+ else
+ {
+ if ((str == "1") || StringEqualI(str, "y") || StringEqualI(str, "on") || StringEqualI(str, "yes") || StringEqualI(str, "true"))
+ return true;
+ if ((str == "0") || StringEqualI(str, "n") || StringEqualI(str, "off") || StringEqualI(str, "no") || StringEqualI(str, "false"))
+ return false;
+ return std::nullopt;
+ }
}
static std::string ToString(bool val)