Skip to content

Commit ea3dfd2

Browse files
committed
use .string() instead of .generic_string() where not needed
1 parent 7a3d309 commit ea3dfd2

File tree

11 files changed

+34
-26
lines changed

11 files changed

+34
-26
lines changed

src/absolute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ std::string fs_absolute(std::string_view path, const bool expand_tilde)
3535
std::error_code ec;
3636

3737
if(auto a = Filesystem::absolute(ex, ec); !ec)
38-
return a.generic_string();
38+
return a.string();
3939

4040
fs_print_error(path, __func__, ec);
4141
return {};

src/normalize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fs_drop_slash(std::string_view in)
118118

119119
if(fs_is_windows()){
120120
// Extended-length or device path
121-
if(in.length() >= 4 && fs_win32_is_ext_path(in)){
121+
if(fs_win32_is_ext_path(in)){
122122
i = 4;
123123
#if defined(_WIN32)
124124
} else if (PathIsUNCA(in.data())){

src/platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::string fs_get_cwd()
5454

5555
#if defined(HAVE_CXX_FILESYSTEM)
5656
if(auto s = Filesystem::current_path(ec); !ec) FFS_LIKELY
57-
return s.generic_string();
57+
return s.string();
5858
#elif defined(_WIN32)
5959
// windows.h https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
6060
if(DWORD L = GetCurrentDirectoryW(0, nullptr); L > 0) {

src/pure.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool fs_is_absolute(std::string_view path)
6969
return false;
7070

7171
// Extended-length or device path
72-
if(path.length() >= 4 && fs_win32_is_ext_path(path))
72+
if(fs_win32_is_ext_path(path))
7373
return true;
7474
#if defined(_WIN32)
7575
if(PathIsUNCA(path.data()))
@@ -87,7 +87,7 @@ bool fs_is_absolute(std::string_view path)
8787
std::string fs_file_name(std::string_view path)
8888
{
8989
#ifdef HAVE_CXX_FILESYSTEM
90-
return Filesystem::path(path).filename().generic_string();
90+
return Filesystem::path(path).filename().string();
9191
#else
9292

9393
const auto i = path.find_last_of(fs_is_windows() ? "/\\" : "/");
@@ -104,13 +104,22 @@ std::string fs_root(std::string_view path)
104104
// root_path = root_name / root_directory
105105

106106
#ifdef HAVE_CXX_FILESYSTEM
107-
return Filesystem::path(path).root_path().generic_string();
107+
return Filesystem::path(path).root_path().string();
108108
#else
109-
if (std::string r = fs_root_name(path);
110-
r.empty())
111-
return fs_slash_first(path) ? "/" : "";
112-
else
113-
return (fs_is_windows() && r == path) ? r : r + "/";
109+
if (std::string r = fs_root_name(path); r.empty()){
110+
if (fs_slash_first(path))
111+
return std::string(path.substr(0, 1));
112+
113+
return {};
114+
} else if (fs_is_windows()) {
115+
if (path.length() >= 3 && (path[2] == '/' || path[2] == '\\')){
116+
return r + path[2];
117+
}
118+
119+
return r;
120+
} else
121+
return "/";
122+
114123
#endif
115124
}
116125

@@ -133,7 +142,7 @@ std::string fs_root_name([[maybe_unused]] std::string_view path)
133142
std::string fs_stem(std::string_view path)
134143
{
135144
#ifdef HAVE_CXX_FILESYSTEM
136-
return Filesystem::path(path).filename().stem().generic_string();
145+
return Filesystem::path(path).filename().stem().string();
137146
#else
138147
std::string r = fs_file_name(path);
139148
// handle special case a/..
@@ -153,7 +162,7 @@ std::string fs_stem(std::string_view path)
153162
std::string fs_suffix(std::string_view path)
154163
{
155164
#ifdef HAVE_CXX_FILESYSTEM
156-
return Filesystem::path(path).filename().extension().generic_string();
165+
return Filesystem::path(path).filename().extension().string();
157166
#else
158167
const std::string p = fs_file_name(path);
159168
// find last dot
@@ -200,7 +209,7 @@ std::string fs_with_suffix(std::string_view path, std::string_view new_suffix)
200209
return fs_join(path, new_suffix);
201210

202211
#ifdef HAVE_CXX_FILESYSTEM
203-
return Filesystem::path(path).replace_extension(new_suffix).generic_string();
212+
return Filesystem::path(path).replace_extension(new_suffix).string();
204213
#else
205214
std::string const p = fs_parent(path);
206215

@@ -233,7 +242,7 @@ std::string fs_lexically_normal(std::string_view path){
233242

234243
std::string fs_make_preferred(std::string_view path){
235244
#ifdef HAVE_CXX_FILESYSTEM
236-
return Filesystem::path(path).make_preferred().generic_string();
245+
return Filesystem::path(path).make_preferred().string();
237246
#else
238247
fs_print_error(path, __func__, std::make_error_code(std::errc::function_not_supported));
239248
return {};

src/symlink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ std::string fs_read_symlink(std::string_view path)
116116
return fs_win32_final_path(path);
117117
#elif defined(HAVE_CXX_FILESYSTEM)
118118
if(auto p = Filesystem::read_symlink(path, ec); !ec) FFS_LIKELY
119-
return p.generic_string();
119+
return p.string();
120120
#else
121121

122122
// https://www.man7.org/linux/man-pages/man2/readlink.2.html

src/tempdir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ std::string fs_get_tempdir()
2323

2424
#ifdef HAVE_CXX_FILESYSTEM
2525
if(auto p = Filesystem::temp_directory_path(ec); !ec && !p.empty())
26-
return p.generic_string();
26+
return p.string();
2727
#endif
2828

2929
#if defined(_WIN32)

src/windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool fs_win32_is_symlink(std::string_view path)
184184
bool
185185
fs_win32_is_ext_path(std::string_view path)
186186
{
187-
return path.substr(0, 4) == R"(\\?\)" || path.substr(0, 4) == R"(\\.\)";
187+
return path.length() >= 4 && (path.substr(0, 4) == R"(\\?\)" || path.substr(0, 4) == R"(\\.\)");
188188
}
189189

190190

test/core/test_OnDisk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestOnDisk : public testing::Test {
2626

2727
file = cwd + "/ffs_" + n + ".txt";
2828
ASSERT_TRUE(fs_touch(file));
29-
ASSERT_TRUE(fs_exists(file));
29+
ASSERT_TRUE(fs_is_file(file));
3030

3131
dir = cwd + "/ffs_" + n + "_dir";
3232
ASSERT_TRUE(fs_mkdir(dir));

test/core/test_env.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ auto t = fs_get_tempdir();
5656
EXPECT_FALSE(t.empty());
5757

5858
std::cout << "Temp directory " << t << "\n";
59-
EXPECT_TRUE(fs_exists(t));
59+
EXPECT_TRUE(fs_is_dir(t));
6060
}
6161

6262

@@ -95,7 +95,7 @@ auto t = fs_get_tempdir();
9595
EXPECT_FALSE(t.empty());
9696

9797
std::cout << "Temp directory " << t << "\n";
98-
EXPECT_TRUE(fs_exists(t));
98+
EXPECT_TRUE(fs_is_dir(t));
9999

100100
}
101101

test/core/test_permissions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ class TestPermissions : public testing::Test {
1111
std::string nowrite = "nonwritable.txt";
1212
void SetUp() override {
1313
ASSERT_TRUE(fs_touch(read));
14-
ASSERT_TRUE(fs_exists(read));
1514
ASSERT_TRUE(fs_is_file(read));
15+
1616
ASSERT_TRUE(fs_touch(noread));
17-
ASSERT_TRUE(fs_exists(noread));
1817
ASSERT_TRUE(fs_is_file(noread));
1918
if(!fs_is_file(nowrite)){
2019
ASSERT_TRUE(fs_touch(nowrite));

0 commit comments

Comments
 (0)