diff --git a/support/include/utils/path.hpp b/support/include/utils/path.hpp index f05e4a1e..f833061a 100644 --- a/support/include/utils/path.hpp +++ b/support/include/utils/path.hpp @@ -53,50 +53,50 @@ inline constexpr const std::wstring_view not_directory_seperator_w{backslash_w}; #endif // defined(_WIN32) template -[[nodiscard]] inline constexpr auto get_backslash() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_backslash() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_backslash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_backslash() -> std::basic_string_view { return backslash; } template <> -[[nodiscard]] inline constexpr auto get_backslash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_backslash() -> std::basic_string_view { return backslash_w; } template -[[nodiscard]] inline constexpr auto get_directory_seperator() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_directory_seperator() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_directory_seperator() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_directory_seperator() -> std::basic_string_view { return directory_seperator; } template <> -[[nodiscard]] inline constexpr auto get_directory_seperator() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_directory_seperator() -> std::basic_string_view { return directory_seperator_w; } template -[[nodiscard]] inline constexpr auto get_not_directory_seperator() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_not_directory_seperator() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_not_directory_seperator() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_not_directory_seperator() -> std::basic_string_view { return not_directory_seperator; } template <> -[[nodiscard]] inline constexpr auto get_not_directory_seperator() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_not_directory_seperator() -> std::basic_string_view { return not_directory_seperator_w; } @@ -104,95 +104,95 @@ template [[nodiscard]] inline constexpr auto get_dot() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_dot() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot() -> std::basic_string_view { return dot; } template <> -[[nodiscard]] inline constexpr auto get_dot() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot() -> std::basic_string_view { return dot_w; } template -[[nodiscard]] inline constexpr auto get_dot_backslash() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_dot_backslash() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_dot_backslash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot_backslash() -> std::basic_string_view { return dot_backslash; } template <> -[[nodiscard]] inline constexpr auto get_dot_backslash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot_backslash() -> std::basic_string_view { return dot_backslash_w; } template -[[nodiscard]] inline constexpr auto get_dot_slash() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_dot_slash() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_dot_slash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot_slash() -> std::basic_string_view { return dot_slash; } template <> -[[nodiscard]] inline constexpr auto get_dot_slash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_dot_slash() -> std::basic_string_view { return dot_slash_w; } template -[[nodiscard]] inline constexpr auto get_long_notation() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_long_notation() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_long_notation() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_long_notation() -> std::basic_string_view { return long_notation; } template <> -[[nodiscard]] inline constexpr auto get_long_notation() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_long_notation() -> std::basic_string_view { return long_notation_w; } template -[[nodiscard]] inline constexpr auto get_slash() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_slash() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_slash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_slash() -> std::basic_string_view { return slash; } template <> -[[nodiscard]] inline constexpr auto get_slash() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_slash() -> std::basic_string_view { return slash_w; } #if defined(_WIN32) template -[[nodiscard]] inline constexpr auto get_unc_notation() - -> std::basic_string_view; +[[nodiscard]] inline constexpr auto +get_unc_notation() -> std::basic_string_view; template <> -[[nodiscard]] inline constexpr auto get_unc_notation() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_unc_notation() -> std::basic_string_view { return unc_notation; } template <> -[[nodiscard]] inline constexpr auto get_unc_notation() - -> std::basic_string_view { +[[nodiscard]] inline constexpr auto +get_unc_notation() -> std::basic_string_view { return unc_notation_w; } #endif // defined(_WIN32) @@ -204,13 +204,13 @@ template [[nodiscard]] auto absolute(std::wstring_view path) -> std::wstring; -[[nodiscard]] inline auto combine(std::string_view path, - const std::vector &paths) - -> std::string; +[[nodiscard]] inline auto +combine(std::string_view path, + const std::vector &paths) -> std::string; -[[nodiscard]] inline auto combine(std::wstring_view path, - const std::vector &paths) - -> std::wstring; +[[nodiscard]] inline auto +combine(std::wstring_view path, + const std::vector &paths) -> std::wstring; [[nodiscard]] auto contains_trash_directory(std::string_view path) -> bool; @@ -242,28 +242,28 @@ format_path(string_t &path, std::basic_string_view not_sep) -> string_t &; -[[nodiscard]] inline auto get_parent_api_path(std::string_view path) - -> std::string; +[[nodiscard]] inline auto +get_parent_api_path(std::string_view path) -> std::string; -[[nodiscard]] inline auto get_parent_api_path(std::wstring_view path) - -> std::wstring; +[[nodiscard]] inline auto +get_parent_api_path(std::wstring_view path) -> std::wstring; [[nodiscard]] auto get_parent_path(std::string_view path) -> std::string; [[nodiscard]] auto get_parent_path(std::wstring_view path) -> std::wstring; -[[nodiscard]] inline auto get_parts(std::string_view path) - -> std::vector; +[[nodiscard]] inline auto +get_parts(std::string_view path) -> std::vector; -[[nodiscard]] inline auto get_parts_w(std::wstring_view path) - -> std::vector; +[[nodiscard]] inline auto +get_parts_w(std::wstring_view path) -> std::vector; [[nodiscard]] auto get_relative_path(std::string_view path, std::string_view root_path) -> std::string; -[[nodiscard]] auto get_relative_path(std::wstring_view path, - std::wstring_view root_path) - -> std::wstring; +[[nodiscard]] auto +get_relative_path(std::wstring_view path, + std::wstring_view root_path) -> std::wstring; [[nodiscard]] auto make_file_uri(std::string_view path) -> std::string; @@ -301,16 +301,15 @@ inline auto combine(std::string_view path, return combine_t(path, paths); } -inline auto combine(std::wstring_view path, - const std::vector &paths) - -> std::wstring { +inline auto +combine(std::wstring_view path, + const std::vector &paths) -> std::wstring { return combine_t(path, paths); } template -[[nodiscard]] inline auto -create_api_path_t(std::basic_string_view path) - -> string_t { +[[nodiscard]] inline auto create_api_path_t( + std::basic_string_view path) -> string_t { auto backslash_t = get_backslash(); auto dot_backslash_t = get_dot_backslash(); auto dot_slash_t = get_dot_slash(); @@ -358,9 +357,8 @@ inline auto create_api_path(std::wstring_view path) -> std::wstring { } template -[[nodiscard]] inline auto -finalize_t(std::basic_string_view path) - -> string_t { +[[nodiscard]] inline auto finalize_t( + std::basic_string_view path) -> string_t { string_t dir_sep_t{get_directory_seperator()}; string_t fmt_path{path}; if (fmt_path.empty()) { @@ -484,17 +482,19 @@ template std::basic_string_view path) -> string_t { auto slash_t = get_slash(); - if (path == slash_t) { + string_t ret{path}; + utils::string::right_trim(ret, slash_t.at(0U)); + + if (ret == slash_t || ret.empty()) { return string_t{path}; } - auto sub_path = path.substr(0, path.rfind(slash_t) + 1); + auto sub_path = ret.substr(0, ret.rfind(slash_t) + 1); if (sub_path == slash_t) { return string_t{sub_path}; } - string_t ret{sub_path}; - return utils::string::right_trim(ret, slash_t.at(0U)); + return sub_path; } inline auto get_parent_api_path(std::string_view path) -> std::string { diff --git a/support/test/src/utils/path_test.cpp b/support/test/src/utils/path_test.cpp index b0cb8503..7cd1d336 100644 --- a/support/test/src/utils/path_test.cpp +++ b/support/test/src/utils/path_test.cpp @@ -264,6 +264,23 @@ TEST(utils_path, create_api_path) { EXPECT_STREQ("/.state/.local", s.c_str()); } +TEST(utils_path, get_parent_api_path) { + auto s = utils::path::get_parent_api_path(""); + EXPECT_STREQ("/", s.c_str()); + + s = utils::path::get_parent_api_path("/"); + EXPECT_STREQ("/", s.c_str()); + + s = utils::path::get_parent_api_path("/moose"); + EXPECT_STREQ("/", s.c_str()); + + s = utils::path::get_parent_api_path("/moose/cow"); + EXPECT_STREQ("/moose", s.c_str()); + + s = utils::path::get_parent_api_path("/moose/cow/"); + EXPECT_STREQ("/moose", s.c_str()); +} + TEST(utils_path, finalize) { auto s = utils::path::finalize(""); EXPECT_STREQ("", s.c_str());