You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/tests/utils.cpp

53 lines
1.3 KiB
C++

9 years ago
#include "includes.h"
void prepare_logdir()
{
9 years ago
spdlog::drop_all();
9 years ago
#ifdef _WIN32
9 years ago
system("if not exist logs mkdir logs");
system("del /F /Q logs\\*");
9 years ago
#else
9 years ago
auto rv = system("mkdir -p logs");
rv = system("rm -f logs/*");
(void)rv;
9 years ago
#endif
9 years ago
}
8 years ago
std::string file_contents(const std::string &filename)
9 years ago
{
std::ifstream ifs(filename);
if (!ifs)
throw std::runtime_error("Failed open file ");
8 years ago
return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
9 years ago
}
8 years ago
std::size_t count_lines(const std::string &filename)
9 years ago
{
std::ifstream ifs(filename);
if (!ifs)
throw std::runtime_error("Failed open file ");
std::string line;
size_t counter = 0;
8 years ago
while (std::getline(ifs, line))
9 years ago
counter++;
return counter;
}
8 years ago
std::size_t get_filesize(const std::string &filename)
9 years ago
{
std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
if (!ifs)
throw std::runtime_error("Failed open file ");
return static_cast<std::size_t>(ifs.tellg());
9 years ago
}
// source: https://stackoverflow.com/a/2072890/192001
8 years ago
bool ends_with(std::string const &value, std::string const &ending)
8 years ago
{
8 years ago
if (ending.size() > value.size())
return false;
8 years ago
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}