diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/copynpaste.cpp | 1 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 16 | ||||
-rw-r--r-- | src/utils/stringutils.h | 8 | ||||
-rw-r--r-- | src/utils/xml.cpp | 19 | ||||
-rw-r--r-- | src/utils/xml.h | 13 |
5 files changed, 47 insertions, 10 deletions
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 31aa7bf9..3d2e3b80 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -269,7 +269,6 @@ static char* getSelection(Display *dpy, Window us, Atom selection) return (char*)data; } } - printf("Timeout\n"); return NULL; } 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 diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 9835f88c..bb386f51 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -21,15 +21,19 @@ #include "utils/xml.h" +#include <iostream> +#include <fstream> +#include <cstring> + +#include <libxml/parser.h> +#include <libxml/xmlerror.h> + #include "log.h" #include "resources/resourcemanager.h" #include "utils/zlib.h" -#include <libxml/parser.h> -#include <libxml/xmlerror.h> - namespace XML { static void xmlLogger(void *ctx, xmlErrorPtr error); @@ -129,6 +133,15 @@ namespace XML return def; } + bool getBoolProperty(xmlNodePtr node, const char* name, bool def) + { + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + + if (xmlStrEqual(prop, BAD_CAST "true" ) ) return true; + if (xmlStrEqual(prop, BAD_CAST "false") ) return false; + return def; + } + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name) { for_each_xml_child_node(child, parent) diff --git a/src/utils/xml.h b/src/utils/xml.h index 8ffecb76..48e66787 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -60,14 +60,14 @@ namespace XML }; /** - * Gets an integer property from an xmlNodePtr. + * Gets an floating point property from an xmlNodePtr. */ - int getProperty(xmlNodePtr node, const char *name, int def); + double getFloatProperty(xmlNodePtr node, const char *name, double def); /** - * Gets an floating point property from an xmlNodePtr. + * Gets an integer property from an xmlNodePtr. */ - double getFloatProperty(xmlNodePtr node, const char *name, double def); + int getProperty(xmlNodePtr node, const char *name, int def); /** * Gets a string property from an xmlNodePtr. @@ -76,6 +76,11 @@ namespace XML const std::string &def); /** + * Gets a boolean property from an xmlNodePtr. + */ + bool getBoolProperty(xmlNodePtr node, const char *name, bool def); + + /** * Finds the first child node with the given name */ xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name); |