Newer
Older
#ifndef UTIL__H
#define UTIL__H
#include <string>
#include <vector>
#include <array>
Franck Dary
committed
#include <regex>
#include <boost/flyweight.hpp>
namespace util
{
void warning(std::string_view message, const std::experimental::source_location & location = std::experimental::source_location::current());
void error(std::string_view message, const std::experimental::source_location & location = std::experimental::source_location::current());
void error(const std::exception & e, const std::experimental::source_location & location = std::experimental::source_location::current());
void myThrow(std::string_view message, const std::experimental::source_location & location = std::experimental::source_location::current());
std::vector<std::filesystem::path> findFilesByExtension(std::filesystem::path directory, std::string extension);
std::string_view getFilenameFromPath(std::string_view s);
std::vector<std::string> split(std::string_view s, char delimiter);
utf8string splitAsUtf8(std::string_view s);
std::string int2HumanStr(int number);
std::string shrink(const std::string & s, int printedSize);
int printedLength(std::string_view s);
bool isSeparator(utf8char c);
bool isIllegal(utf8char c);
template <typename T>
bool isEmpty(const std::vector<T> & s)
{
return s.empty();
}
template <typename T>
bool isEmpty(const std::basic_string<T> & s)
template <typename T>
std::size_t getSize(const std::vector<T> & s)
{
return s.size();
}
template <typename T>
std::size_t getSize(const boost::flyweight<T> & s)
{
return getSize(s.get());
}
template <typename T>
bool isEmpty(const boost::flyweight<T> & s)
{
return isEmpty(s.get());
}
bool doIfNameMatch(const std::regex & reg, std::string_view name, const std::function<void(const std::smatch &)> & f);
Franck Dary
committed
template <>
struct fmt::formatter<std::experimental::source_location>
{
constexpr auto parse(format_parse_context & ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const std::experimental::source_location & d, FormatContext & ctx)
return format_to(ctx.out(), "{},l.{},'{}'", util::getFilenameFromPath(d.file_name()), d.line(), d.function_name());
}
};
template <typename T>
struct fmt::formatter<boost::flyweight<T>>
{
constexpr auto parse(format_parse_context & ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const boost::flyweight<T> & s, FormatContext & ctx)
{
return format_to(ctx.out(), "{}", s.get());
}
};