7#include "plg/config.hpp"
10 using path_view = std::basic_string_view<std::filesystem::path::value_type>;
11 using path_string = std::filesystem::path::string_type;
12 using path_char = path_string::value_type;
13 using path_diff_t = path_string::difference_type;
15#if PLUGIFY_PLATFORM_WINDOWS
16#define PLUGIFY_PATH_LITERAL(x) L##x
18#define PLUGIFY_PATH_LITERAL(x) x
21 template <
typename char_type>
22 bool insensitive_equals(
const path_char lhs,
const path_char rhs) {
23 if constexpr (std::is_same_v<char_type, wchar_t>) {
24 return std::towlower(
static_cast<std::wint_t
>(lhs)) == std::towlower(
static_cast<std::wint_t
>(rhs));
26 return std::tolower(
static_cast<unsigned char>(lhs)) == std::tolower(
static_cast<unsigned char>(rhs));
30 inline bool insensitive_equals(
const path_view lhs,
const path_view rhs) {
31 return lhs.size() == rhs.size() && std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), insensitive_equals<path_char>);
34 inline path_view extension_view(
const std::filesystem::path& path,
size_t extension_size) {
35 if (!path.has_extension()) {
38 const path_string& path_str = path.native();
39 const auto offset =
static_cast<path_diff_t
>(path_str.size() - extension_size);
43 return { path_str.cbegin() + offset, path_str.cend() };
46 inline bool has_extension(
const std::filesystem::path& path,
const path_view extension) {
47 return insensitive_equals(extension_view(path, extension.size()), extension);
50 inline auto as_string(
const std::filesystem::path& p) {
51#if PLUGIFY_PLATFORM_WINDOWS