aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities')
-rw-r--r--src/common/Utilities/Util.cpp8
-rw-r--r--src/common/Utilities/Util.h3
2 files changed, 8 insertions, 3 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index da086c6b6cc..cb70cc114d3 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -651,9 +651,13 @@ void Trinity::Impl::HexStrToByteArray(std::string_view str, uint8* out, size_t o
}
}
-bool StringToBool(std::string_view str)
+Optional<bool> StringToBool(std::string_view str)
{
- return ((str == "1") || StringEqualI(str, "true") || StringEqualI(str, "yes"));
+ 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;
}
bool StringEqualI(std::string_view str1, std::string_view str2)
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index cd8765b309f..8c97f99fe63 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -20,6 +20,7 @@
#include "Define.h"
#include "Errors.h"
+#include "Optional.h"
#include <array>
#include <string>
@@ -345,7 +346,7 @@ inline std::vector<uint8> HexStrToByteVector(std::string_view str, bool reverse
return buf;
}
-TC_COMMON_API bool StringToBool(std::string_view str);
+TC_COMMON_API Optional<bool> StringToBool(std::string_view str);
TC_COMMON_API bool StringEqualI(std::string_view str1, std::string_view str2);
TC_COMMON_API bool StringStartsWith(std::string_view haystack, std::string_view needle);