Skip to content

Commit 1a5a00e

Browse files
committed
parent: no posix
1 parent 6ba8677 commit 1a5a00e

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

+stdlib/parent.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
end
4040
end
4141

42-
p = stdlib.posix(p);
43-
4442
if ~strlength(p)
4543
p = '.';
4644
end
@@ -66,7 +64,7 @@
6664
%!test
6765
%! if ispc
6866
%! assert(parent('c:/a'), 'c:/')
69-
%! assert(parent('c:\a\'), 'c:/')
67+
%! assert(parent('c:\a\'), 'c:\')
7068
%! assert(parent('c:\'), 'c:/')
7169
%! assert(parent('c:'), 'c:/')
7270
%! end

src/octave/parent.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ DEFUN_DLD (parent, args, nargout,
1515
return octave_value("");
1616
}
1717

18-
std::string out = std::filesystem::path(fs_drop_slash(args(0).string_value())).parent_path().generic_string();
18+
auto par = std::filesystem::path(fs_drop_slash(args(0).string_value())).parent_path();
1919

20-
return octave_value(out);
20+
if (par.empty())
21+
return ".";
22+
23+
// need this for <filesystem> or _splitpath_s to make x: x:/
24+
if (fs_is_windows() && par == par.root_name())
25+
par += '/';
26+
27+
return octave_value(par.string());
2128
}

src/parent_fs.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@
77

88
std::string fs_parent(std::string_view in)
99
{
10-
std::string out;
11-
if(in.empty())
12-
out = ".";
13-
else
14-
out = std::filesystem::path(fs_drop_slash(in)).parent_path().generic_string();
10+
auto par = std::filesystem::path(fs_drop_slash(in)).parent_path();
1511

16-
// handle "/" and other no parent cases
17-
if (out.empty()){
18-
if (!in.empty() && in.front() == '/')
19-
out = "/";
20-
else
21-
out = ".";
22-
}
12+
if (par.empty())
13+
return ".";
2314

24-
// make x: x:/
25-
if (fs_is_windows() && out.length() == 2 && !fs_root_name(out).empty())
26-
out.push_back('/');
15+
// need this for <filesystem> or _splitpath_s to make x: x:/
16+
if (fs_is_windows() && par == par.root_name())
17+
par += '/';
2718

28-
return out;
19+
return par.string();
2920
}

0 commit comments

Comments
 (0)