diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/copynpaste.cpp | 1 | ||||
-rw-r--r-- | src/utils/mkdir.cpp | 8 | ||||
-rw-r--r-- | src/utils/mkdir.h | 4 | ||||
-rw-r--r-- | src/utils/specialfolder.cpp | 8 | ||||
-rw-r--r-- | src/utils/specialfolder.h | 4 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 23 | ||||
-rw-r--r-- | src/utils/stringutils.h | 22 | ||||
-rw-r--r-- | src/utils/xml.cpp | 23 | ||||
-rw-r--r-- | src/utils/xml.h | 13 |
9 files changed, 83 insertions, 23 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/mkdir.cpp b/src/utils/mkdir.cpp index bd9fd2b1..75ab8595 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -28,8 +28,8 @@ #include <sys/stat.h> -#ifdef _MKDIR_TEST_ -// compile with -D_MKDIR_TEST_ to get a standalone binary +#ifdef MKDIR_TEST +// compile with -DMKDIR_TEST to get a standalone binary #include <cstdio> #include <cstdlib> #endif @@ -92,7 +92,7 @@ int mkdir_r(const char *pathname) { return -1; } -#ifdef _MKDIR_TEST_ +#ifdef MKDIR_TEST printf("%s\n", tmp); #endif *p = '/'; @@ -101,7 +101,7 @@ int mkdir_r(const char *pathname) { return 0; } -#ifdef _MKDIR_TEST_ +#ifdef MKDIR_TEST int main(int argc, char** argv) { if (argc < 2) exit(1); mkdir_r(argv[1]); diff --git a/src/utils/mkdir.h b/src/utils/mkdir.h index 9369b4e7..13cfc1c1 100644 --- a/src/utils/mkdir.h +++ b/src/utils/mkdir.h @@ -18,8 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _MKDIR_H -#define _MKDIR_H +#ifndef MKDIR_H +#define MKDIR_H int mkdir_r(const char *pathname); diff --git a/src/utils/specialfolder.cpp b/src/utils/specialfolder.cpp index 64607716..63337578 100644 --- a/src/utils/specialfolder.cpp +++ b/src/utils/specialfolder.cpp @@ -22,8 +22,8 @@ #include "specialfolder.h" #include <windows.h> -#ifdef _SPECIALFOLDERLOCATION_TEST_ -// compile with -D_SPECIALFOLDERLOCATION_TEST_ to get a standalone +#ifdef SPECIALFOLDERLOCATION_TEST +// compile with -DSPECIALFOLDERLOCATION_TEST to get a standalone // binary for testing #include <iostream> #endif @@ -39,7 +39,7 @@ std::string getSpecialFolderLocation(int folderId) std::string ret; LPITEMIDLIST pItemIdList; LPMALLOC pMalloc; - char szPath[_MAX_PATH]; + char szPath[MAX_PATH]; // get the item ID list for folderId HRESULT hr = SHGetSpecialFolderLocation(NULL, folderId, &pItemIdList); @@ -59,7 +59,7 @@ std::string getSpecialFolderLocation(int folderId) return ret; } -#ifdef _SPECIALFOLDERLOCATION_TEST_ +#ifdef SPECIALFOLDERLOCATION_TEST int main() { std::cout << "APPDATA " << getSpecialFolderLocation(CSIDL_APPDATA) diff --git a/src/utils/specialfolder.h b/src/utils/specialfolder.h index c2c2e0be..eef6416b 100644 --- a/src/utils/specialfolder.h +++ b/src/utils/specialfolder.h @@ -18,8 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _SPECIALFOLDER_H -#define _SPECIALFOLDER_H +#ifndef SPECIALFOLDER_H +#define SPECIALFOLDER_H #ifdef WIN32 #include <shlobj.h> diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 445427fe..96b67370 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) { @@ -210,3 +223,9 @@ std::string autocomplete(std::vector<std::string> &candidates, return newName; } + +std::string normalize(const std::string &name) +{ + std::string normalized = name; + return toLower(trim(normalized));; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 5f1f05f0..2c6fad78 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -120,13 +120,33 @@ std::string removeColors(std::string msg); */ int compareStrI(const std::string &a, const std::string &b); +/** + * Tells wether the character is a word separator. + */ 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); + +/** + * Returns the most approaching string of base from candidates. + */ std::string autocomplete(std::vector<std::string> &candidates, std::string base); +/** + * Normalize a string, which means lowercase and trim it. + */ +std::string normalize(const std::string &name); + #endif // UTILS_STRINGUTILS_H diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 1970b062..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) 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); |