From 6204215c314b31a217b7f481ec116a6592a1c3ee Mon Sep 17 00:00:00 2001 From: Bhuiyan Mohammad Iklash Date: Wed, 5 May 2021 04:52:56 +0600 Subject: [PATCH 1/5] Update README.md --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a23041e..ef3a422 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,21 @@ # mere-utils-lib -## Description +### Description Utility library contains all the reusable functions for the components that are used in mere projects. -## Components -- String +### Components +- AppUtils +- EnvUtils +- BinUtils +- FileUtils +- FolderUtls +- i18Utils +- IconUtils +- PathUtils +- ProcessUtils +- SignalUtils +- StringUtils -## Support +### Support If you find a bug, or have a feature suggestion, please [log an issue](https://github.com/merelabs/mere-utils-lib/issues). If you'd like to contribute, please read [How to Contribute](CONTRIBUTING.md). From 31d588e71d59b2ca7fe6087924fa5b1d7d38397b Mon Sep 17 00:00:00 2001 From: Bhuiyan Mohammad Iklash Date: Fri, 7 May 2021 09:49:32 +0600 Subject: [PATCH 2/5] Fix create intermediate path --- src/pathutils.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pathutils.cpp b/src/pathutils.cpp index 791c13c..e885c8e 100644 --- a/src/pathutils.cpp +++ b/src/pathutils.cpp @@ -8,6 +8,10 @@ bool Mere::Utils::PathUtils::exists(const std::string &path) { struct stat s; + stat(path.c_str(), &s); + + //S_ISDIR(s.st_mode) || S_ISREG(s.st_mode) || S_ISFIFO(s.st_mode) || S_ISLNK(s.st_mode) || S_ISSOCK(s.st_mode); + return stat(path.c_str(), &s) == 0; } @@ -26,6 +30,16 @@ bool Mere::Utils::PathUtils::create(const std::string &path, int mode) { if(exists(path)) return false; + auto pos = path.find("/", 0); + while (pos != std::string::npos) + { + std::string part = path.substr(0, pos + 1); + if (!exists(part) && mkdir(part.c_str(), mode)) + return false; + + pos = path.find("/", pos + 1); + } + int err = mkdir(path.c_str(), mode); return !err; From f0336d16b063dedd6ad4030579272758f9b4f8a4 Mon Sep 17 00:00:00 2001 From: Bhuiyan Mohammad Iklash Date: Fri, 7 May 2021 10:24:55 +0600 Subject: [PATCH 3/5] Add remove file function --- src/fileutils.cpp | 5 +++++ src/fileutils.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 63b25ba..f55dc3a 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -10,6 +10,11 @@ bool Mere::Utils::FileUtils::touch(const std::string &path) return std::ofstream(path).good(); } +bool Mere::Utils::FileUtils::remove(const std::string &path) +{ + return std::remove(path.c_str()) == 0; +} + bool Mere::Utils::FileUtils::isExist(const std::string &path) { return std::ifstream(path).good(); diff --git a/src/fileutils.h b/src/fileutils.h index 63ebd65..901c2f8 100644 --- a/src/fileutils.h +++ b/src/fileutils.h @@ -14,6 +14,7 @@ class MERE_UTILS_LIB_SPEC FileUtils FileUtils() = default; public: static bool touch(const std::string &path); + static bool remove(const std::string &path); static bool isExist(const std::string &path); static bool isExist(const QString &path); From 73831f816b9945ad8f48a827174ea5000ba8ee4b Mon Sep 17 00:00:00 2001 From: Bhuiyan Mohammad Iklash Date: Tue, 11 May 2021 10:06:49 +0600 Subject: [PATCH 4/5] Add string split --- src/stringutils.cpp | 19 ++++++++++++++++++- src/stringutils.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/stringutils.cpp b/src/stringutils.cpp index 4864247..4e16cbb 100644 --- a/src/stringutils.cpp +++ b/src/stringutils.cpp @@ -1,6 +1,7 @@ #include "stringutils.h" #include +#include bool Mere::Utils::StringUtils::isInteger(const QString& str, int base) { @@ -64,6 +65,8 @@ QString Mere::Utils::StringUtils::trim(const QString& str) std::string& Mere::Utils::StringUtils::trim(std::string &str) { + if (str.empty()) return str; + // from left auto pos = str.find_first_not_of(" "); if (pos != std::string::npos) @@ -77,8 +80,9 @@ std::string& Mere::Utils::StringUtils::trim(std::string &str) str = str.erase(pos + 1); } else + { str.clear(); - + } return str; } @@ -175,3 +179,16 @@ int Mere::Utils::StringUtils::indexOf(const QString& str, const QString &sub, ui return pos; } + +//static +std::vector Mere::Utils::StringUtils::split(const std::string &str, char del) +{ + std::vector parts; + + std::string part; + std::stringstream stream (str); + while(std::getline(stream , part, del)) + parts.push_back(part); + + return parts; +} diff --git a/src/stringutils.h b/src/stringutils.h index 562309d..7d763c6 100644 --- a/src/stringutils.h +++ b/src/stringutils.h @@ -70,6 +70,8 @@ class MERE_UTILS_LIB_SPEC StringUtils static int indexOf(const QString& str, const QString &sub, uint occurrence = 1); + + static std::vector split(const std::string &str, char del = ' '); }; } From c8df08be35d264e7fb0d26d71e46824899b1f83f Mon Sep 17 00:00:00 2001 From: Bhuiyan Mohammad Iklash Date: Wed, 12 May 2021 06:30:51 +0600 Subject: [PATCH 5/5] Update README.md --- README.md | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef3a422..46241c9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # mere-utils-lib +An simple utility library contains common reusable functionality of components that are used in mere projects. -### Description -Utility library contains all the reusable functions for the components that are used in mere projects. - -### Components +### components - AppUtils - EnvUtils - BinUtils @@ -16,6 +14,30 @@ Utility library contains all the reusable functions for the components that are - SignalUtils - StringUtils -### Support +## requires +`mere-utils` requires following componnets +- C++11 +- QtCore + +## required +`mere-utils` is required by following app, utility and libaries, +- [mere-xdg](https://github.com/merelabs/mere-xdg-lib) +- [mere-config-lite](https://github.com/merelabs/mere-config-lite) +- [mere-finder-lib](https://github.com/merelabs/mere-finder-lib) +- [mere-launch](https://github.com/merelabs/mere-launch) +- [mere-finder-app](https://github.com/merelabs/mere-finder-app) + +## build ## +``` +$ git clone https://github.com/merelabs/mere-utils-lib.git +$ qmake +$ make +$ make install +``` + +### support If you find a bug, or have a feature suggestion, please [log an issue](https://github.com/merelabs/mere-utils-lib/issues). If you'd like to contribute, please read [How to Contribute](CONTRIBUTING.md). + +## license ## +All the code in this repository is licensed under a [BSD-2-Clause License](LICENSE).