52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <locale>
|
|
|
|
namespace fs
|
|
{
|
|
namespace detail
|
|
{
|
|
TL_DECLARE_STRING_LITERAL(EmptyRootTag, "");
|
|
}
|
|
|
|
// windows path system
|
|
template<typename parse_separators, typename format_separator>
|
|
template<typename T>
|
|
T WindowsSystemCustom<parse_separators, format_separator>::format_absolute(const tl::vector<tl::string>& members)
|
|
{
|
|
return tl::simple_path_system<detail::EmptyRootTag, parse_separators, format_separator>::template format_absolute<T>(members);
|
|
}
|
|
|
|
template<typename parse_separators, typename format_separator>
|
|
void WindowsSystemCustom<parse_separators, format_separator>::parse_absolute(tl::vector<tl::string>& o_elements, const char* path, size_t size)
|
|
{
|
|
// On windows, the drive letter case is undefined. To avoid issues (hashing, etc), we always convert the drive letter to uppercase
|
|
tl::simple_path_system<detail::EmptyRootTag, parse_separators, format_separator>::parse_absolute(o_elements, path, size);
|
|
if (!o_elements.empty())
|
|
{
|
|
tl::string& str = o_elements.front();
|
|
if (str.length() == 2 && str[1] == ':')
|
|
{
|
|
char strUp[2];
|
|
strUp[0] = tl::ascii::toupper(str[0]);
|
|
strUp[1] = ':';
|
|
str = tl::string(strUp, 2);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<typename parse_separators, typename format_separator>
|
|
bool WindowsSystemCustom<parse_separators, format_separator>::match(const char* path, size_t size)
|
|
{
|
|
return size >= 2 && std::isalpha(path[0], std::locale()) && path[1] == ':';
|
|
}
|
|
|
|
template<typename parse_separators, typename format_separator>
|
|
bool WindowsSystemCustom<parse_separators, format_separator>::validate_abs_path(const tl::vector<tl::string>& members)
|
|
{
|
|
return !members.empty() && match(members[0].c_str(), members[0].size());
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
}
|