This commit is contained in:
jeanlemotan
2024-07-02 18:12:23 +02:00
commit b344afa9fe
89 changed files with 10568 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <tl/vector.h>
#include "tl/string.h"
#include "tl/path_system.h"
#include "tl/rel_path.h"
#include "tl/abs_path.h"
namespace fs
{
// custom windows path system
template<typename parse_separators, typename format_separator>
struct WindowsSystemCustom : public tl::detail::path_system::base_path_system<parse_separators, format_separator>
{
template<typename T>
static T format_absolute(const tl::vector<tl::string>& members);
static void parse_absolute(tl::vector<tl::string>& o_elements, const char* path, size_t size);
static bool validate_abs_path(const tl::vector<tl::string>& members);
static bool match(const char* path, size_t size);
};
TL_DECLARE_STRING_VECTOR(WindowsParseSeparators, "\\", "/");
TL_DECLARE_STRING_LITERAL(WindowsFormatSeparator, "\\");
using WindowsSystem = WindowsSystemCustom<WindowsParseSeparators, WindowsFormatSeparator>;
// posix path system
TL_DECLARE_STRING_LITERAL(PosixRootTag, "/");
TL_DECLARE_STRING_VECTOR(PosixParseSeparators, "/");
TL_DECLARE_STRING_LITERAL(PosixFormatSeparator, "/");
using PosixSystem = tl::simple_path_system<PosixRootTag, PosixParseSeparators, PosixFormatSeparator>;
// mac path system
TL_DECLARE_STRING_LITERAL(UncRootTag, "\\\\");
TL_DECLARE_STRING_VECTOR(UncParseSeparators, "\\", "/");
TL_DECLARE_STRING_LITERAL(UncFormatSeparator, "\\");
using UncSystem = tl::simple_path_system<UncRootTag, UncParseSeparators, UncFormatSeparator>;
using AbsPath = tl::abs_path<tl::path_systems<WindowsSystem, PosixSystem, UncSystem> >;
using RelPath = AbsPath::rel_path_type;
}
#include "fs/AbsPath.inl"
template <>
struct std::formatter<fs::RelPath>
{
constexpr auto parse(format_parse_context& ctx) noexcept { return ctx.begin(); }
auto format(const fs::RelPath& p, std::format_context& ctx) const
{
return format_to(ctx.out(), "{}", p.get_as<fs::PosixSystem>());
}
};