4#include <bnb/utils/defs.hpp>
12 namespace fs = std::filesystem;
13 using error_code = std::error_code;
14 using file_time_type = std::filesystem::file_time_type;
16 inline fs::path replace_extension(fs::path p,
const std::string& ext)
18 return p.replace_extension(std::string(
".") + ext);
21 std::string path_to_utf8(
const fs::path& p);
22 fs::path utf8_to_path(
const std::string& s);
24 inline std::string remove_trailing_separator(std::string strpath)
26 if (!strpath.empty() && (fs::path::preferred_separator == strpath[strpath.size() - 1])) {
27 strpath.erase(strpath.size() - 1);
32 template<
typename... T>
33 bool match_extesions(
const fs::path& path, T&&... extensions)
35 auto ext = bnb::path_to_utf8(path.extension());
36 std::transform(ext.begin(), ext.end(), ext.begin(), [](
unsigned char c) { return std::tolower(c); });
42 std::string ext_to_lower(extensions);
43 std::transform(ext_to_lower.begin(), ext_to_lower.end(), ext_to_lower.begin(), [](
unsigned char c) { return std::tolower(c); });
44 match = ext == ext_to_lower;