mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
clang-format
This commit is contained in:
parent
bfc76278a9
commit
c40555c0ac
@ -488,27 +488,27 @@ SPDLOG_INLINE bool create_dir(filename_t path)
|
||||
|
||||
#ifdef _WIN32
|
||||
// support forward slash in windows
|
||||
std::replace(path.begin(), path.end(), '/', folder_sep);
|
||||
std::replace(path.begin(), path.end(), '/', folder_sep);
|
||||
#endif
|
||||
|
||||
size_t search_offset = 0;
|
||||
do
|
||||
{
|
||||
auto token_pos = path.find(folder_sep, search_offset);
|
||||
// treat the entire path as a folder if no folder separator not found
|
||||
if (token_pos == filename_t::npos)
|
||||
{
|
||||
token_pos = path.size();
|
||||
}
|
||||
size_t search_offset = 0;
|
||||
do
|
||||
{
|
||||
auto token_pos = path.find(folder_sep, search_offset);
|
||||
// treat the entire path as a folder if no folder separator not found
|
||||
if (token_pos == filename_t::npos)
|
||||
{
|
||||
token_pos = path.size();
|
||||
}
|
||||
|
||||
auto subdir = path.substr(0, token_pos);
|
||||
auto subdir = path.substr(0, token_pos);
|
||||
|
||||
if (!subdir.empty() && !file_exists(subdir) && !mkdir_(subdir))
|
||||
{
|
||||
return false; // return error if failed creating dir
|
||||
}
|
||||
search_offset = token_pos + 1;
|
||||
} while (search_offset < path.size());
|
||||
if (!subdir.empty() && !file_exists(subdir) && !mkdir_(subdir))
|
||||
{
|
||||
return false; // return error if failed creating dir
|
||||
}
|
||||
search_offset = token_pos + 1;
|
||||
} while (search_offset < path.size());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -521,8 +521,8 @@ SPDLOG_INLINE bool create_dir(filename_t path)
|
||||
SPDLOG_INLINE filename_t dir_name(filename_t path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// support forward slash in windows
|
||||
std::replace(path.begin(), path.end(), '/', folder_sep);
|
||||
// support forward slash in windows
|
||||
std::replace(path.begin(), path.end(), '/', folder_sep);
|
||||
#endif
|
||||
auto pos = path.find_last_of(folder_sep);
|
||||
return pos != filename_t::npos ? path.substr(0, pos) : filename_t{};
|
||||
|
@ -13,25 +13,23 @@ bool try_create_dir(const char *path, const char *normalized_path)
|
||||
return file_exists(normalized_path);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("create_dir", "[create_dir]")
|
||||
{
|
||||
prepare_logdir();
|
||||
|
||||
REQUIRE(try_create_dir("test_logs/dir1/dir1", "test_logs/dir1/dir1"));
|
||||
REQUIRE(try_create_dir("test_logs/dir1/dir1", "test_logs/dir1/dir1")); //test existing
|
||||
REQUIRE(try_create_dir("test_logs/dir1///dir2//", "test_logs/dir1/dir2"));
|
||||
REQUIRE(try_create_dir("./test_logs/dir1/dir3", "test_logs/dir1/dir3"));
|
||||
REQUIRE(try_create_dir("test_logs/../test_logs/dir1/dir4", "test_logs/dir1/dir4"));
|
||||
REQUIRE(try_create_dir("test_logs/dir1/dir1", "test_logs/dir1/dir1")); // test existing
|
||||
REQUIRE(try_create_dir("test_logs/dir1///dir2//", "test_logs/dir1/dir2"));
|
||||
REQUIRE(try_create_dir("./test_logs/dir1/dir3", "test_logs/dir1/dir3"));
|
||||
REQUIRE(try_create_dir("test_logs/../test_logs/dir1/dir4", "test_logs/dir1/dir4"));
|
||||
|
||||
#ifdef WIN32
|
||||
// test backslash folder separator
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir222", "test_logs\\dir1\\dir222"));
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir223\\", "test_logs\\dir1\\dir223\\"));
|
||||
REQUIRE(try_create_dir(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23", "test_logs\\dir1\\dir2\\dir23"));
|
||||
REQUIRE(try_create_dir("test_logs\\..\\test_logs\\dir1\\dir5", "test_logs\\dir1\\dir5"));
|
||||
// test backslash folder separator
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir222", "test_logs\\dir1\\dir222"));
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir223\\", "test_logs\\dir1\\dir223\\"));
|
||||
REQUIRE(try_create_dir(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23", "test_logs\\dir1\\dir2\\dir23"));
|
||||
REQUIRE(try_create_dir("test_logs\\..\\test_logs\\dir1\\dir5", "test_logs\\dir1\\dir5"));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("dir_name", "[create_dir]")
|
||||
@ -44,31 +42,30 @@ TEST_CASE("dir_name", "[create_dir]")
|
||||
REQUIRE(dir_name(R"(dir\)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\\\)") == R"(dir\\)");
|
||||
REQUIRE(dir_name(R"(dir\file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\file.txt)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\file.txt\)") == R"(dir\file.txt)");
|
||||
REQUIRE(dir_name(R"(dir/file.txt/)") == R"(dir\file.txt)");
|
||||
REQUIRE(dir_name(R"(dir/file.txt/)") == R"(dir\file.txt)");
|
||||
REQUIRE(dir_name(R"(\dir\file.txt)") == R"(\dir)");
|
||||
REQUIRE(dir_name(R"(/dir/file.txt)") == R"(\dir)");
|
||||
REQUIRE(dir_name(R"(/dir/file.txt)") == R"(\dir)");
|
||||
REQUIRE(dir_name(R"(\\dir\file.txt)") == R"(\\dir)");
|
||||
REQUIRE(dir_name(R"(//dir/file.txt)") == R"(\\dir)");
|
||||
REQUIRE(dir_name(R"(//dir/file.txt)") == R"(\\dir)");
|
||||
REQUIRE(dir_name(R"(..\file.txt)") == "..");
|
||||
REQUIRE(dir_name(R"(../file.txt)") == "..");
|
||||
REQUIRE(dir_name(R"(../file.txt)") == "..");
|
||||
REQUIRE(dir_name(R"(.\file.txt)") == ".");
|
||||
REQUIRE(dir_name(R"(./file.txt)") == ".");
|
||||
REQUIRE(dir_name(R"(./file.txt)") == ".");
|
||||
REQUIRE(dir_name(R"(c:\\a\b\c\d\file.txt)") == R"(c:\\a\b\c\d)");
|
||||
REQUIRE(dir_name(R"(c://a/b/c/d/file.txt)") == R"(c:\\a\b\c\d)");
|
||||
REQUIRE(dir_name(R"(c://a/b/c/d/file.txt)") == R"(c:\\a\b\c\d)");
|
||||
#else
|
||||
REQUIRE(dir_name("dir/") == "dir");
|
||||
REQUIRE(dir_name("dir///") == "dir//");
|
||||
REQUIRE(dir_name("dir/file") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt/") == "dir/file.txt");
|
||||
REQUIRE(dir_name("/dir/file.txt") == "/dir");
|
||||
REQUIRE(dir_name("//dir/file.txt") == "//dir");
|
||||
REQUIRE(dir_name("../file.txt") == "..");
|
||||
REQUIRE(dir_name("./file.txt") == ".");
|
||||
REQUIRE(dir_name("dir/") == "dir");
|
||||
REQUIRE(dir_name("dir///") == "dir//");
|
||||
REQUIRE(dir_name("dir/file") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt/") == "dir/file.txt");
|
||||
REQUIRE(dir_name("/dir/file.txt") == "/dir");
|
||||
REQUIRE(dir_name("//dir/file.txt") == "//dir");
|
||||
REQUIRE(dir_name("../file.txt") == "..");
|
||||
REQUIRE(dir_name("./file.txt") == ".");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user