summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/copynpaste.cpp1
-rw-r--r--src/utils/stringutils.cpp17
-rw-r--r--src/utils/stringutils.h11
-rw-r--r--src/utils/xml.cpp25
-rw-r--r--src/utils/xml.h13
5 files changed, 55 insertions, 12 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 445427fe..ca03791f 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)
{
@@ -155,7 +155,8 @@ bool isWordSeparator(char chr)
return (chr == ' ' || chr == ',' || chr == '.' || chr == '"');
}
-const std::string findSameSubstring(const std::string &str1, const std::string &str2)
+const std::string findSameSubstring(const std::string &str1,
+ const std::string &str2)
{
int minLength = str1.length() > str2.length() ? str2.length() : str1.length();
for (int f = 0; f < minLength; f ++)
@@ -176,6 +177,18 @@ const char* getSafeUtf8String(std::string text)
return buf;
}
+bool getBoolFromString(const std::string &text, bool def)
+{
+ std::string a = text;
+ toLower(trim(a));
+ if (a == "true" || a == "1" || a == "on" || a == "yes" || a == "y")
+ return true;
+ if (a == "false" || a == "0" || a == "off" || a == "no" || a == "n")
+ return false;
+ else
+ return def;
+}
+
std::string autocomplete(std::vector<std::string> &candidates,
std::string base)
{
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 5f1f05f0..f032733d 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -122,10 +122,19 @@ int compareStrI(const std::string &a, const std::string &b);
bool isWordSeparator(char chr);
-const std::string findSameSubstring(const std::string &str1, const std::string &str2);
+const std::string findSameSubstring(const std::string &str1,
+ const std::string &str2);
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, bool def = false);
+
std::string autocomplete(std::vector<std::string> &candidates,
std::string base);
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 9835f88c..65eb1370 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -21,15 +21,20 @@
#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/stringutils.h"
#include "utils/zlib.h"
-#include <libxml/parser.h>
-#include <libxml/xmlerror.h>
-
namespace XML
{
static void xmlLogger(void *ctx, xmlErrorPtr error);
@@ -129,6 +134,18 @@ namespace XML
return def;
}
+ bool getBoolProperty(xmlNodePtr node, const char* name, bool def)
+ {
+ bool ret = def;
+ xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ if (prop)
+ {
+ ret = getBoolFromString((char*) prop, def);
+ xmlFree(prop);
+ }
+ return ret;
+ }
+
xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name)
{
for_each_xml_child_node(child, parent)
@@ -149,7 +166,7 @@ namespace XML
logger->log("Error in unknown xml file on line %d",
error->line);
- logger->log(error->message);
+ logger->log("%s", error->message);
// No need to keep errors around
xmlCtxtResetLastError(error->ctxt);
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);