Skip to content

Commit

Permalink
Merge pull request #12 from merelabs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bmin authored May 12, 2021
2 parents 7ff6027 + f723d3f commit 1a25be2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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).
5 changes: 5 additions & 0 deletions src/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/pathutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion src/stringutils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stringutils.h"

#include <iostream>
#include <sstream>

bool Mere::Utils::StringUtils::isInteger(const QString& str, int base)
{
Expand Down Expand Up @@ -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)
Expand All @@ -77,8 +80,9 @@ std::string& Mere::Utils::StringUtils::trim(std::string &str)
str = str.erase(pos + 1);
}
else
{
str.clear();

}

return str;
}
Expand Down Expand Up @@ -175,3 +179,16 @@ int Mere::Utils::StringUtils::indexOf(const QString& str, const QString &sub, ui

return pos;
}

//static
std::vector<std::string> Mere::Utils::StringUtils::split(const std::string &str, char del)
{
std::vector<std::string> parts;

std::string part;
std::stringstream stream (str);
while(std::getline(stream , part, del))
parts.push_back(part);

return parts;
}
2 changes: 2 additions & 0 deletions src/stringutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> split(const std::string &str, char del = ' ');
};

}
Expand Down

0 comments on commit 1a25be2

Please sign in to comment.