updated build system
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
parent
dd492ff52d
commit
a3e578240b
57
support/3rd_party/include/utils/path.hpp
vendored
57
support/3rd_party/include/utils/path.hpp
vendored
@ -269,27 +269,35 @@ combine(std::wstring path,
|
|||||||
template <typename string_t>
|
template <typename string_t>
|
||||||
[[nodiscard]] inline auto create_api_path_t(
|
[[nodiscard]] inline auto create_api_path_t(
|
||||||
std::basic_string_view<typename string_t::value_type> path) -> string_t {
|
std::basic_string_view<typename string_t::value_type> path) -> string_t {
|
||||||
static auto backslash_t = get_backslash<typename string_t::value_type>();
|
auto backslash_t = get_backslash<typename string_t::value_type>();
|
||||||
static auto dot_slash_t = get_dot_slash<typename string_t::value_type>();
|
auto dot_t = get_dot<typename string_t::value_type>();
|
||||||
static auto dot_t = get_dot<typename string_t::value_type>();
|
auto dot_slash_t = get_dot_slash<typename string_t::value_type>();
|
||||||
static auto slash_t = get_slash<typename string_t::value_type>();
|
auto slash_t = get_slash<typename string_t::value_type>();
|
||||||
|
|
||||||
if (path.empty() || (path == dot_t) || (path == slash_t)) {
|
if (path.empty() || path == backslash_t || path == dot_t ||
|
||||||
|
path == dot_slash_t || path == slash_t) {
|
||||||
return string_t{slash_t};
|
return string_t{slash_t};
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t api_path{path};
|
string_t api_path{path};
|
||||||
|
#if defined(_WIN32)
|
||||||
|
if ((api_path.size() >= 2U) && (api_path.at(1U) == ':')) {
|
||||||
|
api_path = api_path.substr(2U);
|
||||||
|
}
|
||||||
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
|
while (utils::string::begins_with(api_path, dot_slash_t)) {
|
||||||
|
api_path = api_path.substr(dot_slash_t.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
while (utils::string::begins_with(api_path, dot_t)) {
|
||||||
|
api_path = api_path.substr(dot_t.size());
|
||||||
|
}
|
||||||
|
|
||||||
format_path(api_path, slash_t, backslash_t);
|
format_path(api_path, slash_t, backslash_t);
|
||||||
if (api_path.find(dot_slash_t) == 0) {
|
|
||||||
api_path = api_path.substr(1U);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (api_path.at(0U) != '/') {
|
if (api_path.at(0U) != slash_t.at(0U)) {
|
||||||
api_path = string_t{slash_t} + api_path;
|
return string_t{slash_t} + api_path;
|
||||||
}
|
|
||||||
|
|
||||||
if ((api_path != slash_t) && utils::string::ends_with(api_path, slash_t)) {
|
|
||||||
utils::string::right_trim(api_path, '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return api_path;
|
return api_path;
|
||||||
@ -347,14 +355,6 @@ template <typename string_t>
|
|||||||
format_path(fmt_path,
|
format_path(fmt_path,
|
||||||
get_directory_seperator<typename string_t::value_type>(),
|
get_directory_seperator<typename string_t::value_type>(),
|
||||||
get_not_directory_seperator<typename string_t::value_type>());
|
get_not_directory_seperator<typename string_t::value_type>());
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
if ((fmt_path.size() >= 2U) && (fmt_path.at(1U) == ':')) {
|
|
||||||
fmt_path[0U] =
|
|
||||||
utils::string::to_lower(string_t{1U, fmt_path.at(0U)}).at(0U);
|
|
||||||
}
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
return fmt_path;
|
return fmt_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,11 +374,21 @@ format_path(string_t &path,
|
|||||||
-> string_t & {
|
-> string_t & {
|
||||||
utils::string::replace(path, not_sep, sep);
|
utils::string::replace(path, not_sep, sep);
|
||||||
|
|
||||||
string_t double_sep{2U, sep.at(0U)};
|
string_t double_sep(2U, sep.at(0U));
|
||||||
while (utils::string::contains(path, double_sep)) {
|
while (utils::string::contains(path, double_sep)) {
|
||||||
utils::string::replace(path, double_sep, sep);
|
utils::string::replace(path, double_sep, sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path != sep) {
|
||||||
|
utils::string::right_trim(path, sep.at(0U));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
if ((path.size() >= 2U) && (path.at(1U) == ':')) {
|
||||||
|
path[0U] = utils::string::to_lower(string_t{1U, path.at(0U)}).at(0U);
|
||||||
|
}
|
||||||
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,6 +406,7 @@ template <typename string_t>
|
|||||||
if (ret == slash_t) {
|
if (ret == slash_t) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils::string::right_trim(ret, '/');
|
return utils::string::right_trim(ret, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
support/3rd_party/test/src/utils/path_test.cpp
vendored
44
support/3rd_party/test/src/utils/path_test.cpp
vendored
@ -119,6 +119,47 @@ TEST(utils_path, combine) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(utils_path, format_path) {
|
||||||
|
std::string path{"\\"};
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "\\\\";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "\\\\\\";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "\\\\\\\\";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "/";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
path = "//";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "///";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
|
||||||
|
path = "////";
|
||||||
|
utils::path::format_path(path, utils::path::directory_seperator,
|
||||||
|
utils::path::not_directory_seperator);
|
||||||
|
EXPECT_STREQ("/", path.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(utils_path, create_api_path) {
|
TEST(utils_path, create_api_path) {
|
||||||
auto s = utils::path::create_api_path("");
|
auto s = utils::path::create_api_path("");
|
||||||
EXPECT_STREQ("/", s.c_str());
|
EXPECT_STREQ("/", s.c_str());
|
||||||
@ -132,6 +173,9 @@ TEST(utils_path, create_api_path) {
|
|||||||
s = utils::path::create_api_path(".");
|
s = utils::path::create_api_path(".");
|
||||||
EXPECT_STREQ("/", s.c_str());
|
EXPECT_STREQ("/", s.c_str());
|
||||||
|
|
||||||
|
s = utils::path::create_api_path("./");
|
||||||
|
EXPECT_STREQ("/", s.c_str());
|
||||||
|
|
||||||
s = utils::path::create_api_path(R"(\\)");
|
s = utils::path::create_api_path(R"(\\)");
|
||||||
EXPECT_STREQ("/", s.c_str());
|
EXPECT_STREQ("/", s.c_str());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user