diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/base64.cpp | 6 | ||||
-rw-r--r-- | src/utils/copynpaste.cpp | 30 | ||||
-rw-r--r-- | src/utils/dtor.h | 6 | ||||
-rw-r--r-- | src/utils/paths.cpp | 2 | ||||
-rw-r--r-- | src/utils/specialfolder.cpp | 2 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 15 | ||||
-rw-r--r-- | src/utils/xml.cpp | 10 |
7 files changed, 42 insertions, 29 deletions
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 14876d878..843a0b534 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -102,8 +102,8 @@ unsigned char *php3_base64_decode(const unsigned char *string, unsigned char *result = static_cast<unsigned char *>( calloc(length + 1, 1)); - if (result == NULL) - return NULL; + if (!result) + return nullptr; /* run through the whole string, converting as we go */ while ((ch = *current++) != '\0') @@ -155,7 +155,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, case 0: case 1: free(result); - return 0; + return nullptr; case 2: k++; case 3: diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 6d1c675d3..3e37afd9d 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -43,7 +43,7 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) { bool ret = false; - if (!OpenClipboard(NULL)) + if (!OpenClipboard(nullptr)) return false; HANDLE h = GetClipboardData(CF_UNICODETEXT); @@ -54,13 +54,13 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) if (data) { int len = WideCharToMultiByte(CP_UTF8, 0, data, -1, - NULL, 0, NULL, NULL); + nullptr, 0, nullptr, nullptr); if (len > 0) { // Convert from UTF-16 to UTF-8 void *temp = calloc(len, 1); if (WideCharToMultiByte(CP_UTF8, 0, data, -1, - (LPSTR)temp, len, NULL, NULL)) + (LPSTR)temp, len, nullptr, nullptr)) { text.insert(pos, (char*)temp); pos += len-1; @@ -94,7 +94,8 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) bool sendBuffer(std::string& text) { - int wCharsLen = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, NULL, 0); + int wCharsLen = MultiByteToWideChar(CP_UTF8, + 0, text.c_str(), -1, nullptr, 0); if (!wCharsLen) return false; @@ -284,6 +285,9 @@ bool sendBuffer(std::string& text) } #elif USE_X11 + +#include <unistd.h> + static char* getSelection2(Display *dpy, Window us, Atom selection, Atom request_target) { @@ -295,7 +299,7 @@ static char* getSelection2(Display *dpy, Window us, Atom selection, if (owner == None) { //printf("No owner\n"); - return NULL; + return nullptr; } XConvertSelection(dpy, selection, request_target, XA_PRIMARY, us, CurrentTime); @@ -314,13 +318,13 @@ static char* getSelection2(Display *dpy, Window us, Atom selection, if (e.xselection.property == None) { //printf("Couldn't convert\n"); - return NULL; + return nullptr; } long unsigned len, left, dummy; int format; Atom type; - unsigned char *data = NULL; + unsigned char *data = nullptr; ret = XGetWindowProperty(dpy, us, e.xselection.property, 0, 0, False, AnyPropertyType, &type, &format, &len, &left, &data); @@ -328,7 +332,7 @@ static char* getSelection2(Display *dpy, Window us, Atom selection, { if (ret == Success) XFree(data); - return NULL; + return nullptr; } ret = XGetWindowProperty(dpy, us, e.xselection.property, 0, @@ -338,7 +342,7 @@ static char* getSelection2(Display *dpy, Window us, Atom selection, if (ret != Success) { //printf("Failed to get property: %p on %lu\n", data, len); - return NULL; + return nullptr; } //printf(">>> Got %s: len=%lu left=%lu (event %i)\n", data, @@ -346,14 +350,14 @@ static char* getSelection2(Display *dpy, Window us, Atom selection, return reinterpret_cast<char*>(data); } } - return NULL; + return nullptr; } static Atom requestAtom; static char* getSelection(Display *dpy, Window us, Atom selection) { - char *data = NULL; + char *data = nullptr; if (requestAtom != None) data = getSelection2(dpy, us, selection, requestAtom); if (!data) @@ -371,7 +375,7 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) { Display *dpy = info.info.x11.display; Window us = info.info.x11.window; - char *data = NULL; + char *data = nullptr; requestAtom = XInternAtom (dpy, "UTF8_STRING", true); @@ -428,7 +432,7 @@ bool sendBuffer(std::string& text) } close(fd[0]); } - execl("/usr/bin/xsel", "xsel", "-i", (char *)0); + execl("/usr/bin/xsel", "xsel", "-i", (char *)nullptr); exit(1); } diff --git a/src/utils/dtor.h b/src/utils/dtor.h index 11583709f..fbe903ced 100644 --- a/src/utils/dtor.h +++ b/src/utils/dtor.h @@ -30,14 +30,16 @@ template<typename T> struct dtor : public std::unary_function <T, void> { - void operator()(T &ptr) { delete ptr; } + void operator()(T &ptr) + { delete ptr; } }; template<typename T1, typename T2> struct dtor<std::pair<T1, T2> > : public std::unary_function <std::pair<T1, T2>, void> { - void operator()(std::pair<T1, T2> &pair) { delete pair.second; } + void operator()(std::pair<T1, T2> &pair) + { delete pair.second; } }; template<class Cont> diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index b42caf9b5..3cc35cb55 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -41,7 +41,7 @@ std::string getRealPath(const std::string &str) char *realPath = (char*)calloc(PATH_MAX, sizeof(char)); realpath(str.c_str(), realPath); #else - char *realPath = realpath(str.c_str(), NULL); + char *realPath = realpath(str.c_str(), nullptr); #endif path = realPath; free(realPath); diff --git a/src/utils/specialfolder.cpp b/src/utils/specialfolder.cpp index 31eaec687..fae0fbf47 100644 --- a/src/utils/specialfolder.cpp +++ b/src/utils/specialfolder.cpp @@ -45,7 +45,7 @@ std::string getSpecialFolderLocation(int folderId) char szPath[_MAX_PATH]; // get the item ID list for folderId - HRESULT hr = SHGetSpecialFolderLocation(NULL, folderId, &pItemIdList); + HRESULT hr = SHGetSpecialFolderLocation(nullptr, folderId, &pItemIdList); if (hr != S_OK) return ret; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 6c50d4019..39f14a646 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -22,6 +22,8 @@ #include "utils/stringutils.h" +#include "configuration.h" + #include <string.h> #include <algorithm> #include <cstdarg> @@ -487,11 +489,16 @@ std::string combineDye2(std::string file, std::string dye) std::vector<std::string> getLang() { std::vector<std::string> langs; - char *lng = getenv("LANG"); - if (!lng) - return langs; - std::string lang(lng); + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return langs; + lang = lng; + } + int dot = lang.find("."); if (dot != (signed)std::string::npos) lang = lang.substr(0, dot); diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 89457a4e8..10436067f 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -35,10 +35,10 @@ namespace XML { Document::Document(const std::string &filename, bool useResman): - mDoc(0) + mDoc(nullptr) { int size; - char *data = NULL; + char *data = nullptr; if (useResman) { ResourceManager *resman = ResourceManager::getInstance(); @@ -87,7 +87,7 @@ namespace XML if (data) mDoc = xmlParseMemory(data, size); else - mDoc = 0; + mDoc = nullptr; } Document::~Document() @@ -98,7 +98,7 @@ namespace XML xmlNodePtr Document::rootNode() { - return mDoc ? xmlDocGetRootElement(mDoc) : 0; + return mDoc ? xmlDocGetRootElement(mDoc) : nullptr; } int getProperty(xmlNodePtr node, const char* name, int def) @@ -162,7 +162,7 @@ namespace XML return child; } - return NULL; + return nullptr; } } // namespace XML |