Banuba SDK
filesystem.hpp
1 
2 #pragma once
3 
4 #include <bnb/utils/defs.hpp>
5 
6 #include <filesystem>
7 #include <algorithm>
8 
9 // we can't pollute global namespace in header
10 namespace bnb
11 {
12  namespace fs = std::filesystem;
13  using error_code = std::error_code;
14  using file_time_type = std::filesystem::file_time_type;
15 
16  inline fs::path replace_extension(fs::path p, const std::string& ext)
17  {
18  return p.replace_extension(std::string(".") + ext);
19  }
20 
21  std::string path_to_utf8(const fs::path& p);
22  fs::path utf8_to_path(const std::string& s);
23 
24  inline std::string remove_trailing_separator(std::string strpath)
25  {
26  if (!strpath.empty() && (fs::path::preferred_separator == strpath[strpath.size() - 1])) {
27  strpath.erase(strpath.size() - 1);
28  }
29  return strpath;
30  }
31 
32  template<typename... T>
33  bool match_extesions(const fs::path& path, T&&... extensions)
34  {
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); });
37  bool match = false;
38  ([&]() {
39  if (match) {
40  return;
41  }
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;
45  }(),
46  ...);
47 
48  return match;
49  }
50 } // namespace bnb
bnb::transform
void transform(const uint8_t *src, uint32_t src_w, uint32_t src_h, uint8_t *dst, uint32_t dst_w, uint32_t dst_h, uint32_t channels, const transformation &t)
Transform src image to dst.