2021-04-29 02:11:44 +02:00
|
|
|
// This file is under GNU General Public License 3.0
|
|
|
|
// see LICENSE.txt
|
|
|
|
|
|
|
|
#ifndef LIBPEPADAPTER_STD_UTILS_HH
|
|
|
|
#define LIBPEPADAPTER_STD_UTILS_HH
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <exception>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace pEp {
|
|
|
|
namespace Utils {
|
|
|
|
// C-types helpers
|
|
|
|
bool is_c_str_empty(const char *str);
|
|
|
|
|
|
|
|
// C++/STL data types to string
|
|
|
|
template<typename T>
|
|
|
|
std::string to_string(const std::vector<T> &v);
|
|
|
|
|
|
|
|
// exception utils
|
|
|
|
std::string nested_exception_to_string(
|
|
|
|
const std::exception &e,
|
|
|
|
int level = 0,
|
|
|
|
std::string src = "");
|
|
|
|
void print_exception(const std::exception &e, int level = 0);
|
|
|
|
|
|
|
|
// file utils
|
|
|
|
bool path_exists(const std::string &filename);
|
|
|
|
bool path_is_dir(const std::string &path);
|
|
|
|
void path_delete(const std::string &filename);
|
|
|
|
void path_delete_all(const std::string &path);
|
|
|
|
|
|
|
|
std::ofstream file_create(const std::string &filename);
|
|
|
|
void path_ensure_not_existing(const std::string &path);
|
|
|
|
|
|
|
|
void dir_create(const std::string &dirname, const mode_t mode = 0775);
|
|
|
|
std::vector<std::string> dir_list_all(
|
|
|
|
const std::string &path,
|
|
|
|
const bool incl_dot_and_dotdot = false);
|
|
|
|
std::vector<std::string> dir_list_dirs(
|
|
|
|
const std::string &dirname,
|
|
|
|
const bool incl_dot_and_dotdot = false);
|
|
|
|
std::vector<std::string> dir_list_files(const std::string &dirname);
|
2021-06-01 22:22:46 +02:00
|
|
|
|
|
|
|
//String formatting
|
|
|
|
std::string padTo(const std::string &str, const size_t num, const char paddingChar);
|
|
|
|
|
2021-06-07 12:57:14 +02:00
|
|
|
enum class Color
|
|
|
|
{
|
|
|
|
RESET,
|
|
|
|
BLACK,
|
|
|
|
RED,
|
|
|
|
GREEN,
|
|
|
|
YELLOW,
|
|
|
|
BLUE,
|
|
|
|
MAGENTA,
|
|
|
|
CYAN,
|
|
|
|
WHITE,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string to_termcol(const Color& col);
|
|
|
|
|
2021-04-29 02:11:44 +02:00
|
|
|
} // namespace Utils
|
|
|
|
} // namespace pEp
|
|
|
|
|
|
|
|
#include "std_utils.hxx"
|
|
|
|
|
|
|
|
#endif // LIBPEPADAPTER_STD_UTILS_HH
|