Skip to content

Commit 6434bf2

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

15 files changed

+42
-85
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_absolute.f90

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ program main
2626
error stop
2727
endif
2828

29-
ref = get_cwd() // "/rel"
30-
out = absolute(in, "")
31-
if(len_trim(out) == 0) error stop "absolute(" // in // ", '') has empty output"
32-
if(out /= ref) then
33-
write(stderr, '(a)') "absolute(" // in // ", '') =" // out // " /= " // ref
34-
error stop
35-
endif
36-
37-
ref = get_cwd()
38-
out = absolute("", "")
39-
if(len_trim(out) == 0) error stop "absolute('', '') has empty output"
40-
if(out /= ref) then
41-
write(stderr, '(a)') "absolute('', ''): " // out // " /= " // ref
42-
error stop
43-
endif
44-
45-
ref = get_cwd() // "/rel"
46-
out = absolute("", in)
47-
if(len_trim(out) == 0) error stop "absolute('', path) has empty output"
48-
if(out /= ref) then
49-
write(stderr,'(a)') "absolute('', " // in //"): " // out // " /= " // ref
50-
error stop
51-
endif
52-
5329
end block valgrind
5430

5531
end program

test/core/test_canonical.f90

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,15 @@ program test_canon
88

99
valgrind : block
1010

11-
character(:), allocatable :: p1, p2
11+
character(:), allocatable :: p1
1212

1313
integer :: L1, L2
1414

15-
! -- current directory -- old MacOS doesn't handle "." or ".." alone
16-
p1 = canonical(".")
17-
L1 = len_trim(p1)
18-
if(L1 == 0) error stop "ERROR: canonical '.' failed"
19-
20-
p2 = get_cwd()
21-
if(p1 /= p2) error stop "ERROR: canonical '.' failed: " // p1 // " /= " // p2
22-
23-
print *, "OK: current dir = ", p1
15+
p1 = canonical("")
16+
if(p1 /= "") error stop "canonical('') not empty: " // p1
2417

25-
! -- home directory
26-
p2 = get_homedir()
2718
p1 = canonical("~")
2819
L1 = len_trim(p1)
29-
if (p1(1:1) == "~") then
30-
write(stderr,'(a)') "canonical(~) did not expanduser: " // p1
31-
error stop
32-
end if
33-
if(len_trim(p1) /= len_trim(p2)) then
34-
write(stderr,*) "ERROR: canonical('~') " // p1 // " /= get_homedir: " // p2
35-
error stop
36-
end if
37-
38-
print *, "OK: home dir = ", p1
39-
40-
!> empty
41-
p2 = canonical("")
42-
if(p2 /= "") error stop "canonical('') not empty: " // p2
43-
44-
! -- relative dir
4520
p1 = canonical("~/..", .false., .true.)
4621

4722
L2 = len_trim(p1)
@@ -51,12 +26,10 @@ program test_canon
5126
end if
5227
print *, 'OK: canon_dir = ', p1
5328

54-
if(is_cygwin()) stop "OK: Cygwin does not support canonicalize relative non-existing path"
55-
5629
! -- relative, non-existing file
5730

5831
!> strict, not exist
59-
if(backend() == "<filesystem>") then
32+
if(backend() == "<filesystem>" .and. .not. is_cygwin()) then
6033
p1 = canonical("not-exist/dir/..", strict=.true.)
6134
!! not a trailing slash input to avoid ambiguity in various backends
6235
if (len_trim(p1) /= 0) then

0 commit comments

Comments
 (0)