2#ifndef LIBSBX_FILESYSTEM_ALIAS_HPP_
3#define LIBSBX_FILESYSTEM_ALIAS_HPP_
10namespace sbx::filesystem {
12template<utility::
character Char>
16 using char_type = Char;
17 using string_type = std::basic_string<char_type>;
18 using string_view_type = std::basic_string_view<char_type>;
19 using size_type = std::size_t;
20 using hash_type = std::size_t;
23 : _value{_normalize(string_view_type{})} { }
26 : _value{_normalize(
alias)} { }
32 auto string()
const &
noexcept ->
const string_type& {
36 auto string() &&
noexcept -> string_type {
37 return std::move(_value);
40 auto view()
const noexcept -> string_view_type {
44 auto length()
const noexcept -> size_type {
45 return _value.length();
48 auto hash()
const noexcept -> hash_type {
50 return std::hash<string_type>{}(_value);
53 auto operator==(
const basic_alias& other)
const noexcept ->
bool {
54 return _value == other._value;
59 static auto _normalize(string_view_type
alias) -> string_type {
60 auto normalized = string_type{
alias};
61 auto whitespace = string_view_type{
reinterpret_cast<const char_type*
>(
" \t\n\r")};
63 auto begin = normalized.find_first_not_of(whitespace);
65 if (begin == string_type::npos) {
67 }
else if (begin > 0) {
68 normalized.erase(0, begin);
71 if (!normalized.empty()) {
72 auto end = normalized.find_last_not_of(whitespace);
74 if (end != string_type::npos && end + 1 < normalized.size()) {
75 normalized.erase(end + 1);
79 if (normalized.find(
reinterpret_cast<const char_type*
>(
"://")) != string_type::npos) {
83 if (normalized.empty()) {
84 normalized =
reinterpret_cast<const char_type*
>(
"/");
87 if (normalized.front() !=
static_cast<char_type
>(
'/')) {
88 normalized.insert(normalized.begin(),
static_cast<char_type
>(
'/'));
91 while (normalized.size() > 1 && normalized.back() ==
static_cast<char_type
>(
'/')) {
92 normalized.pop_back();
95 if (normalized.back() !=
static_cast<char_type
>(
'/')) {
96 normalized.push_back(
static_cast<char_type
>(
'/'));
110template<sbx::utility::
character Char>
111struct std::hash<sbx::filesystem::basic_alias<Char>> {