summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp16
-rw-r--r--src/utils/stringutils.h8
2 files changed, 22 insertions, 2 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 9fe3de14..3988c769 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -26,7 +26,7 @@
#include <cstdarg>
#include <cstdio>
-const int UTF8_MAX_SIZE = 10;
+static int UTF8_MAX_SIZE = 10;
std::string &trim(std::string &str)
{
@@ -174,4 +174,16 @@ const char* getSafeUtf8String(std::string text)
memcpy(buf, text.c_str(), text.size());
memset(buf + text.size(), 0, UTF8_MAX_SIZE);
return buf;
-} \ No newline at end of file
+}
+
+bool getBoolFromString(const std::string &text)
+{
+ std::string txt = text;
+ toLower(trim(txt));
+ if (txt == "true" || txt == "yes" || txt == "on" || txt == "1")
+ return true;
+ else if (txt == "false" || txt == "no" || txt == "off" || txt == "0")
+ return false;
+ else
+ return (bool) atoi(txt.c_str());
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index ec82e240..7c14b1e5 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -125,4 +125,12 @@ const std::string findSameSubstring(const std::string &str1, const std::string &
const char* getSafeUtf8String(std::string text);
+/**
+ * Returns a bool value depending on the given string value.
+ *
+ * @param text the string used to get the bool value
+ * @return a boolean value..
+ */
+bool getBoolFromString(const std::string &text);
+
#endif // UTILS_STRINGUTILS_H